我有一个带有两个接口的 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
Run Code Online (Sandbox Code Playgroud)
问题是,当 eth0 链接上的 DHCP 服务器不可用或 eth0 链接关闭时,系统会挂起 5 分钟,从而显着减慢启动过程。
violet@ubuntu-xenial:~$ systemd-analyze blame
5min 241ms networking.service
1.529s nmbd.service
1.524s winbind.service
Run Code Online (Sandbox Code Playgroud)
我尝试减少 /etc/systemd/system/network-online.target.wants/networking.service 文件中的时间,这使得系统启动速度更快,而无需等待网络服务,但是,无法在 eth1 上加载虚拟接口。
有没有更简洁的方法让系统在没有 eth0 接口上的完整网络配置的情况下启动,并且仍然在 eth1 上加载所有静态网络配置?
bou*_*555 57
似乎有人对客户端没有及时获取 DHCP 感到偏执。
编辑这个文件/etc/dhcp/dhclient.conf并设置timeout一个合理的值,比如
timeout 15
Run Code Online (Sandbox Code Playgroud)
300 秒的默认值太高了。建议的替换值 15 已经过测试并且工作正常。
小智 29
所以在你的/etc/network/interfaces,改变这个:
# The primary network interface
auto eth0
iface eth0 inet dhcp
Run Code Online (Sandbox Code Playgroud)
对此:
# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp
Run Code Online (Sandbox Code Playgroud)
eth0当内核从接口检测到热插拔事件时(即当您插入电缆时),这将启动接口,而不是在启动时启动它。