Ubuntu 22.04 的 ssh 问题

Jor*_*vez 3 ssh networking 22.04

我最近在两台不同的计算机上升级到 Ubuntu 22.04 LTS,它们有一个令人困惑的行为:

  • 从这些 22.04 我可以连接到本地网络中的其他人,没有任何问题
  • 从这些 22.04 我无法连接到外部计算机,长时间延迟和超时(见下文)
  • 我的本地网络中还有一个 Ubuntu 20.04.3 LTS,从 20.04 我可以连接到同一台外部计算机
  • 我可以从该外部计算机连接到 22.04 计算机

我认为这个问题:

  • 与防火墙无关,我没有安装任何防火墙,或者路由器问题
  • 与 RSA 问题无关,我在所有计算机上共享相同的密钥
  • 与端口无关,我使用默认的22端口

在这里找到完整的详细输出,希望它有帮助:

alice:~$ ssh -vvv externalHost
OpenSSH_8.9p1 Ubuntu-3, OpenSSL 3.0.2 15 Mar 2022
debug1: Reading configuration data /home/user/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/user/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/user/.ssh/known_hosts2'
debug2: resolving "externalHost" port 22
debug3: resolve_host: lookup external-host:22
debug3: ssh_connect_direct: entering
debug1: Connecting to externalHost [XXXXX] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x10
debug1: connect to address XXX port 22: Connection timed out
ssh: connect to host externalHost port 22: Connection timed out*
Run Code Online (Sandbox Code Playgroud)

使用 strace 我检测到最后的系统调用,当执行在超时之前被阻止时

...
fcntl(3, F_SETFD, FD_CLOEXEC)           = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("0.0.0.0")}, [128 => 16]) = 0
getpid()                                = 10276
setsockopt(3, SOL_IP, IP_TOS, [16], 4)  = 0
connect(3, {sa_family=AF_INET, sin_port=htons(22), sin_addr=inet_addr("externalHost-IPaddress")}, 16) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
Run Code Online (Sandbox Code Playgroud)

小智 7

由于我无法发表评论,所以我将其作为答案。我遇到了同样的问题,经过几个小时的搜索找到了解决该问题的方法。

我添加了

 IPQoS none
Run Code Online (Sandbox Code Playgroud)

到我的 /etc/ssh/ssh_config

看起来上一个版本中 ssh 客户端发生了一些变化,并且与本地路由器通信时出现问题。

我希望它有帮助。