sin*_*law 57
问题可能是ssh正在尝试连接到解析为的所有不同IP www.google.com.例如在我的机器上:
# ssh -v -o ConnectTimeout=1 -o ConnectionAttempts=1 www.google.com
OpenSSH_5.9p1, OpenSSL 0.9.8t 18 Jan 2012
debug1: Connecting to www.google.com [173.194.43.20] port 22.
debug1: connect to address 173.194.43.20 port 22: Connection timed out
debug1: Connecting to www.google.com [173.194.43.19] port 22.
debug1: connect to address 173.194.43.19 port 22: Connection timed out
debug1: Connecting to www.google.com [173.194.43.18] port 22.
debug1: connect to address 173.194.43.18 port 22: Connection timed out
debug1: Connecting to www.google.com [173.194.43.17] port 22.
debug1: connect to address 173.194.43.17 port 22: Connection timed out
debug1: Connecting to www.google.com [173.194.43.16] port 22.
debug1: connect to address 173.194.43.16 port 22: Connection timed out
ssh: connect to host www.google.com port 22: Connection timed out
Run Code Online (Sandbox Code Playgroud)
如果我使用特定的IP运行它,它返回的速度要快得多.
编辑:我已经定时(带time),结果如下:
ConnectTimeout 选项允许您告诉您的 ssh 客户端在返回错误之前您愿意等待连接多长时间。通过将 ConnectTimeout 设置为 1,您实际上是在说“最多尝试 1 秒,如果您还没有连接,则失败”。
问题是当您按名称连接时,DNS 查找可能需要几秒钟。通过 IP 地址连接要快得多,实际上可能在一秒钟或更短的时间内工作。sinelaw 正在经历的是,每次通过 DNS 名称进行连接的尝试都无法在一秒内发生。ConnectTimeout 的默认设置遵循 linux 内核连接超时,这通常很长。
| 归档时间: |
|
| 查看次数: |
107523 次 |
| 最近记录: |