![如何检测/防止 systemd 网络启动失败](https://linux22.com/image/88339/%E5%A6%82%E4%BD%95%E6%A3%80%E6%B5%8B%2F%E9%98%B2%E6%AD%A2%20systemd%20%E7%BD%91%E7%BB%9C%E5%90%AF%E5%8A%A8%E5%A4%B1%E8%B4%A5.png)
使用 Centos 7(最新更新),在 200 英里外的远程防火墙计算机上,我偶尔会遇到重启困难,网络堆栈无法正常启动。该盒子有 3 个接口,通常外部 DHCP 接口需要更长的时间才能启动,并且网络堆栈没有正确等待,结果是服务器已启动但无法通过互联网访问。
该网卡是双 Intel 芯片组,使用 e1000e 驱动程序。我的板载接口问题更严重,所以我买了这张卡来解决这个问题。它有所帮助,但仍然没有完美解决。大多数情况下,再次软重启或重新启动网络堆栈会使其正确恢复在线状态。
我正在使用旧的网络脚本,而不是 NetworkManager,因为界面复杂并且需要良好的远程设置;我经常很难让 NM 正确启动复杂的配置。
即使考虑某种类型的紧急网络监视器,如果它发现网络不在线,它也会尝试重新启动/重新启动。当它失败时,我必须指导我 85 岁的母亲学习基本的 Linux 网络命令,我相信你们都知道这是一个挑战。
这是最近一次启动失败的 /var/log/messages。
May 14 04:58:55 windward network: Bringing up loopback interface: Cannot get current device settings: No such device
May 14 04:58:55 windward network: not setting speed
May 14 04:58:55 windward network: not setting duplex
May 14 04:58:55 windward network: not setting autoneg
May 14 04:58:55 windward network: [ OK ]
May 14 04:58:55 windward network: Bringing up interface enp1s0f0: Cannot get current device settings: No such device
May 14 04:58:55 windward network: not setting speed
May 14 04:58:55 windward network: not setting duplex
May 14 04:58:55 windward network: not setting autoneg
May 14 04:58:55 windward kernel: IPv6: ADDRCONF(NETDEV_UP): enp1s0f0: link is not ready
May 14 04:59:00 windward kernel: e1000e: enp1s0f0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
May 14 04:59:00 windward kernel: IPv6: ADDRCONF(NETDEV_CHANGE): enp1s0f0: link becomes ready
May 14 04:59:01 windward network: Determining IP information for enp1s0f0... failed; no link present. Check cable?
May 14 04:59:01 windward network: [FAILED]
May 14 04:59:01 windward network: Bringing up interface enp1s0f1: Cannot get current device settings: No such device
May 14 04:59:01 windward network: not setting speed
May 14 04:59:01 windward network: not setting duplex
May 14 04:59:01 windward network: not setting autoneg
May 14 04:59:01 windward kernel: IPv6: ADDRCONF(NETDEV_UP): enp1s0f1: link is not ready
May 14 04:59:03 windward kernel: e1000e: enp1s0f1 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: Rx/Tx
May 14 04:59:03 windward kernel: IPv6: ADDRCONF(NETDEV_CHANGE): enp1s0f1: link becomes ready
May 14 04:59:04 windward network: Determining if ip address 10.20.128.1 is already in use for device enp1s0f1...
May 14 04:59:06 windward network: [ OK ]
May 14 04:59:06 windward systemd: network.service: control process exited, code=exited status=1
May 14 04:59:06 windward systemd: Failed to start LSB: Bring up/down networking.
May 14 04:59:06 windward systemd: Unit network.service entered failed state.
May 14 04:59:06 windward systemd: network.service failed.
May 14 04:59:06 windward systemd: Reached target Network.
May 14 04:59:06 windward systemd: Starting Network.
May 14 04:59:06 windward systemd: Started OpenSSH server daemon.
答案1
您是否尝试在配置文件中增加 DHCP 客户端超时?
您可以尝试编辑 /etc/dhcp/dhclient.conf 并设置“超时”选项,如下所示:
timeout=60