使用特定域名时,从 Mac 到 CentOS 的 SSH 永远挂起

使用特定域名时,从 Mac 到 CentOS 的 SSH 永远挂起

我在 Google Compute 上运行 CentOS 服务器已有大约一年了。我每天都使用 SSH 登录,没有任何问题。突然,当我尝试使用 SSH 登录时,命令只是等待、等待、等待... 经过试验,似乎我可以使用各种其他方式引用服务器,轻松地使用 SSH 登录,但只有我的主域会导致问题。

这是我的命令行的复制/粘贴,其中域和 IP 已更改以保护无辜者。;)

Kenny-iMac:~$ ssh [email protected]
^C
Kenny-iMac:~$ host mymaindomain.com
mymaindomain.com has address xxx.xxx.xxx.xxx
mymaindomain.com mail is handled by 10 mxa.smtphost.com.
mymaindomain.com mail is handled by 10 mxb.smtphost.com.
Kenny-iMac:~$ ssh [email protected]
Last login: Sat Jun  2 18:43:05 2018 from nnn.nnn.nnn.nnn
[kenny@production-frontend-0 ~]$ exit
logout
Connection to xxx.xxx.xxx.xxx closed.
Kenny-iMac:~$ host otherdomainonserver.com
otherdomainonserver.com has address xxx.xxx.xxx.xxx
otherdomainonserver.com mail is handled by 10 mxa.smtphost.com.
otherdomainonserver.com mail is handled by 10 mxb.smtphost.com.
Kenny-iMac:~$ ssh [email protected]
Last login: Sat Jun  2 18:45:20 2018 from nnn.nnn.nnn.nnn
[kenny@production-frontend-0 ~]$ exit
logout
Connection to otherdomainonserver.com closed.
Kenny-iMac:~$ 

如果这有助于诊断问题,我可以更改上述内容以包含真实域,但我认为除非需要,否则最好将它们排除在外。

如果我能正确查找 mymaindomain.com 的 DNS,并且我的 ssh 密钥设置正确,可以让我登录(并且已经工作了一年),是什么原因导致这种情况突然发生?为什么 ssh 到我的主域会导致我挂起?

编辑:有人建议我这样做ssh -v以查看发生了什么。以下是输出:

$ ssh -v [email protected]
OpenSSH_7.6p1, LibreSSL 2.6.2
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to mymaindomain.com port 22.

然后它就挂了。

编辑 2:我更改了目标的 sshd_config,以将日志记录级别设置为DEBUG3最高。当我尝试时,我得到了ssh [email protected]绝对没有在日志中。当我成功登录时,日志中会喷出大量内容。ssh [email protected]

我感到很困惑。

答案1

一位朋友建议在远程 CentOS 服务器上启动 sshd 日志记录,我将其启动,DEBUG3当我尝试从我的 Mac 连接时,服务器完全没有记录任何内容。这让我意识到,我从我的 Mac 尝试 ssh 根本无法触及远程服务器。

我尝试 ping,但 ping 失败。但我能够使用 Chrome 连接并加载服务器上托管的其中一个网站,因此这说明我能够通过域名进行查找和连接。但是,现在我认为我被这个数据点误导了,Chrome 可能缓存了过去某个时间点的 IP 查找,并且能够使用它。

我使用 homebrew 安装了 telnet,并尝试连接到 mymaindomain.com 端口 22,但它挂了...但随后超时并给了我一个实际的错误消息!

nodename nor servname provided, or not known

该错误消息让我浏览了几个页面,这些页面表明 MacOS X 的内部 DNS 解析器可能是问题所在,并且他们建议 killall -HUP mDNSResponder. 但那并没有解决问题。

其他人建议 launchctl unload -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist其次是 launchctl load -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

但那人却不肯跑,说道:Operation not permitted while System Integrity Protection is engaged“。

因此,我认为重新加载 Mac OS X 的内部 DNS 缓存的最简单方法是重新启动。并且成功了。当我没有尝试关闭它然后再打开时,我犯了一个经典错误。

相关内容