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

 

1)現象說明
公司IDC機房裏的一臺線上服務器硬件報警,最後排查發現服務器主板壞了,隨即聯繫廠商進行更換主板,最後更換後,登陸服務器,發現網卡綁定及ip信息都在,可是ip卻ping不通了,進一步排查,重啓網卡,提示以前的eth0和eth1網卡設備發現不了了,也就是說服務器主板更換後,以前的網卡設備都識別不了了html

主板更換後,重啓並登錄服務器,發現以前的網卡設備(eth0、eth一、eth二、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地址不一致致使混亂,因此就識別不了當前網卡;bash

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、eth一、eth三、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、eth一、eth二、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、eth一、eth二、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的名字不一樣;less

相關文章
相關標籤/搜索