记一次 Linux 下网卡启动异常排查

这篇博客可能写的比较乱,机器连不上网,我整个操作是通过 IPKVM 完成的,无法复制日志,委屈一下读者了。

前情提要

我这是一台《NAS》,之前一直都是只装一张显卡,刚刚我尝试装第二张显卡,开机之后发现 NAS 连不上网,于是开始排查之路。

排查历程

首先我观察机器连接的交换机,发现交换机对应网口灯都不亮,用各种操作排除了交换机、网线的问题之后,我用 ip addr 一看发现网卡 enp6s0 是 down 的,用 lspci 能找到网卡,说明不是第二张显卡抢走了 PCIe 通道导致网卡无法启动。

然后我尝试用 ip link set enp6s0 up 手动 up 网卡,发现是可以启动的,虽然拿到的是本地链路 IPv6,但至少说明网卡硬件是没问题的。

经 AI 提醒,我开始查看 /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug enp5s0
iface enp5s0 inet dhcp

盲生,你发现了华点:这怎么写的 enp5s0,我这里网卡接口名称明明是 enp6s0?联想到我加了一张显卡,于是我拔掉第二张显卡,开机,接口名称变回 enp5s0,正常联网。

于是结论:enp6s0 这种命名是根据 PCI 路径自动生成的,加了第二张卡,网卡的 PCI bus 位置发生变化,原本是 05:00.0,现在是 06:00.0,于是接口名称变化,网卡接口不能被启动,导致无法联网。

解决方案

新建文件 /etc/systemd/network/10-lan0.link(根据网卡 MAC 地址修改):

[Match]
MACAddress=xx:e0:af:ae:xx:xx

[Link]
Name=lan0

这样做就能把网卡接口名称固定下来,避免下次又变了又无法联网了。

然后把 /etc/network/interfaces 改成:

auto lan0
iface lan0 inet dhcp

重启,联网正常。

上一篇