Linux – ssh + long ssh delay and resolv conf file

linuxssh

Linux system running Redhat 5.1.

When I connect to the machines with SSH there is a long delay before the login completes and I get a shell.

I did some research and found a solution to this problem that suggested that I could remove the /etc/resolv.conf, and then logins would work quickly. I tried doing this and it actually worked; removing the /etc/resolv.conf sped things up.

So now I want to understand why this is causing a problem, and how to get fast SSH logins without breaking name resolution.

Update: UseDNS no was in sshd_config (but has not fixed the issue)

Best Answer

As a security measure when you connect to ssh server, the server will perform several DNS lookups on the IP address you are connecting from. These DNS checks make take a while, particularly if the reverse zones are not setup properly for the IP addresses you are connecting from.

In your /etc/ssh/sshd_config there is an option you can set to disable DNS checks. Specifically you would want to set UseDNS no.

man sshd_config

UseDNS

Specifies whether sshd(8) 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''.

Another common source of problems can be related to tcpwrappers. If SSH is compiled to use tcpwrappers, and tcpwrappers is compiled to do DNS lookups, then you can see slowness from this.

If you are connecting from within your network, the majority of the delay will be fixed by setting up proper reverse DNS zones.