Linux服務器更換主板后,網卡識別失敗的處理方法


 

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的名字不同;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM