Ubuntu 16.04 – 系统启动等待“提升网络接口”

我有一个带有两个接口的Ubuntu 16.04系统 – eth0配置了DHCP,eth1配置了静态IP地址。

/ etc / network / interfaces文件具有以下配置

# The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet dhcp # The Secondary network interface auto eth1 iface eth1 inet static address 10.10.1.10 netmask 255.255.255.0 dns-nameservers 74.82.42.42 4.2.2.2 ## Virtual Interfaces for virtual hosts auto eth1:11 iface eth1:11 inet static address 10.10.1.11 netmask 255.255.255.0 auto eth1:12 iface eth1:12 inet static address 10.10.1.12 netmask 255.255.255.0 auto eth1:13 iface eth1:13 inet static address 10.10.1.13 netmask 255.255.255.0 

问题是,当eth0链路上的DHCP服务器不可用或者eth0链路断开时,系统会挂起5分钟,这会显着降低启动过程的速度。

 violet@ubuntu-xenial:~$ systemd-analyze blame 5min 241ms networking.service 1.529s nmbd.service 1.524s winbind.service 

我尝试减少/etc/systemd/system/network-online.target.wants/networking.service文件中的时间,这使得系统启动更快,而无需等待网络服务,但无法加载eth1上的虚拟接口。

是否有更简洁的方法让系统在eth0接口上没有完全网络配置的情况下启动,并仍然在eth1上加载所有静态网络配置?

似乎有人对一个客户没有及时获得它的DHCP感到妄想。

编辑此文件/etc/dhcp/dhclient.conf并将timeout设置为合理的值,例如

 timeout 15 

默认值300秒太高了。 建议的15的替换值进行了测试并且工作正常。

所以在你的/etc/network/interfaces ,改变这个:

 # The primary network interface auto eth0 iface eth0 inet dhcp 

对此:

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

当内核从接口检测到一个hotplug事件时(即插入电缆时),这将启动接口eth0 ,而不是在启动时启动它。

如您所引用,可以更改引发网络接口的超时值(如果运行systemd ):

打开终端窗口,然后输入命令:

 sudo nano /etc/systemd/system/network-online.target.wants/networking.service 

然后将TimeoutStartSec=5min行更改为您选择的值。 按Ctrl + o然后按Ctrl + x保存文件。

最后,重启守护进程:

 sudo systemctl daemon-reload