Code前端首页关于Code前端联系我们

Linux服务器网卡识别错误如何处理

terry 2年前 (2023-09-28) 阅读数 66 #未命名

1)现象描述

公司IDC机房在线服务器硬件报警,最新排查发现服务器主板坏了,然后联系厂家更换主板。最后更换完成后,登录服务器,发现网卡连接和IP信息都有,但是无法ping通IP。进一步排查后,重启网卡,提示无法检测到之前的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)

之前的网卡设备和bonding连接配置信息还在(bonding网卡操作: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是not find and 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.conf。查看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 = eth0。 =em1 有不同的名字

版权声明

本文仅代表作者观点,不代表Code前端网立场。
本文系作者Code前端网发表,如需转载,请注明页面地址。

热门