1)現象說明
公司IDC機房裡的一臺線上伺服器硬體報警,最後排查發現伺服器主機板壞了,隨即聯絡廠商進行更換主機板,最後更換後,登入伺服器,發現網路卡繫結及ip資訊都在,但是ip卻ping不通了,進一步排查,重啟網路卡,提示之前的eth0和eth1網路卡裝置發現不了了,也就是說伺服器主機板更換後,之前的網路卡裝置都識別不了了!
主機板更換後,重啟並登陸伺服器,發現之前的網路卡裝置(eth0、eth1、eth2、eth3)都沒有了! [root@kevin01 ~]# ifconfig -a bond0 Link encap:Ethernet HWaddr 08:94:EF:5E:AE:72 inet addr:192.168.10.20 Bcast:192.168.10.255 Mask:255.255.255.0 inet6 addr: fe80::a94:efff:fe5e:ae72/64 Scope:Link UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1 RX packets:75582 errors:0 dropped:0 overruns:0 frame:0 TX packets:58537 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:5890233 (5.6 MiB) TX bytes:4390537 (4.1 MiB) 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:65536 Metric:1 RX packets:26 errors:0 dropped:0 overruns:0 frame:0 TX packets:26 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1983 (1.9 KiB) TX bytes:1983 (1.9 KiB) usb0 Link encap:Ethernet HWaddr 0A:94:EF:5E:AE:79 BROADCAST MULTICAST MTU:1500 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:1000 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) 之前的網路卡裝置和bond繫結的配置資訊都還在(bond繫結網路卡操作:http://www.cnblogs.com/kevingrace/p/7966511.html) [root@kevin ~]# cd /etc/sysconfig/network-scripts/ [root@kevin network-scripts]# ls ifcfg-bond0 ifcfg-lo ifdown-ib ifdown-ppp ifup-aliases ifup-ipv6 ifup-ppp init.ipv6-global ifcfg-eth0 ifcfg-usb0 ifdown-ippp ifdown-routes ifup-bnep ifup-isdn ifup-routes net.hotplug ifcfg-eth1 ifdown ifdown-ipv6 ifdown-sit ifup-eth ifup-plip ifup-sit network-functions ifcfg-eth2 ifdown-bnep ifdown-isdn ifdown-tunnel ifup-ib ifup-plusb ifup-tunnel network-functions-ipv6 ifcfg-eth3 ifdown-eth ifdown-post ifup ifup-ippp ifup-post ifup-wireless [root@kevin ~]# /etc/init.d/network restart ...... 報錯說沒有發現eth0和eth1網路卡 [root@kevin ~]# ipdown eth0 報錯提示說沒有發現eth0網路卡
2)產生原因
這是因為伺服器更換了主機板或網路卡,mac地址改變所導致的。系統載入網路卡驅動後會去讀一個檔案(即/etc/udev/rules.d/70-persistent-net.rules),這個檔案是一個緩衝檔案,包含了網路卡的mac地址,因為更換了主機板,網路卡的mac地址也變了,但是這個檔案的mac地址還沒變,還是之前壞了的主機板的上面的網路卡的MAC地址,這樣系統在載入網路卡,讀取這個檔案的時候讀取的是之前網路卡的mac地址,和現在更換後主機板後的網路卡mac地址不一致導致混亂,所以就識別不了當前網路卡;
3)解決辦法
一般來說,刪除/etc/udev/rules.d/70-persistent-net.rules檔案(或者把這個檔案重新命名 或者 清空該檔案內容),重啟伺服器就可以解決了,重啟後會重新生成這個檔案, 這樣就順利解決這個問題了!這裡注意下,由於我的這臺伺服器繫結了網路卡,所以重啟網路卡後,還需要進行modprobe命令使得網路卡繫結生效,大致步驟如下: # mv /etc/udev/rules.d/70-persistent-net.rules /etc/udev/rules.d/70-persistent-net.rules.bak20180307 # init 6 重啟伺服器後,檢視/etc/udev/rules.d/70-persistent-net.rules檔案,發現沒有eth0、eth1、eth3、eth4的網路卡資訊(mac和裝置名稱) [root@kevin network-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*" 然後重啟網路卡等操作 [root@kevin ~]# modprobe bonding [root@kevin ~]# /etc/init.d/network restart [root@kevin ~]# modprobe bonding 接著ifconfig檢視,發現eth0、eth1、eth2、eth3網路卡裝置都能識別了 [root@kevin ~]# ifconfig -a bond0 Link encap:Ethernet HWaddr 08:94:EF:5E:AE:72 inet addr:192.168.10.20 Bcast:192.168.10.255 Mask:255.255.255.0 inet6 addr: fe80::a94:efff:fe5e:ae72/64 Scope:Link UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1 RX packets:108809 errors:0 dropped:0 overruns:0 frame:0 TX packets:84207 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:8471111 (8.0 MiB) TX bytes:6322341 (6.0 MiB) eth0 Link encap:Ethernet HWaddr 08:94:EF:5E:AE:72 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:38051 errors:0 dropped:0 overruns:0 frame:0 TX packets:14301 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:2869726 (2.7 MiB) TX bytes:944276 (922.1 KiB) Interrupt:16 eth1 Link encap:Ethernet HWaddr 08:94:EF:5E:AE:72 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:69158 errors:0 dropped:0 overruns:0 frame:0 TX packets:68615 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:5469647 (5.2 MiB) TX bytes:5279012 (5.0 MiB) Interrupt:17 eth2 Link encap:Ethernet HWaddr 08:94:EF:5E:AE:74 BROADCAST MULTICAST MTU:1500 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:1000 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) Interrupt:16 eth3 Link encap:Ethernet HWaddr 08:94:EF:5E:AE:75 BROADCAST MULTICAST MTU:1500 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:1000 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) Interrupt:17 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:65536 Metric:1 RX packets:26 errors:0 dropped:0 overruns:0 frame:0 TX packets:26 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1983 (1.9 KiB) TX bytes:1983 (1.9 KiB) usb0 Link encap:Ethernet HWaddr 0A:94:EF:5E:AE:79 BROADCAST MULTICAST MTU:1500 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:1000 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) 在檢視/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" 接著嘗試ping其他機器 [root@kevin ~]# ping 192.168.10.23 PING 192.168.10.23 (192.168.10.23) 56(84) bytes of data. 64 bytes from 192.168.10.23: icmp_seq=1 ttl=64 time=0.030 ms 64 bytes from 192.168.10.23: icmp_seq=2 ttl=64 time=0.016 ms 64 bytes from 192.168.10.23: icmp_seq=3 ttl=64 time=0.016 ms 如果ping不通的話,多執行下面命令 [root@kevin ~]# modprobe bonding
溫馨提示:有時候重啟後還是出現以上情況,對比之前的/etc/udev/rules.d/70-persistent-net.rules檔案,新的檔案mac地址和name已經改變,name=eth0,和之前name=em1的名字不同;