You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

sshd开机启动绑定指定IP失败,手动重启恢复正常问题求助

sshd开机启动绑定指定IP失败,手动重启恢复正常问题求助

大家好,我遇到了一个棘手的问题,想请教下各位大佬:

我的环境背景

我有一台NUC10i7FNH工作站,原本装的是Ubuntu 22.04.1 Server版,但因为升级了最新的BIOS(版本59)和UEFI dbx(版本267)后,Server版会出现内核panic循环,根据NUC兼容性列表,我不得不降级成了Workstation版。

硬件设备信息如下:

sudo fwupdmgr get-devices

NUC10i7FNH

│
├─SSD 970 EVO Plus 2TB:
│     Summary:            NVM Express solid state drive
│     Current version:    2B2QEXM7
│     Vendor:             Samsung (NVME:0x144D)
├─System Firmware:
│ │   Summary:            UEFI ESRT device
│ │   Current version:    59
│ │   Minimum Version:    59
│ │   Vendor:             Intel(R) Client Systems (DMI:Intel Corp.)
│ │   Update State:       Success
│ └─UEFI dbx:
│       Summary:          UEFI revocation database
│       Current version:  267
│       Minimum Version:  267
│       Vendor:           UEFI:Linux Foundation
│       Install Duration: 1 second
└─Thunderbolt host controller:
Summary:            Unmatched performance for high-speed I/O
Current version:    42.00
Vendor:             Intel Corporation (THUNDERBOLT:0x8086, TBT:0x8086)

这台是多宿主无头工作站,通过netplan配置了bond和VLAN,我希望sshd只在以下几个IP的22端口监听(对应特定的管理和实验室VLAN):

  • 192.16.0.150/24(仅管理VLAN的管理员访问)
  • 10.0.1.150/24(实验室1 VLAN的授权用户)
  • 10.0.2.150/24(实验室2 VLAN的授权用户)
  • 10.0.3.150/24(实验室3 VLAN的授权用户)
  • 10.0.4.150/24(实验室4 VLAN的授权用户)

其他VLAN(存储、备份、数据/应用等)不需要开放SSH访问。

遇到的问题

刚装完sshd没修改sshd_config时,所有接口都会监听sshd,这不符合我的需求。于是我尝试在配置里添加ListenAddress指定上述IP,试过两种写法:

带端口的写法:

ListenAddress 192.168.0.200:22
ListenAddress 10.0.1.200:22
ListenAddress 10.0.2.200:22
ListenAddress 10.0.3.200:22
ListenAddress 10.0.4.200:22

不带端口的写法:

ListenAddress 192.168.0.200
ListenAddress 10.0.1.200
ListenAddress 10.0.2.200
ListenAddress 10.0.3.200
ListenAddress 10.0.4.200

两种配置都会出现同样的问题:系统开机(或重启)时,sshd服务启动失败,系统状态显示degraded:

sudo systemctl status | head -n 5

● hell
State: degraded
Jobs: 0 queued
Failed: 1 units
Since: Thu 2022-12-08 19:40:14 CET; 9min ago

查看sshd服务状态,报错是无法绑定指定的IP地址:

sudo systemctl status ssh.service

× ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2022-12-08 19:40:15 CET; 9min ago
Docs: man:sshd(8)
man:sshd_config(5)
Process: 853 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Process: 866 ExecStart=/usr/sbin/sshd -D $SSHD_OPTS (code=exited, status=255/EXCEPTION)
Main PID: 866 (code=exited, status=255/EXCEPTION)
CPU: 15ms

déc. 08 19:40:15 hell sshd[866]: error: Bind to port 22 on 10.0.4.150 failed: Cannot assign requested address.
déc. 08 19:40:15 hell sshd[866]: error: Bind to port 22 on 10.0.3.150 failed: Cannot assign requested address.
déc. 08 19:40:15 hell sshd[866]: error: Bind to port 22 on 10.0.2.150 failed: Cannot assign requested address.
déc. 08 19:40:15 hell sshd[866]: error: Bind to port 22 on 10.0.1.150 failed: Cannot assign requested address.
déc. 08 19:40:15 hell sshd[866]: error: Bind to port 22 on 192.168.0.150 failed: Cannot assign requested address.
déc. 08 19:40:15 hell sshd[866]: fatal: Cannot bind any address.
déc. 08 19:40:15 hell systemd[1]: ssh.service: Main process exited, code=exited, status=255/EXCEPTION
déc. 08 19:40:15 hell systemd[1]: ssh.service: Failed with result 'exit-code'.
déc. 08 19:40:15 hell systemd[1]: Failed to start OpenBSD Secure Shell server.
déc. 08 19:46:17 hell systemd[1]: ssh.service: Unit cannot be reloaded because it is inactive.

但只要手动执行sudo systemctl restart ssh.service,服务就能正常启动,并且能成功绑定所有指定的IP:

sudo systemctl status ssh.service

● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2022-12-08 19:49:59 CET; 15s ago
Docs: man:sshd(8)
man:sshd_config(5)
Process: 4248 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 4249 (sshd)
Tasks: 1 (limit: 76717)
Memory: 1.7M
CPU: 12ms
CGroup: /system.slice/ssh.service
└─4249 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"

déc. 08 19:49:59 hell systemd[1]: Starting OpenBSD Secure Shell server...
déc. 08 19:49:59 hell sshd[4249]: Server listening on 10.0.4.150 port 22.
déc. 08 19:49:59 hell sshd[4249]: Server listening on 10.0.3.150 port 22.
déc. 08 19:49:59 hell systemd[1]: Started OpenBSD Secure Shell server.
déc. 08 19:49:59 hell sshd[4249]: Server listening on 10.0.2.150 port 22.
déc. 08 19:49:59 hell sshd[4249]: Server listening on 10.0.1.150 port 22.
déc. 08 19:49:59 hell sshd[4249]: Server listening on 192.168.0.150 port 22.

有没有大佬能帮我分析下,为什么开机时sshd无法绑定这些IP,但手动重启就正常了?

备注:内容来源于stack exchange,提问作者Fred L.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 07:29:09