PS:通常我通过vmware克隆或者导出装有lnmp环境的centos镜像在本地或者其他机器上复制使用lnmp环境,每次安装都会有一个共同问题出现,那就是网卡无法启动。经过多方资料查找,让我从根源上了解了这个问题的产生机制,现分享如下:
-
网卡错误示例显示:
Device eth0 does not seem to be present, delaying initialization #报错:设备eth0的似乎并不存在,延迟初始化 Device eth1 does not seem to be present, delaying initialization Device eth2 does not seem to be present, delaying initialization
-
‘克隆’或’导入’镜像,新生成的虚拟机发生哪些变化?
vmware虚拟机系统在’克隆’或者安装其他虚拟机’导出’的”镜像”的时候,会自动分配给新生成的虚拟机一段网卡信息(MAC地址),这段MAC地址是唯一的虚拟机标识!
-
网卡不存在错误如何产生?
网卡错误:
service network restart #报错:设备eth0的似乎并不存在,延迟初始化 Device eth0 does not seem to be present, delaying initialization
在centos系统中/etc/udev/rules.d/70-persistent-net.rules这个文件确定了网卡与MAC地址的绑定,克隆之后网卡的MAC地址发生了变化,所以导致系统认为网络设备不存在
查看系统在未启动网卡时70-persistent-net.rules内容
# This file was automatically generated by the /lib/udev/write_net_rules # program, run by the persistent-net-generator.rules rules file. # # You can modify it, as long as you keep each rule on a single # line, and change only the value of the NAME= key. # PCI device 0x1022:0x2000 (pcnet32) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:50:bd:17", ATTR{type}=="0", KERNEL=="eth*", NAME="eth0" SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:3A:2F:1D", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
-
解决办法
由上面图片我们得知新虚拟机的MAC地址为00:50:56:3A:2F:1D,这个在70-persistent-net.rules中成了eth1的MAC地址
# cd /etc/sysconfig/network-scripts/ # ls | grep ifcfg ifcfg-eth0 ifcfg-lo
查看网卡配置文件,只有ifcfg-eth0存在.所以我们可以删掉70-persistent-net.rules中eth1的网卡信息,把eth0的MAC地址改成现在新虚拟机上的MAC地址00:50:56:3A:2F:1D
#....省略注释说明 # PCI device 0x1022:0x2000 (pcnet32) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:3A:2F:1D", ATTR{type}=="0", KERNEL=="eth*", NAME="eth0"
同时修改ifcfg-eth0的网卡配置信息
vim etc/sysconfig/network-scripts/ifcfg-eth0 ............. HWADDR=00:50:56:3A:2F:1D .............
重启系统搞定
总结:
从上面的原理分析,应该基本知道问题出现是由于新虚拟机mac地址与系统内网卡配置mac地址不同导致网卡无法启动.同时70-persistent-net.rules文件确定了网卡与MAC地址的绑定,需要重新绑定mac与网卡的关系,才能正确使用.二者缺一不可
参考:
1.LINUX6不能启动,bringing up interface eth0:解决
2.Device eth0 does not seem to be present, delaying initialization