pig2 发表于 2014-1-13 23:26:30

遇到克隆虚拟机后的网卡启动失败问题解析

虚拟机的网络是个问题,找了很多的资料,特别是克隆之后,因为不懂这里面的原理,真的让人很懊恼,这里备用以后查询。公司测试环境安装的都是RHEL6.3,在进行虚拟机克隆后,发现clone的虚拟机网卡起不来,具体报如下错误:
# service network restart
Shutting down loopback interface:                        
Bringing up loopback interface:                           
Bringing up interface eth0:Error: No suitable device found: no device found for connection 'System eth0'.
                                                         

当你执行ifconfig命令的时候,会发现显示eth1网卡的配置文件却为/etc/sysconfig/network-scripts/ifcfg-eth0。# ifconfig|grep addr
eth1      Link encap:EthernetHWaddr 00:0c:29:f4:95:e3
          inet6 addr: fe80::20c:29ff:fe5c:65b7/64 Scope:Link
          Interrupt:19 Base address:0x2024
          inet addr:127.0.0.1Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
# ls
ifcfg-eth0   ifdown-isdn    ifup-aliasesifup-plusb   init.ipv6-global
ifcfg-lo   ifdown-post    ifup-bnep   ifup-post      net.hotplug
ifdown       ifdown-ppp   ifup-eth      ifup-ppp       network-functions
ifdown-bnepifdown-routesifup-ippp   ifup-routes    network-functions-ipv6
ifdown-eth   ifdown-sit   ifup-ipv6   ifup-sit
ifdown-ipppifdown-tunnelifup-isdn   ifup-tunnel
ifdown-ipv6ifup         ifup-plip   ifup-wireless
#

产生这个问题的原因是虚拟机分配给操作系统的虚拟网卡MAC地址是不一样的。第一个系统的网卡MAC地址记录在了/etc/udev/rules.d/70-persistent-net.rules,命名为eth0。新克隆分配的系统的网卡MAC地址也记录在了该文件当中,与之前的系统一样,因此有了冲突。可以查看一下两个机子的这个70-persistent-net.rules文件的内容第一个系统:
# cat 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:f4:95:e3", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
克隆后的系统:# cat 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:f4:95:e3", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
我们可以看到这两个系统中的MAC地址一样。问题解决方法:
删除克隆后这个系统中的 /etc/udev/rules.d/70-persistent-net.rules文件,重启后系统会重新生成一个新的虚拟网卡MAC地址,然后把这个文件里NAME="eth1"的eth1改成eth0,同时也要修改ATTR{address}里的mac地址和/etc/sysconfig/network-scripts/ifcfg-eth0文件mac地址,并与新的虚拟网卡MAC地址保持一致。如:将原文件的
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:f4:95:e3", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
改为 SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:5c:65:b7", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
修改/etc/sysconfig/network-scripts/ifcfg-eth0文件DEVICE="eth0"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="05944003-ae77-4c9d-9e58-3ec2851db71d"
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME="System eth0"
HWADDR=00:0c:29:5c:65:b7
然后重启网络服务,发现一切正常了。
# service network restart
Shutting down interface eth0:Device state: 3 (disconnected)
                                                         
Shutting down loopback interface:                        
Bringing up loopback interface:                           
Bringing up interface eth0:Active connection state: activating
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/1
state: activated
Connection activated          设置IP后,再检查一下
# ifconfig|grep addr
eth0      Link encap:EthernetHWaddr 00:0C:29:5C:65:B7
          inet addr:192.168.0.129Bcast:192.168.0.255Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe5c:65b7/64 Scope:Link
          Interrupt:19 Base address:0x2024
          inet addr:127.0.0.1Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host

注:如果你执行ifconfig命令的时候,发现仍然显示eth1而不是eth0,可以将系统重启一遍就变过来了。
页: [1]
查看完整版本: 遇到克隆虚拟机后的网卡启动失败问题解析