Debian /etc/network/interfaces 启动时未加载(如何修复竞争条件)

Debian /etc/network/interfaces 启动时未加载(如何修复竞争条件)

我之前有一个可以正常工作的服务器配置,但最近我进行了更新,发现它似乎破坏了一些东西。我认为最初有两个问题,其中第一个我已经解决了。我在查看时注意到systemctl status networking一个我从未见过的命令失败了。我查了一下,它来自一个我从未见过的包。ifupdown2我安装了它,错误就解决了。我假设这是一个未标记的依赖项,因为我以前从未需要过这个包,所以添加了它。

现在,当我的服务器启动时,networking服务成功运行,但没有设置任何网络配置:

# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp2s5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:1e:2a:c2:08:13 brd ff:ff:ff:ff:ff:ff
# 
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp2s5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:1e:2a:c2:08:13 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::21e:2aff:fec2:813/64 scope link 
       valid_lft forever preferred_lft forever
# 
# ip route # This is not a copy-paste error, it actually just prints nothing
# 
# journalctl -u networking
-- Logs begin at Thu 2019-03-28 15:17:47 CDT, end at Thu 2019-03-28 15:19:18 CDT. --
Mar 28 15:17:51 linux-01 systemd[1]: Starting ifupdown2 networking initialization...
Mar 28 15:17:51 linux-01 networking[572]: networking: Configuring network interfaces
Mar 28 15:17:54 linux-01 systemd[1]: Started ifupdown2 networking initialization.

这是我的 /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 enp2s5
iface enp2s5 inet static
        address 10.0.6.164/24
        gateway 10.0.6.1
        # dns-* options are implemented by the resolvconf package, if installed
        dns-nameservers 8.8.8.8

奇怪的是,即使networking启动成功,如果我重新加载它,一切仍然正常。

# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp2s5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:1e:2a:c2:08:13 brd ff:ff:ff:ff:ff:ff
#
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp2s5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:1e:2a:c2:08:13 brd ff:ff:ff:ff:ff:ff
    inet 10.0.6.164/24 scope global enp2s5
       valid_lft forever preferred_lft forever
    inet6 fe80::21e:2aff:fec2:813/64 scope link 
       valid_lft forever preferred_lft forever
#
# ip route
default via 10.0.6.1 dev enp2s5 
10.0.6.0/24 dev enp2s5 proto kernel scope link src 10.0.6.164

我认为这可能是一种竞争条件。我从 journalctl 捕获了 3 个失败,它们都包含类似以下内容:

Mar 28 15:11:51 linux-01 kernel: r8169 0000:02:05.0 enp2s5: link down
Mar 28 15:11:51 linux-01 kernel: r8169 0000:02:05.0 enp2s5: link down
Mar 28 15:11:51 linux-01 kernel: IPv6: ADDRCONF(NETDEV_UP): enp2s5: link is not ready
Mar 28 15:11:51 linux-01 systemd[1]: Started ifupdown2 networking initialization.
Mar 28 15:11:51 linux-01 systemd[1]: Reached target Network.
Mar 28 15:11:51 linux-01 systemd[1]: Starting Permit User Sessions...
Mar 28 15:11:51 linux-01 systemd[1]: Starting Fail2Ban Service...
...
Mar 28 15:11:54 linux-01 kernel: r8169 0000:02:05.0 enp2s5: link up
Mar 28 15:11:54 linux-01 kernel: IPv6: ADDRCONF(NETDEV_CHANGE): enp2s5: link becomes ready

系统似乎在尝试在设备准备就绪之前加载网络配置,但我不知道如何让它等到设备准备就绪。另外,不应该allow-hotplug enp2s5让时间变得无关紧要吗?

有人可以确认我对问题的评估吗?有人可以告诉我如何让 systemd 等到设备准备就绪吗?

注意:我不再拥有对服务器的物理访问权限,获取访问权限非常麻烦。我宁愿不进行任何重启,直到我 100% 确定它可以正常工作。

答案1

感谢@Mark Wagner 的建议:

我猜测将自动 enp2s5 添加到 /etc/network/interfaces 可以解决这个问题。

我不确定自动和允许热插拔之间有什么区别,但这似乎已经解决了这个问题。

相关内容