以CentOS6为例,虚拟机软件为VMware Workstaion,通过链接克隆虚拟机后发现网卡不能正常启动了。
检查发现,克隆虚拟机后,网卡的实际MAC地址
和设备的UUID
都发生了改变,但是网卡配置文件/etc/sysconfig/network-scripts/ifcfg-eth0
中HWADDR
和UUID
没有做自动调整。
DEVICE=eth0
HWADDR=52:54:00:49:C2:3E
TYPE=Ethernet
UUID=799e6052-94c7-4c31-8013-cae79f714a04
ONBOOT=no
NM_CONTROLLED=no
BOOTPROTO=dhcp
由于这两行值,即便不存在,网卡也能正常启动,于是把相关的内容删除。变成如下情形:
DEVICE=eth0
TYPE=Ethernet
ONBOOT=no
NM_CONTROLLED=no
BOOTPROTO=dhcp
问题依旧。
想到在RHEL5中有udev规则控制网卡启动加载设备名后,在/etc/udev/rules.d
发现
#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.
# PCI device 0x1af4:0x1000 (virtio-pci)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:49:c2:3e", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
原来网卡的信息被持久化到了设备名生成规则中了,这样好办了,删除/etc/udev/rules.d/70-persistent-net.rules 即可,重新启动会自动生成的。
# rm -f /etc/udev/rules.d/70-persistent-net.rules
# reboot
重启后网卡自动加载,至此问题解决。