错误: 在Vmware/virtualbox上新建一个拷贝的Red Hat Enterprise Linux虚拟机,启动时发现找不到网卡(上不去网):
[root[@primary](https://my.oschina.net/primary) ~]# service network restart
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Device eth1 does not seem to be present, delaying initialization.
[FAILED]
错误原因: 克隆的Linux系统在新的机器上运行,新服务器网卡物理地址已经改变。而/etc/udev/rules.d/70-persistent-net.rules这个文件确定了网卡和MAC地址的信息之间的绑定,克隆后的网卡的MAC已经发生了变化,所以导致系统认为网络设备不存在,网络不能正常启动。另外一个就是/etc/sysconfig/network-scripts/ifcfg-eth0里面MAC地址也是以前的旧信息。 关于/etc/udev/rules.d/70-persistent-net.rules这个文件,系统在启动时会自动监测变化,然后由/lib/udev/write_net_rules写入到/etc/udev/rules.d/70-persistent-net.rules中一个新的配置节,网卡的的序号依次递增(如原来为eth0,则修改第一后生成一个eth1,再次修改后生成一个eth2...),且其ATTR{address}的值为当前网卡对应的mac地址。
[root[@primary](https://my.oschina.net/primary) ~]# 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, and change only the value of the NAME= key.
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:2a:c4:f0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:1d:6d:0e", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:8e:51:f6", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"
~
~
~
~
~
~
~
~
~
"/etc/udev/rules.d/70-persistent-net.rules" 14L, 750C
[root@primary ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 看到里面配置的的确是eth1的旧信息,实际是需要配置为最新的eth2的信息。
解决方法: 1.编辑/etc/sysconfig/network-scripts/ifcfg-eth0配置文件,修改为eth2的配置信息并设置为静态:DEVICE=eth2, BOOTPROTO=static, HWADDR=08:00:27:8e:51:f6 2.重启网卡服务成功即可。
[root[@primary](https://my.oschina.net/primary) ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth2
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
DNS1=114.114.114.114
IPADDR=192.168.100.238
NETMASK=255.255.255.0
GATEWAY=192.168.100.254
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth2"
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
HWADDR=08:00:27:8e:51:f6
LAST_CONNECT=1464664485
USERCTL=no
~
~
~
~
~
~
~
~
"/etc/sysconfig/network-scripts/ifcfg-eth0" 18L, 341C
[root[@primary](https://my.oschina.net/primary) ~]# service network restart (或者/etc/init.d/network restart)
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Determining if ip address 192.168.100.238 is already in use for device eth2...
[ OK ]
[root[@primary](https://my.oschina.net/primary) ~]# ifconfig
eth2 Link encap:Ethernet HWaddr 08:00:27:8E:51:F6
inet addr:192.168.100.238 Bcast:192.168.100.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe8e:51f6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3378 errors:0 dropped:0 overruns:0 frame:0
TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:234683 (229.1 KiB) TX bytes:776 (776.0 b)
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:15 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:901 (901.0 b) TX bytes:901 (901.0 b)