linux更换网卡不识别_教你处理Linux服务器网卡识别失败的方法

原标题:教你处理Linux服务器网卡识别失败的方法

1)现象说明

公司IDC机房里的一台线上服务器硬件报警,最后排查发现服务器主板坏了,随即联系厂商进行更换主板,最后更换后,登录服务器,发现网卡绑定及ip信息都在,但是ip却ping不通了,进一步排查,重启网卡,提示之前的eth0和eth1网卡设备发现不了了,也就是说服务器主板更换后,之前的网卡设备都识别不了了!

主板更换后,重启并登陆服务器,发现之前的网卡设备(eth0、eth1、eth2、eth3)都没有了!

[root@kevin01 ~] # ifconfig -a bond 0 Link encap:Ethernet HWaddr 08 : 94 :EF : 5 E: 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) usb 0 Link encap:Ethernet HWaddr 0 A: 94 :EF : 5 E: 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-s/ [root@kevin network-s] # 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-s] # 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查看,发现eth 0、eth1、eth2、eth3网卡设备都能识别了 [root@kevin ~] # ifconfig -a bond 0 Link encap:Ethernet HWaddr 08 : 94 :EF : 5 E: 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) eth 0 Link encap:Ethernet HWaddr 08 : 94 :EF : 5 E: 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 : 5 E: 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 : 5 E: 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 : 5 E: 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) usb 0 Link encap:Ethernet HWaddr 0 A: 94 :EF : 5 E: 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的名字不同;

《Linux就该这么学》是一本基于最新Linux系统编写,面向零基础读者的技术书籍。从Linux基础知识讲起,然后渐进式地提高内容难度,详细讲解Linux系统中各种服务的工作原理和配置方式,以匹配真实生产环境对运维人员的要求,突显内容的实用性。想要学习Linux系统的读者可以点击"阅读原文"按钮了解这本书,同时这本书也适合专业的运维人员阅读,作为一本非常有参考价值的工具书!返回搜狐,查看更多

责任编辑:

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值