Ssh – Fix slow SSH login due to reverse lookup without disabling UseDNS

binddomain-name-systemssh

Whenever I try to connect to my server from Azure VM it takes a lot of time due to failing reverse DNS lookup.

I can disable lookups with UseDNS no and completely bypass the problem but this makes logs less useful so I'd rather not do it that way.

I'm also running local BIND server for caching and serving local zones.

What I've noticed is that whenever SSH client sends username, named emits multiple warnings like:

Mar 10 22:56:04 ghost named[1813]: DNS format error from 8.8.8.8#53 resolving 137.161.97.23.in-addr.arpa/PTR for client 127.0.0.1#37839: invalid response

This is repeated for every server configured as forwarder as well as for microsoft servers serving that zone. Then there is a 1s pause and the whole thing repeats 4 times.

If I execute nslookup -type=ptr -nosearch -d2 137.161.97.23.in-addr.arpa 207.46.75.254 similar warnings happen but they are not repeated 4 times.

So my questions are:

  1. Why is this response not cached ?
  2. Why does sshd retry it 3 times ?
  3. Can I do something about it ?

UPDATE
I know my client machine has no PTR record but it's perfectly valid for client to not have one. Besides I have no control over DNS records of client machines.

Best Answer

Depending on your use case and what exactly you are trying to avoid by not fixing either your DNS or your ssh config, you can modify hosts files on your servers to report the name and IP to sshd.

It isn't cached because nslookup doesn't use your system's resolver (only the entries in resolv.conf), if you are, in fact, running a caching name server locally. By default, there is no local cache on Linux servers. Common ones include nscd, sssd, and bind.

Related Topic