在使用VMware的时候,往往需要创建多个虚拟机,为此,VMware提供了一个便利的功能:clone(克隆)。用户只需要装好一台虚拟机,然后使用clone功能就可以复制出多个虚拟机了,省时省事。

然而VMware为了避免目标和源这两台虚拟机之间的网卡冲突,在复制的过程中,自动修改了目标虚拟机网卡的MAC地址。于是当目标虚拟机启动的时候,系统就会赋予这些网卡新的id,譬如源虚拟机装了3张网卡,那么目标虚拟机的网卡id就是eth3、eth4和eth5,这是因为udev这个服务进程检测到有新的网卡(新的mac地址),于是重新加载驱动,赋予该网卡新的id(因为旧网卡id尚未删除)。假如在目标虚拟机上再重新clone,网卡id还会继续增长,这样的网卡id看起来很碍眼,解决办法是修改/etc/udev/rules.d/zNN_persistent-net.rules文件。

  • 修改前的zNN_persistent-net.rules

# This file was automatically generated by the /lib/udev/write_net_rules
# program, probably run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single line.
# MAC addresses must be written in lowercase.

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:0c:29:a8:e8:91", NAME="eth0"

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:0c:29:a8:e8:9b", NAME="eth1"

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:0c:29:a8:e8:a5", NAME="eth2"

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:0c:29:2e:e1:61", NAME="eth4"

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:0c:29:2e:e1:6b", NAME="eth3"

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:0c:29:2e:e1:57", NAME="eth5"

配置文件中有6张网卡,实际在用的只有三张,其mac地址末尾分别是61,6b和57,eth0、eth1和eth2已经失效,我们只需将e旧的th0、eth1、eth2注释掉,然后再将这几个网卡id赋予新的网卡即可。

  • 修改后的zNN_persistent-net.rules

# This file was automatically generated by the /lib/udev/write_net_rules
# program, probably run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single line.
# MAC addresses must be written in lowercase.

# PCI device 0x1022:0x2000 (pcnet32)
# SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:0c:29:a8:e8:91", NAME="eth0"

# PCI device 0x1022:0x2000 (pcnet32)
# SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:0c:29:a8:e8:9b", NAME="eth1"

# PCI device 0x1022:0x2000 (pcnet32)
# SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:0c:29:a8:e8:a5", NAME="eth2"

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:0c:29:2e:e1:61", NAME="eth1"

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:0c:29:2e:e1:6b", NAME="eth2"

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:0c:29:2e:e1:57", NAME="eth0"

重启虚拟机后,网卡id又会变回eth0eth1eth2