使用ssh时有时会出现连接一个服务器的时候超慢,一般会显示一下信息,然后就卡在那不动了
    Connecting to 10.10.10.10:22...Connection established.To escape to local shell, press 'Ctrl+Alt+]'.

    过好长时间之后才会显示类似以下的信息
    Last login: Mon Jun 3 13:19:59 2013 from 10.10.10.1

    会出现这种问题是因为ssh默认有一个配置项UseDNS(文档中解释此配置项的意思为:UseDNS Specifies whether sshd should look up the remote host name and check that the resolved host name for the remote IP address maps back to the very same IP address. The default is “yes”.)

    当此项配置不开启时默认值为UseDNS yes,这样会导致ssh在有连接过来的时候进行dns解析,所以会产生较长时间的停顿,所以要解决此问题可以将此配置项打开,然后值改为no,操作如下:
    vim /etc/ssh/sshd_config

    将第5行(UseDNS)的注释去掉,然后将值改为no(因为默认是YES)

    1. #Compression delayed
    2. #ClientAliveInterval 0
    3. #ClientAliveCountMax 3
    4. #ShowPatchLevel no
    5. UseDNS no
    6. #PidFile /var/run/sshd.pid
    7. #MaxStartups 10
    8. #PermitTunnel no
    9. #ChrootDirectory none

    然后重启一下sshd服务。

    1. /etc/init.d/ssh restart
    2. /etc/init.d/ssh start