这是因为服务器更换了主板或网卡,MAC 地址改变所导致的。系统加载网卡驱动后会去读一个文件(即 /etc/udev/rules.d/70-persistent-net.rules ),这个文件是一个缓冲文件,包含了网卡的 MAC 地址,因为更换了主板,网卡的 MAC 地址也变了,但是这个文件的 MAC 地址还没变,还是之前坏了的主板的上面的网卡的 MAC 地址,这样系统在加载网卡,读取这个文件的时候读取的是之前网卡的 MAC 地址,和现在更换后主板后的网卡 MAC 地址不一致导致混乱,所以就识别不了当前网卡。
[root@kevinnetwork-scripts]# 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 0x14e4:0x1657 (tg3)SUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{address}=="****",ATTR{type}=="1",KERNEL=="eth*"# PCI device 0x14e4:0x1657 (tg3)SUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{address}=="****",ATTR{type}=="1",KERNEL=="eth*"# PCI device 0x14e4:0x1657 (tg3)SUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{address}=="****",ATTR{type}=="1",KERNEL=="eth*"# PCI device 0x14e4:0x1657 (tg3)SUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{address}=="****",ATTR{type}=="1",KERNEL=="eth*"
在查看 /etc/udev/rules.d/70-persistent-net.rules 文件,发现 eth0、eth1、eth2、eth3 网卡及其 mac 地址信息都有了:
[root@kevin~]# 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 0x14e4:0x1657 (tg3)SUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{address}=="08:94:ef:5e:ae:75",ATTR{type}=="1",KERNEL=="eth*",NAME="eth3"# PCI device 0x14e4:0x1657 (tg3)SUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{address}=="08:94:ef:5e:ae:72",ATTR{type}=="1",KERNEL=="eth*",NAME="eth0"# PCI device 0x14e4:0x1657 (tg3)SUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{address}=="08:94:ef:5e:ae:73",ATTR{type}=="1",KERNEL=="eth*",NAME="eth1"# PCI device 0x14e4:0x1657 (tg3)SUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{address}=="08:94:ef:5e:ae:74",ATTR{type}=="1",KERNEL=="eth*",NAME="eth2"
如果你的服务器有 4 个网卡,重启后对比之前的 /etc/udev/rules.d/70-persistent-net.rules 文件,发现新文件 mac 地址和 name 已经改变,但 name 变成了 name=eth4,name=eth5,name=eth6,name=eth7,这也是正常的。使用 ifconfig -a 命令也是同样的道理。
分别把这四个文件名改为 ifcfg-eth4、ifcfg-eth5、ifcfg-eth6、ifcfg-eth7,并把其中的 MAC 地址 (HWADDR) 改为对应的新 MAC 地址;
或者,把 /etc/udev/rules.d/70-persistent-net.rules 文件中的 name 分别改成 name=eth0,name=eth1,name=eth2,name=eth3,同时修改 ifcfg-eth0、ifcfg-eth1、ifcfg-eth2、ifcfg-eth3 文件中对应的 MAC 地址(HWADDR);