RHEL6 虛擬機克隆網路問題解決方法
環境:Virtualbox+RHEL 6 x64
用VirtualBox的vboxmanager克隆的虛擬機,操作系統RHEL6,啟動后發現網卡不能用了。重啟網路服務,報以下錯誤:
Bringing up interface eth0: Device eth0 does not seem to be present, delaying initialization.
在RHEL5里也發生類似事情,因為複製虛擬機MAC會重新生成,但是操作系統的MAC卻寫在ifcfg-ethx里,造成了不一致,所以不能啟動網路介面,在RHEL5里可以使用kudzu或者註釋網卡配置文件的MAC欄位來解決這個問題。但是在RHEL6里,kudzu已經被hal服務取代了。雖然lspci能夠正常認到網卡,但是卻無法使用/etc/init.d/network restart來啟動服務。嘗試註釋ifcfg-eth0的MAC欄位,還是報錯。查看了下udev的規則,發現了問題的所在。
# cat /etc/udev/rules.d/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.
# net device () (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:16:31:11", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# net device ()
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:32:66:63", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
#
原來UDEV這裡把克隆前的MAC當成了當前虛擬機的eth0 MAC,而重新生成的08:00:27:32:66:63是eth1的MAC。
解決這個問題,只要刪除舊的UDEV配置,修改為:
# cat /etc/udev/rules.d/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.
# net device () (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:32:66:63", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
重啟network服務,一切OK
# /etc/init.d/network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 08:00:27:32:66:63
inet addr:172.16.100.3 Bcast:172.16.100.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe32:6663/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:206 errors:0 dropped:0 overruns:0 frame:0
TX packets:203 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:21157 (20.6 KiB) TX bytes:24515 (23.9 KiB)
Virtualbox有這個問題,VMWARE克隆虛擬機應該也是有這個問題的。
《解決方案》
學習了一招,謝謝樓主分享
《解決方案》
我直接刪除就70-...那個文件就OK了, 不用擔心, 你重啟伺服器后又自動生成出來
《解決方案》
偶在KVM克隆debian虛擬機時也遇到這樣的問題,
我的臨時方法是直接把虛擬機網卡改為eth1,
network restart,OK
另外可行的方法我覺得還有:添加新網卡,刪除舊網卡。
《解決方案》
謝謝分享,我在RHEL6上也遇到這個問題了,最簡單的解決辦法是直接刪除
rm -fr /etc/udev/rules.d/70-persistent-net.rules 重啟系統就ok了。會自動生成一個新的。