![Ubuntu Impish 上的 OpenSSH 服务器在重启后无法启动,只能手动重启](https://linux22.com/image/773179/Ubuntu%20Impish%20%E4%B8%8A%E7%9A%84%20OpenSSH%20%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%9C%A8%E9%87%8D%E5%90%AF%E5%90%8E%E6%97%A0%E6%B3%95%E5%90%AF%E5%8A%A8%EF%BC%8C%E5%8F%AA%E8%83%BD%E6%89%8B%E5%8A%A8%E9%87%8D%E5%90%AF.png)
前言和问题
我有一台 Ubuntu 21.10(Impish)服务器,其网络由 netplan 和 systemd-networkd 管理。
我的/etc/netplan/01-netcfg.yaml
样子是这样的:
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 1.2.3.4/32
- dead:beef:f00:ba1::2/64
routes:
- on-link: true
to: 0.0.0.0/0
via: 1.2.1.2
- on-link: true
to: default
via: fe80::1
vlans:
eth0.1234:
id: 1234
link: eth0
mtu: 1400
addresses:
- 10.0.0.2/25
routes:
- on-link: true
to: 10.0.0.128/24
via: 10.0.0.1
ip a
报告三个接口 (lo、eth0、eth0.1234@eth0) 的正确 IP。Ping 和其他网络流量 (入站/出站、外部/vlan) 正常。
但是,当我重新启动服务器时,sshd.service
启动时无法启动并出现以下错误:
Dec 14 19:18:02 srvnme sshd[1380]: error: Bind to port 22 on dead:beef:f00:ba1::2 failed: Cannot assign requested address.
Dec 14 19:18:02 srvnme sshd[1380]: error: Bind to port 22 on 1.2.3.4 failed: Cannot assign requested address.
Dec 14 19:18:02 srvnme sshd[1380]: fatal: Cannot bind any address.
启动时,服务器未显示任何与接口相关的问题
Dec 14 19:18:02 srvnme kernel: [ 1.240607] r8169 0000:22:00.0 eth0: RTL8168h/8111h, de:ad:be:ef:f0:00, XID 541, IRQ 154
Dec 14 19:18:02 srvnme kernel: [ 1.240738] r8169 0000:22:00.0 eth0: jumbo features [frames: 9194 bytes, tx checksumming: ko]
Dec 14 19:18:02 srvnme kernel: [ 5.046402] r8169 0000:22:00.0 eth0: Link is Down
Dec 14 19:18:03 srvnme kernel: [ 8.054249] r8169 0000:22:00.0 eth0: Link is Up - 1Gbps/Full - flow control rx/tx
Dec 14 19:18:03 srvnme kernel: [ 8.054273] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
如上所述,服务器重启后,我必须将 KVM 连接到服务器以重新启动 OpenSSH 服务器,以便能够再次通过 ssh 进入服务器。
无效的解决方案(迄今为止)
我编辑了 OpenSSH 服务器配置(systemctl edit sshd
)并尝试了两种方法:
[Unit]
Requires=systemd-networkd.service
After=systemd-networkd.service
BindsTo=systemd-networkd.service
[Unit]
Wants=network-online.target
After=network-online.target
这两种方法都没有效果。
如何修复OpenSSH 在服务器启动时不启动问题?