Ubuntu 开机出现 “Waiting for network configuration…” 的成因与解决
问题定位与快速判断
systemd-analyze time、systemd-analyze critical-chainsystemd-analyze blame方案一 使用 NetworkManager 并禁用等待在线(推荐)
/etc/network/interfaces 仅保留本地回环):auto lo
iface lo inet loopback
sudo systemctl enable --now NetworkManager
sudo systemctl disable --now NetworkManager-wait-online.service
sudo systemctl mask systemd-networkd-wait-online.service
sudo systemctl enable --now systemd-resolved
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
sudo update-grub
sudo reboot
NetworkManager-wait-online.service 后,系统不再为“网络就绪”而长时间阻塞,通常可立即消除该等待提示。方案二 使用 ifupdown 的传统网络配置
/etc/network/interfaces 配置 eth0/ens33 等接口。/etc/network/interfaces 中为对应接口配置 auto 与 dhcp(或静态地址),例如:auto eth0
iface eth0 inet dhcp
# 或静态示例:
# iface eth0 inet static
# address 192.168.1.100
# netmask 255.255.255.0
# gateway 192.168.1.1
# dns-nameservers 223.5.5.5 8.8.8.8
/etc/init/failsafe.conf,将首个 sleep 20 调整为 sleep 5,并注释掉与 “Waiting for network configuration…” 相关的 sleep 40/59 与提示行(仅在确认无依赖问题时进行)。sudo update-grub
sudo reboot
方案三 其他可选优化与排查
journalctl --disk-usage 查看占用;若过大可执行 sudo journalctl --vacuum-size=100M 限制日志体积,避免 systemd-journal-flush.service 在启动阶段耗时增加。/etc/fstab,否则会显著拖慢启动;可用 swapon --show、free -h、blkid 与 gparted 核对并修正。