我正在测试Ubuntu 18.04 LTS 云镜像(20180426.2)在 KVM 主机上。有一个 DHCP v4 服务器正在运行,但不支持 IPv6。启动云映像时,它不会获取 IPv4 地址。服务 systemd-networkd-wait-online 启动失败:
root@ubuntu:~# systemctl status systemd-networkd-wait-online.service
● systemd-networkd-wait-online.service - Wait for Network to be Configured
Loaded: loaded (/lib/systemd/system/systemd-networkd-wait-online.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2018-04-30 11:08:47 UTC; 12min ago
Docs: man:systemd-networkd-wait-online.service(8)
Process: 669 ExecStart=/lib/systemd/systemd-networkd-wait-online (code=exited, status=1/FAILURE)
Main PID: 669 (code=exited, status=1/FAILURE)
Apr 30 11:06:47 ubuntu systemd[1]: Starting Wait for Network to be Configured...
Apr 30 11:08:47 ubuntu systemd-networkd-wait-online[669]: Event loop failed: Connection timed out
Apr 30 11:08:47 ubuntu systemd[1]: systemd-networkd-wait-online.service: Main process exited, code=exited, status=1/FAILURE
Apr 30 11:08:47 ubuntu systemd[1]: systemd-networkd-wait-online.service: Failed with result 'exit-code'.
Apr 30 11:08:47 ubuntu systemd[1]: Failed to start Wait for Network to be Configured.
systemd-network 没有启动 IPv4:
root@ubuntu:~# journalctl -u systemd-networkd
[...]
-- Reboot --
Apr 30 11:06:47 ubuntu systemd[1]: Starting Network Service...
Apr 30 11:06:47 ubuntu systemd-networkd[651]: Enumeration completed
Apr 30 11:06:47 ubuntu systemd[1]: Started Network Service.
Apr 30 11:06:47 ubuntu systemd-networkd[651]: lo: Link is not managed by us
Apr 30 11:06:47 ubuntu systemd-networkd[651]: ens6: IPv6 successfully enabled
Apr 30 11:06:47 ubuntu systemd-networkd[651]: ens6: Gained carrier
Apr 30 11:06:49 ubuntu systemd-networkd[651]: ens6: Gained IPv6LL
root@ubuntu:~# networkctl status ens6
● 2: ens6
Link File: /run/systemd/network/10-netplan-ens6.link
Network File: /run/systemd/network/10-netplan-ens6.network
Type: ether
State: degraded (configuring)
Driver: virtio_net
Vendor: Red Hat, Inc.
Model: Virtio network device
HW Address: 02:01:a5:2e:fe:bf
Address: fe80::1:a5ff:fe2e:febf
但 DHCP v4 配置为:
root@ubuntu:~# cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by
# the datasource. Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
version: 2
ethernets:
ens6:
dhcp4: true
match:
macaddress: 02:01:a5:2e:fe:bf
set-name: ens6
root@ubuntu:~# cat /run/systemd/network/10-netplan-ens6.link
[Match]
MACAddress=02:01:a5:2e:fe:bf
[Link]
Name=ens6
WakeOnLan=off
root@ubuntu:~# cat /run/systemd/network/10-netplan-ens6.network
[Match]
MACAddress=02:01:a5:2e:fe:bf
Name=ens6
[Network]
DHCP=ipv4
[DHCP]
UseMTU=true
RouteMetric=100
当我dhclient
手动启动时,网络设备会获取一个 IPv4 地址并且可以访问(如预期的那样):
root@ubuntu:~# dhclient
root@ubuntu:~# networkctl status ens6
● 2: ens6
Link File: /run/systemd/network/10-netplan-ens6.link
Network File: /run/systemd/network/10-netplan-ens6.network
Type: ether
State: routable (configuring)
Path: pci-0000:00:06.0
Driver: virtio_net
Vendor: Red Hat, Inc.
Model: Virtio network device
HW Address: 02:01:a5:2e:fe:bf
Address: 87.106.172.51
fe80::1:a5ff:fe2e:febf
Gateway: 87.106.172.1
有人知道为什么 systemd-networkd 无法正确启动 IPv4 吗?这是我应该报告的错误吗(针对 systemd-networkd)?
答案1
我在 RasPi 2 安装的 Ubuntu Server 18.04 LTS(armhf)上遇到了同样的问题。
dhclient 暂时解决了该问题,但是重新启动系统会再次禁用 IPv4。
我将添加这个...我可以通过添加以下 cronjob 在启动时启动 dhclient 来启用解决方法:
@reboot /bin/sh dhclient