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上的所有静态网络配置?

1这可能会有所帮助:https://ubuntuforums.org/showthread.php?t=2323253 - Mine
或者使用这个链接:http://askubuntu.com/questions/203157/timeout-in-a-connection-to-a-dhcp-server - ElHeineken
3个回答

似乎有人对于客户端无法及时获取到DHCP感到担心。
编辑文件/etc/dhcp/dhclient.conf,将timeout设置为一个合理的值,比如
timeout 15

默认值300秒太高了。建议的替代值15已经测试过并且运行良好。

3谢谢。目前在搞 DNS/DHCP,五分钟的等待太折磨人了。 - Ashley Hughes
1Ubuntu有一些奇怪的默认配置。这真是有趣... - William T Froggard
哇,这将在进一步的配置中非常有用。 - David Tabernero M.
2这在Ubuntu 18上不起作用,但是这个答案可以。 - xinthose
这么多年过去了,对我来说仍然有效 :) - Wajih

所以在你的/etc/network/interfaces中,将这个改成:
# The primary network interface
auto eth0
iface eth0 inet dhcp

转换为:

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

这将在内核检测到接口的热插拔事件时(即当您插入电缆时),启动接口eth0,而不是在启动时启动它。

1这种方法在实体硬件上效果很好,但在虚拟化环境中失败了(尝试过 VMware 和 VirtualBox)。看起来虚拟化内核没有生成正确的事件。 - dtoubelis
这种方法还解决了我在之前只有内置1G的盒子中安装新的10G网络适配器后遇到的问题。Ubuntu能够识别并加载驱动程序,但启动一直停在等待"Raise Network Interfaces"的地方。相应地调整设备名称为eth0解决了这个问题。 - Joseph Jaramillo

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

打开终端窗口,输入以下命令:

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

然后将行TimeoutStartSec=5min更改为您选择的值。按下Ctrl+o,然后Ctrl+x保存文件。
最后,重新启动守护进程:
sudo systemctl daemon-reload

5通常使用sudo来启动GUI程序是一个不太好的主意...我已经修改了你的答案,使用一些表现更好的工具。 - Charles Green
这对我来说是正确的答案。我的电脑在启动时并不总是连接到网络。我不想等待5分钟让Ubuntu弄清楚这一点。 - Yitz
4我很想知道是谁这么傻,竟然认为5分钟的暂停是个“好主意”。 - Clayton Dukes