Networking
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% 確定它會起作用之前,我寧願不進行任何重啟。
感謝@Mark Wagner 的建議:
我猜想將 auto enp2s5 添加到 /etc/network/interfaces 會解決這個問題。
我不確定 auto 和 allow-hotplug 之間的區別是什麼,但這似乎已經解決了問題。