現象:
一台克隆生成的centos,啟動後使用ifconfig檢視網絡資訊,發現隻有lo而沒有任何可用網卡.
使用ifup eth0後報kvm device eth0 does not seem to be present delaying initialization
大概意識是找不到eth0這個網絡裝置
使用
ls /sys/class/net
檢視實體網卡資訊傳回結果如下:
eth1 lo
或者 #dmesg|grep eth
會發現eth0 rename成 eth1
原因:
很多Linux distribution使用udev動态管理裝置檔案,并根據裝置的資訊對其進行持久化命名。例如在
Debian etch中,udev會在系統引導的過程中識别網卡,将mac位址和網卡名稱對應起來記錄在udev的規則 腳本中。而VMware會自動生成虛拟機的mac位址。這樣,由于基本系統的虛拟機已經記錄了該虛拟機的網 卡mac位址對應于網卡eth0,在克隆出的虛拟機中由于mac位址發生改變,udev會自動将該mac對應于網卡eth1。以此類推,udev會記錄所有已經識别的mac與網卡名的關系,是以每次克隆網卡名稱會自動加1, 而其實kernel僅僅隻識别到一張網卡,跟網卡名相關的網絡配置也未發生任何變化。
解決方法:
編輯如下檔案
/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.
# PCI device 0x15ad:0x07b0 (vmxnet3) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:bc:00:45", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:bc:00:46", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
注釋掉eth0的那個段落,然後将eth1的修改為eth0
修改網卡配置檔案
/etc/sysconfig/network-scripts/ifcfg-eth0
把mac位址修改為eth1的位址
HWADDR字段
重新開機後生效
當然,如果你還什麼東西都沒裝,沒有在什麼配置檔案中指定過eth0字段的話.直接cp或者mv ifcfg-eth0 ifcfg-eth1也是可以的.