ssh登录慢的解决方法(关闭usedns选项)

发布时间:2020-08-11编辑:脚本学堂
本文介绍下,ssh登录很慢的一个原因及解决办法,那就是关闭掉usedns选项。有需要的朋友参考下。

当登录SSH时总是要停顿等待一下才能连接上,此时可以考虑是由于OpenSSH服务器开启了DNS查找选项UsedNS的原因。

UseDNS 选项打开状态下,当客户端试图登录SSH服务器时,服务器端先根据客户端的IP地址进行DNS PTR反向查询出客户端的主机名,然后根据查询出的客户端主机名进行DNS正向A记录查询,验证与其原始IP地址是否一致,这是防止客户端欺骗的一种措施。

一般情况下,动态IP不会有PTR记录,可以考虑关闭掉usedns选项。

关闭usedns选项的具体操作如下。

一、编辑文件
vim /etc/ssh/sshd_config

二、找到以下字符
#UseDNS yes
在其下方新建一行,填入
UseDNS no

三、保存并重启SSH
service sshd restart

附,老外提供的文章。
SSH Reverse DNS Lookup Disable

This isn’t the most interesting of posts, but a good “note to self” for future reference. If not disabled, SSHD will try to do a slow reverse lookup of the IP address of the client causing for an unnecessary delay during authentication. I often run into trouble with this when creating a new install of linux or FreeBSD.

To disable it, in the file /etc/ssh/sshd_config add the line below:
UseDNS no

您可能感兴趣的文章:
ssh连接缓慢的解决方法
ssh登录很慢但登录成功后速度正常的问题分析