VMware Workstation中Linux模版虚拟机网络连接采用NAT模式,克隆后查看网络设置与对应的配置文件,发现不一致,具体如下:
[root@localhost ~]# ifconfig -a
eth1 Link encap:Ethernet HWaddr 00:0C:29:B5:A8:81
inet addr:192.168.230.139 Bcast:192.168.230.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feb5:a881/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:134 errors:0 dropped:0 overruns:0 frame:0
TX packets:70 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:34006 (33.2 KiB) TX bytes:7979 (7.7 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:480 (480.0 b) TX bytes:480 (480.0 b)
[root@localhost ~]# ls /etc/sysconfig/network-scripts/ifcfg*
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-lo
原因如下:redhat使用udev动态管理设备文件,并根据设备的信息对其进行持久化命名。udev会在系统引导的过程中识别网卡,将mac地址和网卡名称对应起来记录在udev的规则脚本中。而对于新的虚拟机,VMware会自动为虚拟机的网卡生成MAC地址,当你克隆或者重装虚拟机软件时,由于你使用的是以前系统虚拟硬盘的信息,而该系统中已经有eth0的信息,对于新增的网卡,udev会自动将其命名为eth1(累加的原则),所以在你的系统启动后,你使用ifconfig看到的网卡名为eth1。这时候在/etc/sysconfig/network-script/下依然是eth0的配置文件,重启网络就会出现如下问题:
[root@localhost ~]# /etc/init.d/network restart
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Device eth0 does not seem to be present, delaying initialization.
[FAILED]
(1)备份配置文件
[root@localhost ~]# cp /etc/udev/rules.d/70-persistent-net.rules /etc/udev/rules.d/70-persistent-net.rules.bak
(2)修改/etc/udev/rules.d/70-persistent-net.rules,删除eth0有关内容,修改eth1为eth0, 记录下这个新eth0的mac地址 。
修改前/etc/udev/rules.d/70-persistent-net.rules的内容如下:
[root@localhost ~]# 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 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:f6:7c:14", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:b5:a8:81", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
使用vim修改/etc/udev/rules.d/70-persistent-net.rules。
[root@localhost ~]# vim /etc/udev/rules.d/70-persistent-net.rules
修改后/etc/udev/rules.d/70-persistent-net.rules内容如下:
[root@localhost ~]# 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 0x8086:0x100f (e1000)
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:b5:a8:81", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
(3)修改/etc/sysconfig/network-scripts/ifcfg-eth0,修改其中的mac地址为步骤(2)中记录的地址。
修改前/etc/sysconfig/network-scripts/ifcfg-eth0内容如下:
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
HWADDR="00:0C:29:F6:7C:14"
NM_CONTROLLED="yes"
ONBOOT="no"
使用vim修改/etc/sysconfig/network-scripts/ifcfg-eth0。
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
修改后/etc/sysconfig/network-scripts/ifcfg-eth0内容如下:
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
HWADDR="00:0c:29:b5:a8:81"
NM_CONTROLLED="yes"
ONBOOT="yes"
(4)重启后恢复正常。
[root@localhost ~]# init 6来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28536251/viewspace-1444892/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28536251/viewspace-1444892/