在使用VMware的克隆的时候遇到的问题,在克隆CENTOS6.6时发现总会多出一张网卡。

很多Linux distribution使用udev动态管理设备文件,并根据设备的信息对其进行持久化命名。udev会在系统引导的过程中识别网卡,将mac地址和网卡名称对应起来记录在udev的规则脚本中。而对于新的虚拟机,VMware会自动为虚拟机的网卡生成MAC地址,当你克隆或者重装虚拟机软件时,由于你使用的是以前系统虚拟硬盘的信息,而该系统中已经有eth0的信息,对于这个新的网卡,udev会自动将其命名为eth1(累加的原则),所以在你的系统启动后,你使用ifconfig看到的网卡名为eth1。

 

如何恢复到eth0?

 

在Centos中,udev记录网络规则的脚本为:/etc/udev/rules.d/70-persistent-net.rules

 

[user@localhost ~]$ vi /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.

# PCI device 0x1022:0x2000 (pcnet32)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:5a:6c:73", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a9:22:9d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

 

打开该文件,这时你会发现,里面有eth0,eth1两个网卡的信息,但实际上你ifconfig时只能发现eth1一个网卡的信息,这时因为eth0根本就不存在。

 

将其中eth0的信息删掉,并将eth1信息中的设备名改为eth0,重启系统,你看到的网卡就是eth0了,或者删掉其中所有的信息重启系统udev会帮你发现新的设备的。

 

另外还有一个启动脚本文件/etc/sysconfig/network-scripts/ifcfg-eth0,该文件中的mac地址为原来eth0网卡的物理地址,而虚拟机为eth1分配新的物理地址,故启动脚本中的信息与实际信息时不匹配的,将MAC的地址信息修改为70-persistent-net.rules中的eth1的MAC地址,再次重启网络,就完全恢复到以前eth0网卡的状态了。



In some rare circumstances(环境), your system may boot without network interface and you discover the following message in dmesg :

udev: renamed network interface eth0 to eth1

Since RHEL6, kudzu is no longer available since the kernel and udev take care of hardware changes.  So, you need to modify using udev to get back you’re eth0 interface. Edit the following file “/etc/udev/rules.d/70-persistent-net.rules“.

Normally, you should have a double entry (eth0 and eth1) with different MAC address. This often happen when the OS is virtualized. Just delete the whole entry for eth1 and then rename eth1 to eth0 on the following entry and reboot. There is how the udev network interface entry look like :

解释连接:

http://www.itechlounge.net/2011/09/linux-udev-renamed-network-interface-eth0-to-eth1-on-rhel6/

http://www.2cto.com/os/201308/236031.html