1、问题情况
在vmware中克隆一个虚拟机后,新的虚拟机网络无法使用,并用原操作系统中的网卡eth0在克隆出来的新系统中,网卡号变成了eth1,并且IP地址也丢失了,网络不可正常使用。
2、环境情况
原机器名称 |
克隆后目标主机 |
||
机器名称 |
别名 |
机器名称 |
别名 |
ol6-single |
A机器 |
ol6_weblogic_1 |
B机器 |
3、克隆过程
将A机器关闭,在Vmware控制台上,右击虚拟机A机器(ol6-single),点击“clone”—“下一步“,按提示一步步完成克隆过程,克降后机器名称命名为:ol6_weblogic_1
4、原系统与克隆后系统网络配置差异对比
4.1、ifconfig网络接口输出情况对比
(1)原机器(ol6-single)网络接口配置情况:
[root@ol6-single ~]# ifconfig -a eth0 Link encap:Ethernet HWaddr 00:0C:29:5E:35:00 inet addr:192.168.1.150 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe5e:3500/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:114 errors:0 dropped:0 overruns:0 frame:0 TX packets:81 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:12918 (12.6 KiB) TX bytes:15700 (15.3 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:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) |
(2)克隆后主机(ol6_weblogic_1)网络接口配置情况
[root@ol6_weblogic_1 ~]# ifconfig -a eth1 Link encap:Ethernet HWaddr 00:0C:29:3A:F2:8E inet addr:192.168.91.133 Bcast:192.168.91.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe3a:f28e/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:114 errors:0 dropped:0 overruns:0 frame:0 TX packets:22 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1784 (1.7 KiB) TX bytes:4139 (4.0 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:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 |
克隆过来后,原本的eth0变成了eth1,IP地址也丢失了,并用HWaddr的值发生改变了。
4.2、网络接口配置文件存在情况对比
A机器(原机器) |
B机器(克隆后机器) |
cd /etc/sysconfig/network-scripts |
cd /etc/sysconfig/network-scripts |
[root@ol6-single network-scripts]# ls ifcfg-eth* ifcfg-eth0 |
[root@ol6-weblogic_1 network-scripts]# ls ifcfg-eth* ifcfg-eth0 |
从上面对比结果看来,虽然克隆后的B机器从ifconfig –a上看到原来的eth0不见了,变成了eth1,但是,在/etc/sysconfig/network-scripts看到,B机器的网卡配置文件名称仍然叫eth0
4.3、网络设备绑定文件70-persistent-net.rules内容对比
A机器 (原机器) |
# 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 0x8086:0x100f (e1000) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:5e:35:00", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" |
B机器 (克隆后机器) |
# 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 0x8086:0x100f (e1000) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:5e:35:00", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:3a:f2:8e", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1" |
从上面比较来看,克隆后的机器,/etc/udev/rules.d/70-persistent-net.rules多出了一行配置,见上面标红色内 容,其NAME=“eth1”,MAC发生了变化,原有的NAME="eth0"一行内容仍在,且MAC地址也相同。
5、解决办法
5.1、修改克隆后机器(B机器)70-persistent-net.rules文件内容
对克隆后机器(B机器)/etc/udev/rules.d/70-persistent-net.rules文件进行两步修改:
(1) 将原NAME="eth0"行内容注释
(2) 将NAME="eth1"行内容中的"eth1"修改成"eth0"
修改完成后内容如下:
# 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 0x8086:0x100f (e1000) #SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:5e:35:00", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:3a:f2:8e", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" |
5.2、修改克隆后机器(B机器)的Mac地址与IP地址
[root@ol6_weblogic_1 network-scripts]# vi/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0" HWADDR="00:0C:29:3a:f2:8e" NM_CONTROLLED="yes" ONBOOT="yes" IPADDR=192.168.1.230 NETWORK=192.168.1.0 NETMAST=255.255.255.0 TYPE="Ethernet" UUID="b1b9ac33-19ad-4bb3-ac6c-06d5a3fa7c5b" |
特别注意:
修改的MAC地址,只能是与70-persistent-net.rules文件中ATTR{address}相同的地址
5.3、重启操作系统生效
经验证,重启网络服务(service network restart)方式,IP地址可以变化过来,但是网络接口名称修改不生效。
6、验证
[root@ol6_weblogic_1 ~]# ifconfig –a
eth0 Link encap:Ethernet HWaddr 00:0C:29:3A:F2:8E inet addr:192.168.1.230 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe3a:f28e/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:380 errors:0 dropped:0 overruns:0 frame:0 TX packets:402 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:35506 (34.6 KiB) TX bytes:54463 (53.1 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:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
|
结果:eth1变回了eth0,并且IP地址为所设置的IP地址,网络已可正常使用