如何调试 SSH“连接超时”

如何调试 SSH“连接超时”

从 host1 连接到 host2 时,有时会出现错误

Errno::ETIMEDOUT: Connection timed out - connect(2)

尝试连接时在 host1 上进行 TCP 转储 (tcpdump -vv -i eth0 -s 0 '端口 22 和主机 host2'):

19:13:47.510774 IP (tos 0x0, ttl 64, id 44238, offset 0, flags [DF], proto TCP (6), length 60)
    host1.50274 > host2.ssh: Flags [S], cksum 0x1409 (correct), seq 2693070134, win 5840, options [mss 1460,sackOK,TS val 867914232 ecr 0,nop,wscale 7], length 0
19:13:50.508713 IP (tos 0x0, ttl 64, id 44239, offset 0, flags [DF], proto TCP (6), length 60)
    host1.50274 > host2.ssh: Flags [S], cksum 0x111b (correct), seq 2693070134, win 5840, options [mss 1460,sackOK,TS val 867914982 ecr 0,nop,wscale 7], length 0
19:13:56.508707 IP (tos 0x0, ttl 64, id 44240, offset 0, flags [DF], proto TCP (6), length 60)
    host1.50274 > host2.ssh: Flags [S], cksum 0x0b3f (correct), seq 2693070134, win 5840, options [mss 1460,sackOK,TS val 867916482 ecr 0,nop,wscale 7], length 0

同时在 host2 上(tcpdump -vv -i eth0 -s 0 'port 22 and host host1'):

19:13:47.510512 IP (tos 0x0, ttl 62, id 44238, offset 0, flags [DF], proto TCP (6), length 60)
    host1.50274 > host2.ssh: Flags [S], cksum 0x1409 (correct), seq 2693070134, win 5840, options [mss 1460,sackOK,TS val 867914232 ecr 0,nop,wscale 7], length 0
19:13:50.508453 IP (tos 0x0, ttl 62, id 44239, offset 0, flags [DF], proto TCP (6), length 60)
    host1.50274 > host2.ssh: Flags [S], cksum 0x111b (correct), seq 2693070134, win 5840, options [mss 1460,sackOK,TS val 867914982 ecr 0,nop,wscale 7], length 0
19:13:56.508447 IP (tos 0x0, ttl 62, id 44240, offset 0, flags [DF], proto TCP (6), length 60)
    host1.50274 > host2.ssh: Flags [S], cksum 0x0b3f (correct), seq 2693070134, win 5840, options [mss 1460,sackOK,TS val 867916482 ecr 0,nop,wscale 7], length 0

问题可能出在哪里?我该如何调试?

答案1

我建议使用“ping -s 1450”测试网络(-s 会更改探测数据包的大小,mtr 似乎没有类似的选项)。如果第一个数据包成功,但其他数据包失败,通常是因为问题与数据包大小有关(例如,在大雨下的外部无线电链路等有问题的介质上),小数据包的丢失率几乎为零,大数据包的丢失率接近 1。大多数协议从小协商数据包开始,然后切换到大数据包。

我注意到您说 HTTP 很好,这会反驳我的假设,但我现在没有其他想法。

相关内容