大神教你处理Linux服务器网卡识别失败的方法

在线wifi跑包 金刚包跑包 cap跑包 hccapx ewsa在线 就来 握手包跑包

各位好 又见面了 我是曹操 今天给大家带来一篇新的教程

希望各位细心学习 低调用网

[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)

1)现象描述:在公司的IDC机房中,一台线上服务器的硬件发出报警信号。经过排查,发现服务器的主板出现故障。随后,我们联系了厂商进行主板更换。然而,在更换后重新登录服务器时,发现尽管网卡绑定和IP信息都存在,但是无法通过ping命令进行连接。进一步排查后发现,重启网卡时,提示之前的eth0和eth1网卡设备无法被识别。换句话说,主板更换后,之前的网卡设备无法被识别。

[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 ......
[root@kevin ~]# ipdown eth0
# mv /etc/udev/rules.d/70-persistent-net.rules /etc/udev/rules.d/70-persistent-net.rules.bak20180307 # init 6 

之前的网卡设备和绑定的bond配置信息仍然存在(绑定网卡的操作)。报错信息显示找不到eth0和eth1网卡。报错提示显示找不到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命令以使网卡绑定生效。大致步骤如下:

[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
[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、eth3、eth4网卡的信息(包括MAC地址和设备名称)。然后使用ifconfig命令查看,发现eth0、eth1、eth2、eth3网卡设备都能够被识别。

[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"
[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
[root@kevin ~]# modprobe bonding

继续查看/etc/udev/rules.d/70-persistent-net.rules文件,发现其中包含了eth0、eth1、eth2、eth3网卡及其对应的MAC地址信息。接着尝试使用ping命令进行其他机器的连接。如果无法连接,则可以尝试执行以下命令:

温馨提示:有时候即使重启后仍然出现以上情况。此时,可以将新的/etc/udev/rules.d/70-persistent-net.rules文件与之前的文件进行对比,查看新文件中的MAC地址和名称是否发生了变化,例如name=eth0与之前的name=em1不同。

赞(0)