RHEL 6/ CentOS 6: Slow SSH logins with DNS timeouts

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, February 09, 2012

Follow me on Twitter as @mattiasgeniar

If you’re experiencing slow logins via SSH on a Red Hat Enterprise 6 or CentOS 6 system, it’s probably caused by DNS that is taking too long to respond. Even with correct nameservers in /etc/resolv.conf, you may still find yourself stuck with slow logins.

It’s a known issue on the Red Hat knowledgebase article DOC-58626, but since it’s closed without login, I’ll share the solution as well.

The resolver uses the same socket for the A and AAAA requests.  Some hardware mistakenly only sends back one reply.  When that happens the client sytem will sit and wait for the second reply.  Turning this option on changes this behavior so that if two requests from the same port are not handled correctly it will close the  socket and open a new one before sending the second request.

The solution is to add the following line to your /etc/resolv.conf. Just add it all the way at the bottom, as the last line.

options single-request-reopen

That should fix your slow SSH logins, given you have valid and fast-responding nameservers in your /etc/resolv.conf.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.