这是问题:
root@home:~# ping 8.8.8.8 connect: Network is unreachable root@home:~# dhclient eth0 RTNETLINK answers: File exists root@home:~# ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_req=1 ttl=51 time=16.8 ms 64 bytes from 8.8.8.8: icmp_req=2 ttl=51 time=16.6 ms ^C --- 8.8.8.8 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1002ms rtt min/avg/max/mdev = 16.654/16.737/16.820/0.083 ms root@home:~#
只有手动调用dhclient后,networking才能正常工作。 我没有NetworkManager(删除它)。 以下是/etc/network/interfaces中的相关行:
auto eth0 iface eth0 inet dhcp
这里是启动日志:
root@home:~# cat /var/log/syslog | grep dhclient May 28 21:39:44 home kernel: [ 7.237076] type=1400 audit(1369762781.497:2): apparmor="STATUS" operation="profile_load" name="/sbin/dhclient" pid=405 comm="apparmor_parser" May 28 21:39:44 home kernel: [ 7.238298] type=1400 audit(1369762781.497:4): apparmor="STATUS" operation="profile_load" name="/usr/lib/connman/scripts/dhclient-script" pid=405 comm="apparmor_parser" May 28 21:39:45 home dhclient: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 8 (xid=0x79607e29) May 28 21:39:45 home dhclient: DHCPREQUEST of 192.168.0.103 on eth0 to 255.255.255.255 port 67 (xid=0x79607e29) May 28 21:39:45 home dhclient: DHCPOFFER of 192.168.0.103 from 192.168.0.1 May 28 21:39:45 home dhclient: DHCPACK of 192.168.0.103 from 192.168.0.1 May 28 21:39:45 home dhclient: bound to 192.168.0.103 -- renewal in 234779 seconds. May 28 21:39:45 home kernel: [ 11.695666] type=1400 audit(1369762785.953:10): apparmor="STATUS" operation="profile_replace" name="/sbin/dhclient" pid=1154 comm="apparmor_parser" May 28 21:40:11 home dhclient: DHCPREQUEST of 192.168.0.103 on eth0 to 255.255.255.255 port 67 (xid=0x2aa61c47) May 28 21:40:11 home dhclient: DHCPACK of 192.168.0.103 from 192.168.0.1 May 28 21:40:11 home dhclient: bound to 192.168.0.103 -- renewal in 243414 seconds.
任何想法可能会导致这样的问题?
更新:我发现默认网关不是在启动时添加的,但是当我重新启动networking服务或者手动运行dhclient的时候添加了。 但是我还没有发现是什么原因导致了这样的行为。
编辑:
一般来说,您应该通过选件003从您的DHCP服务器获取您的默认网关。 最好的方法是configuration您的DHCP服务器,以正确地向客户提供这些信息。 如果因为某种原因你不能这样做,我相信你可以使用gateway指令在/etc/network/interfaces文件中手动指定它(参见手册页 )。 我从来没有这样做,但我相信它应该适用于非静态configuration的接口。
如果没有,您可以使用初始化脚本手动添加它。
看起来您正在使用dhclient正确接收DHCP租约。 我怀疑NetworkManager未被完全删除,或者您有另一个启动的networking自动configuration工具(可能与您的桌面环境绑定),并试图重新configuration您的networking设置。
首先通过运行networking启动脚本确认你的/etc/network/interfacesconfiguration正确:
sudo /etc/init.d/networking restart
或者只是使用ifup和ifdown :
sudo ifdown eth0 && ifup eth0
然后确保你没有任何networkingpipe理器的痕迹:
sudo apt-get purge network-manager
就我而言,在CentOS 6 / Fedora下,这与/ etc / sysconfig / network-scripts / ifcfg-eth0和/etc/udev/rules.d/70-persistent-net.rules之间的不一致有关。
在这两个文件中,声明与eth0接口关联的MAC。 在虚拟机克隆上,分配了一个新的MAC,但这里没有反映(pipe理员应该这样做)。
启动时,你可以在dmesg中看到真实的eth0被重命名为eth1(与ifcfg-eth0冲突),然后在70-persistent-net.rules下自动创build一个新条目,将find的MAC与eth1相关联。
dhclient没有启动(或者如果启动,中止),结果是系统没有从DHCP服务器获得IP。
非常值得注意的是,手动运行dhclient强制获取假eth1的IP,networking正常工作,直到下一次重启。
手动编辑上面引用的文件,使MAC和eth *名称重合已经解决了这个问题 – 现在dhclient在启动时开始并自行获取IP。