ifconfig不报告DHCP分配的地址

我正在更新设备的内核,而且我已经遇到DHCP如何工作的变化。 在我的引导脚本结尾附近,我检查是否已经有DHCP分配的地址,如果没有,我自行分配:

ifconfig eth0 169.254.1.1 up 

然后,当DHCP终于给我一个地址,它分配给eth0。 而事实上,这看起来确实发生了:如果我能弄清楚设备的地址,我可以在DHCP分配的地址上跟它通话。

但是,ifconfig继续显示169.254.1.1地址。

这是我用dhcpcd 5.2.12和linux 3.2.9看到的新行为。

如何在没有DHCP服务器的情况下自行分配地址,让DHCP在出现时覆盖该分配,然后如何查找DHCP分配的地址?

 root@appliance:~# ifconfig eth0 Link encap:Ethernet HWaddr 00:22:4D:4F:B3:69 inet addr:169.254.1.1 Bcast:169.254.255.255 Mask:255.255.0.0 inet6 addr: fe80::222:4dff:fe4f:b369/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2686 errors:0 dropped:1 overruns:0 frame:0 TX packets:589 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:403995 (394.5 Kb) TX bytes:73691 (71.9 Kb) Interrupt:20 Memory:fa200000-fa220000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:10 errors:0 dropped:0 overruns:0 frame:0 TX packets:10 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:985 (985.0 b) TX bytes:985 (985.0 b) root@appliance:~# grep dhcp /var/log/messages Jul 18 16:03:55 (none) dhcpcd[2330]: version 5.2.12 starting Jul 18 16:03:56 (none) dhcpcd[2330]: eth0: waiting for carrier Jul 18 16:03:57 (none) dhcpcd[2330]: eth0: carrier acquired Jul 18 16:03:57 (none) dhcpcd[2330]: eth0: broadcasting for a lease Jul 18 16:03:57 (none) dhcpcd[2330]: eth0: offered 10.10.0.177 from 10.10.0.1 Jul 18 16:03:57 (none) dhcpcd[2330]: eth0: acknowledged 10.10.0.177 from 10.10.0.1 Jul 18 16:03:57 (none) dhcpcd[2330]: eth0: checking for 10.10.0.177 Jul 18 16:04:02 (none) dhcpcd[2330]: eth0: leased 10.10.0.177 for 86400 seconds Jul 18 16:04:02 (none) dhcpcd[2330]: forked to background, child pid 2868 

RFC3927的整个想法是地址应该是无状态的。 因此,DHCP客户端应该随机生成地址的最后两个八位位组,然后通过ARPvalidation所述地址是唯一的。 静态设置一个值(即169.254.1.1)就是失败了。 让dhcpcd(或者你正在使用的那个客户端)完成它的工作,它可能会解决你的问题。

我find了一个体面的解决办法。 我没有将eth0设置为固定IP地址,而是创build了一个虚拟networking接口作为回退。 因此:

 ifconfig eth0:0 169.254.1.1 up 

如果没有DHCP服务器,我可以使用169.254地址与设备通话,如果有DHCP服务器,则分配给eth0,我可以用ifconfig查看它!