重启后需要 netplan apply

重启后需要 netplan apply

我正在运行带有 HWE 的 18.04.4 LTS。

重启后,我必须手动运行“sudo netplan apply”来设置 50-cloud-init.yaml 中描述的静态 IP:

network:
ethernets:
    renderer: networkd
    enp0s25:
        dhcp4: no
        optional: false
        addresses: [172.28.1.99/24]
        gateway4: 172.28.1.1
        nameservers:
                   addresses: [172.28.1.99, 172.28.1.1]
version: 2

我看到很多帖子谈论跳过等待网络可用的过程,但没有关于如何强制等待网络的帖子。

因此,登录后,我可以立即应用 netplan,几秒钟后,静态 IP 就应用了,并且卡也启动了。

查看 journalctl --no-pager -lu systemd-networkd,启动期间只有“权限被拒绝”错误......

-- Reboot --
Feb 04 20:10:52 lei systemd[1]: Starting Network Service...
Feb 04 20:10:52 lei systemd-networkd[935]: Failed to connect to bus: Permission denied
Feb 04 20:10:52 lei systemd-networkd[935]: Could not connect to bus: Permission denied
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Main process exited, code=exited, status=1/FAILURE
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Failed with result 'exit-code'.
Feb 04 20:10:52 lei systemd[1]: Failed to start Network Service.
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Service has no hold-off time, scheduling restart.
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Scheduled restart job, restart counter is at 1.
Feb 04 20:10:52 lei systemd[1]: Stopped Network Service.
Feb 04 20:10:52 lei systemd[1]: Starting Network Service...
Feb 04 20:10:52 lei systemd-networkd[936]: Failed to connect to bus: Permission denied
Feb 04 20:10:52 lei systemd-networkd[936]: Could not connect to bus: Permission denied
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Main process exited, code=exited, status=1/FAILURE
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Failed with result 'exit-code'.
Feb 04 20:10:52 lei systemd[1]: Failed to start Network Service.
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Service has no hold-off time, scheduling restart.
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Scheduled restart job, restart counter is at 2.
Feb 04 20:10:52 lei systemd[1]: Stopped Network Service.
Feb 04 20:10:52 lei systemd[1]: Starting Network Service...
Feb 04 20:10:52 lei systemd-networkd[938]: Failed to connect to bus: Permission denied
Feb 04 20:10:52 lei systemd-networkd[938]: Could not connect to bus: Permission denied
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Main process exited, code=exited, status=1/FAILURE
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Failed with result 'exit-code'.
Feb 04 20:10:52 lei systemd[1]: Failed to start Network Service.
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Service has no hold-off time, scheduling restart.
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Scheduled restart job, restart counter is at 3.
Feb 04 20:10:52 lei systemd[1]: Stopped Network Service.
Feb 04 20:10:52 lei systemd[1]: Starting Network Service...
Feb 04 20:10:52 lei systemd-networkd[939]: Failed to connect to bus: Permission denied
Feb 04 20:10:52 lei systemd-networkd[939]: Could not connect to bus: Permission denied
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Main process exited, code=exited, status=1/FAILURE
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Failed with result 'exit-code'.
Feb 04 20:10:52 lei systemd[1]: Failed to start Network Service.
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Service has no hold-off time, scheduling restart.
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Scheduled restart job, restart counter is at 4.
Feb 04 20:10:52 lei systemd[1]: Stopped Network Service.
Feb 04 20:10:52 lei systemd[1]: Starting Network Service...
Feb 04 20:10:52 lei systemd-networkd[940]: Failed to connect to bus: Permission denied
Feb 04 20:10:52 lei systemd-networkd[940]: Could not connect to bus: Permission denied
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Main process exited, code=exited, status=1/FAILURE
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Failed with result 'exit-code'.
Feb 04 20:10:52 lei systemd[1]: Failed to start Network Service.
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Service has no hold-off time, scheduling restart.
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Scheduled restart job, restart counter is at 5.
Feb 04 20:10:52 lei systemd[1]: Stopped Network Service.
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Start request repeated too quickly.
Feb 04 20:10:52 lei systemd[1]: systemd-networkd.service: Failed with result 'exit-code'.
Feb 04 20:10:52 lei systemd[1]: Failed to start Network Service.

然后,当我执行 netplan apply 时的条目......

Feb 04 20:11:49 lei systemd[1]: Starting Network Service...
Feb 04 20:11:49 lei systemd-networkd[2856]: Enumeration completed
Feb 04 20:11:49 lei systemd[1]: Started Network Service.
Feb 04 20:11:49 lei systemd-networkd[2856]: lo: Link is not managed by us
Feb 04 20:11:53 lei systemd-networkd[2856]: enp0s25: Gained carrier
Feb 04 20:11:54 lei systemd-networkd[2856]: enp0s25: Gained IPv6LL
Feb 04 20:11:54 lei systemd-networkd[2856]: enp0s25: Configured

我按照 heynnema 的建议实施了更严格的 .yaml 配置,但结果仍然相同。netplan --debug generate 返回:

root@l:/etc/netplan# netplan --debug generate                                                       
DEBUG:command generate: running ['/lib/netplan/generate']                                             
** (generate:22264): DEBUG: 21:54:44.867: Processing input file /etc/netplan/50-cloud-init.yaml..     
** (generate:22264): DEBUG: 21:54:44.867: starting new processing pass                                
** (generate:22264): DEBUG: 21:54:44.868: enp0s25: setting default backend to 1                       
** (generate:22264): DEBUG: 21:54:44.868: Configuration is valid                                      
** (generate:22264): DEBUG: 21:54:44.868: Generating output files..                                   
** (generate:22264): DEBUG: 21:54:44.868: NetworkManager: definition enp0s25 is not for us (backend 1)

重新启动时,我仍然没有静态 IP,直到我手动执行 netplan apply...

dparks@l:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp0s25: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether d0:50:99:67:5e:2b brd ff:ff:ff:ff:ff:ff
dparks@l:~$
dparks@l:~$ sudo netplan apply
[sudo] password for dparks:
dparks@l:~$
dparks@l:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether d0:50:99:67:5e:2b brd ff:ff:ff:ff:ff:ff
    inet 172.28.1.99/24 brd 172.28.1.255 scope global enp0s25
       valid_lft forever preferred_lft forever
    inet6 fe80::d250:99ff:fe67:5e2b/64 scope link
       valid_lft forever preferred_lft forever

/etc/systemd/network 是空的:

dparks@l:~$ ls -al /etc/systemd/network
total 8
drwxr-xr-x 2 root root 4096 Apr 20  2018 .
drwxr-xr-x 5 root root 4096 Feb  6 06:18 ..

该问题被确定为根文件夹的权限问题:

dr-xr-x--x 26 root root 4096 Feb 4 20:09 /

更正为 0755 解决了该问题并且 netplan 在启动时正确应用。

drwxr-xr-x 26 root root 4096 Feb  4 20:09 /

相关内容