天天看點

克隆虛拟機網卡問題

 公司測試環境安裝的都是RHEL6.3,在進行虛拟機克隆後,發現clone的虛拟機網卡起不來,具體報如下錯誤:

[root@localhost Desktop]# service network restart

Shutting down loopback interface:                        [  OK  ]

Bringing up loopback interface:                            [  OK  ]

Bringing up interface eth0:  Error: No suitable device found: no device found for connection 'System eth0'.

                                                           [FAILED]

當你執行ifconfig指令的時候,會發現顯示eth1網卡的配置檔案卻為/etc/sysconfig/network-scripts/ifcfg-eth0。

[root@localhost network-scripts]# ifconfig|grep addr

eth1      Link encap:Ethernet  HWaddr 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.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

[root@localhost network-scripts]# ls

ifcfg-eth0   ifdown-isdn    ifup-aliases  ifup-plusb     init.ipv6-global

ifcfg-lo     ifdown-post    ifup-bnep     ifup-post      net.hotplug

ifdown       ifdown-ppp     ifup-eth      ifup-ppp       network-functions

ifdown-bnep  ifdown-routes  ifup-ippp     ifup-routes    network-functions-ipv6

ifdown-eth   ifdown-sit     ifup-ipv6     ifup-sit

ifdown-ippp  ifdown-tunnel  ifup-isdn     ifup-tunnel

ifdown-ipv6  ifup           ifup-plip     ifup-wireless

[root@localhost network-scripts]# 

産生這個問題的原因是虛拟機配置設定給作業系統的虛拟網卡MAC位址是不一樣的。第一個系統的網卡MAC位址記錄在了/etc/udev/rules.d/70-persistent-net.rules,命名為eth0。新克隆配置設定的系統的網卡MAC位址也記錄在了該檔案當中,與之前的系統一樣,是以有了沖突。

可以檢視一下兩個機子的這個70-persistent-net.rules檔案的内容

第一個系統:

[root@localhost rules.d]# 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"

克隆後的系統:

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: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

然後重新開機網絡服務,發現一切正常了。

Shutting down interface eth0:  Device state: 3 (disconnected)

                                                           [  OK  ]

Shutting down loopback interface:                          [  OK  ]

Bringing up interface eth0:  Active connection state: activating

Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/1

state: activated

Connection activated          [  OK  ]

設定IP後,再檢查一下

[root@localhost Desktop]# ifconfig|grep addr

eth0      Link encap:Ethernet  HWaddr 00:0C:29:5C:65:B7  

          inet addr:192.168.0.129  Bcast:192.168.0.255  Mask:255.255.255.0

注:如果你執行ifconfig指令的時候,發現仍然顯示eth1而不是eth0,可以将系統重新開機一遍就變過來了。