VMware中克隆虚拟机出现eth0改变为eth1情况

时间:2023-03-09 00:38:45
VMware中克隆虚拟机出现eth0改变为eth1情况

解决如下:

查看复制虚拟机网卡信息如下:

 root@jcfx-2 ~]# ifconfig
eth1 Link encap:Ethernet HWaddr 00:0C:29:CC:32:63
inet addr:192.168.72.11 Bcast:192.168.72.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fecc:3263/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:17551 errors:0 dropped:0 overruns:0 frame:0
TX packets:166 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1303129 (1.2 MiB) TX bytes:63288 (61.8 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:584 (584.0 b) TX bytes:584 (584.0 b)

具体需求是将eth1修改为eth0:

为什么eth0会变成eth1?

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

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

 [root@jcfx-2 ~]# more /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)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a0:25:f7", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:cc:32:63", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
 解决如下:
将70-persistent-net.rules脚本中多出来的eth1信息注销,并且修改原有的eth0的MAC地址信息,该信息与eth1的MAC信息保持一致,或者修改为别的MAC地址;
修改如下:
[root@jcfx-2 ~]# more /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)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:cc:32:63", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x15ad:0x07b0 (vmxnet3)
#SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:cc:32:63", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
最后重启服务器:
reboot