AWS Ubuntu 22.04 界面在重启时关闭

AWS Ubuntu 22.04 界面在重启时关闭

通过 AWS 使用 Ubuntu 22.04.01,刚刚将内核更新(以及 中的其他项目apt upgrade)到 6.2.0-1017-aws 并重新启动。必须进入控制台,因为连接失败且网络没有变化。然后我看到 的ifconfig输出仅显示正在运行的“lo”环回接口,而不是带有私有 IP 的接口。ip a显示接口存在但已关闭。

root@test:~# ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 336  bytes 26160 (26.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 336  bytes 26160 (26.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
root@test:~# 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: ens5: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 12:af:bd:fe:c2:c3 brd ff:ff:ff:ff:ff:ff
    altname enp0s5

查看唯一的 netplan 配置文件/etc/netplan/50-cloud-init.yaml,我发现它是由 AWS 的云服务自动生成的,并在启动时被重写。但我没有看到任何错误。dhcp4 设置为 true。为什么这个接口不会像内核更新之前那样在启动时启动?

# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  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:
    ethernets:
        ens5:
            dhcp4: true
            dhcp6: false
            match:
                macaddress: 12:af:bd:fe:c2:c3
            set-name: ens5
    version: 2

运行dhclient解决了这个问题,每次都给了我预期的静态私有 IP 地址。我甚至不需要启动接口,它会自动帮我完成。

root@test:~# dhclient
root@test:~# ifconfig
ens5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 9001
        inet 172.31.1.200 netmask 255.255.255.0  broadcast 172.31.1.255
        inet6 fe80::10af:bdff:fefe:c2c3  prefixlen 64  scopeid 0x20<link>
        ether 12:af:bd:fe:c2:c3  txqueuelen 1000  (Ethernet)
        RX packets 3  bytes 680 (680.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 9  bytes 990 (990.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 496  bytes 38048 (38.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 496  bytes 38048 (38.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

所以我将其添加@reboot dhclient到 crontab 中crontab -e,现在重启时没有任何问题。但为什么我必须这样做?我不明白为什么界面不会自动出现,我必须将 dhclient 设置为在启动时运行。这感觉很老套。它解决了这个问题,我发帖主要是为了帮助其他人,但我也想更多地了解这个问题,并知道是否有更好的方法。

相关内容