Slow DNS Lookups Suddenly

I have an Ubuntu 12.04 server and the DNS looksups appear to be extremely slow. time curl www.google.com takes 40 seconds and time curl 173.194.74.147 takes 70ms. I reinstalled another dedicated server with Ubuntu 12.04 and it has the same problem too.

Question: I have been asked to check my DNS configuration. So I added google's DNS servers but I am still getting slow DNS resolves. What else should I check for?

/etc/resolve/conf

nameserver 127.0.0.1
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 213.186.33.99
search ovh.net

Solution 1:

I just had this problem. I'm not sure about your case, but for me, it was a IPv6 network problem:

me@server:~$ time wget -O /dev/null google.com

--2014-08-26 09:44:15--  http://google.com/
Resolving google.com (google.com)... 2607:f8b0:4005:800::100e, 74.125.239.98, 74.125.239.100, ...
Connecting to google.com (google.com)|2607:f8b0:4005:800::100e|:80... ^C

real    1m32.876s
user    0m0.000s
sys     0m0.000s

I had to stop wget using Ctrl+C after 1.5 minutes. Note the 2607:f8b0:4005:800::100e indicates an IPv6 lookup. I added the following lines to /etc/sysctl.conf:

# Disable IPv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

And then refreshed those settings via: sudo sysctl -p Source: http://www.noobslab.com/2012/05/disable-ipv6-if-your-internet-is.html

Once I did that, things started working:

me@server:~$ time wget -O /dev/null google.com

--2014-08-26 09:46:12--  http://google.com/
Resolving google.com (google.com)... 74.125.239.98, 74.125.239.100, 74.125.239.102, ...
Connecting to google.com (google.com)|74.125.239.98|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.google.com/ [following]
--2014-08-26 09:46:12--  http://www.google.com/
Resolving www.google.com (www.google.com)... 74.125.239.115, 74.125.239.112, 74.125.239.116, ...
Connecting to www.google.com (www.google.com)|74.125.239.115|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `/dev/null'

    [ <=>                                   ] 19,139      --.-K/s   in 0.002s  

2014-08-26 09:46:12 (10.6 MB/s) - `/dev/null' saved [19139]


real    0m0.093s
user    0m0.004s
sys 0m0.000s

Note: you can just run wget google.com but it will save a file in your current location. -O /dev/null will suppress that.