# Slow DNS lookups [solved]

## katratxo

Hi all,

I've been struggling with this problem. I searched several times in this forums without success.

I have a fresh gentoo installation, with IPv6 support disabled in the kernel. Everything is working fine but the DNS lookups. I know that in many times this problem is related to the IPv6 support. I tested my laptop in my office network (with the same DNS servers and goes fast), but in my house the DNS lookups can take up to 10-15 secs.

I have another laptop with Windowz XP, connected to the same router and works just fine; so I think that I can discard a network problem in my house.

I'm using -ipv6 in my USE flag (in the make.conf looks like this):

```

 USE="-gnome -kde -qt3 -qt4 -ipv6 X dvd dbus hal alsa cdr xulrunner"

```

After adding the -ipv6 I made a emerge -avDuN world (because the -ipv6 was added after the installation).

My /etc/resolv.conf looks like this:

```

nameserver 80.58.61.254

nameserver 80.58.61.250

```

Here you have a list of tests I've been collecting to isolate the issue.

Downloading a small file with wget

```

** First round **

time wget http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

--2008-08-27 07:10:04--  http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

Resolving mirror.switch.ch... 130.59.10.36

Connecting to mirror.switch.ch|130.59.10.36|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 568 [application/x-bzip2]

Saving to: `stage3-i686-2008.0.tar.bz2.DIGESTS'

100%[======================================>] 568         --.-K/s   in 0s      

2008-08-27 07:10:09 (37.3 MB/s) - `stage3-i686-2008.0.tar.bz2.DIGESTS' saved [568/568]

real   0m5.465s

user   0m0.000s

sys   0m0.004s

** Second round **

time wget http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

--2008-08-27 07:12:37--  http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

Resolving mirror.switch.ch... 130.59.10.36

Connecting to mirror.switch.ch|130.59.10.36|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 568 [application/x-bzip2]

Saving to: `stage3-i686-2008.0.tar.bz2.DIGESTS.1'

100%[======================================>] 568         --.-K/s   in 0s      

2008-08-27 07:12:47 (30.7 MB/s) - `stage3-i686-2008.0.tar.bz2.DIGESTS.1' saved [568/568]

real   0m10.335s

user   0m0.004s

sys   0m0.000s

```

Note: The download took almost 0 secs, so the rest of the time was spent resolving the name mirror.switch.ch

Querying the DNS server with dig

```

** First round **

time dig google.es

; <<>> DiG 9.4.2-P2 <<>> google.es

;; global options:  printcmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2528

;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:

;google.es.                     IN      A

;; ANSWER SECTION:

google.es.              1102    IN      A       72.14.221.104

google.es.              1102    IN      A       66.249.93.104

google.es.              1102    IN      A       216.239.59.104

;; Query time: 53 msec

;; SERVER: 80.58.61.254#53(80.58.61.254)

;; WHEN: Wed Aug 27 07:15:48 2008

;; MSG SIZE  rcvd: 75

real    0m6.065s

user    0m0.004s

sys   0m0.000s

** Sencond round **

time dig google.es

; <<>> DiG 9.4.2-P2 <<>> google.es

;; global options:  printcmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1310

;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:

;google.es.         IN   A

;; ANSWER SECTION:

google.es.      1800   IN   A   216.239.59.104

google.es.      1800   IN   A   72.14.221.104

google.es.      1800   IN   A   66.249.93.104

;; Query time: 104 msec

;; SERVER: 80.58.61.254#53(80.58.61.254)

;; WHEN: Wed Aug 27 07:19:02 2008

;; MSG SIZE  rcvd: 75

real   0m0.109s

user   0m0.004s

sys   0m0.000s

** Third round **

time dig google.es

; <<>> DiG 9.4.2-P2 <<>> google.es

;; global options:  printcmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 23789

;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:

;google.es.         IN   A

;; ANSWER SECTION:

google.es.      353   IN   A   72.14.221.104

google.es.      353   IN   A   66.249.93.104

google.es.      353   IN   A   216.239.59.104

;; Query time: 53 msec

;; SERVER: 80.58.61.250#53(80.58.61.250)

;; WHEN: Wed Aug 27 07:19:46 2008

;; MSG SIZE  rcvd: 75

real   0m7.065s

user   0m0.000s

sys   0m0.004s

```

Note: Some times can take up to 10 secs

Querying DNS server using host

```

* First round *

time host www.gentoo.org

www.gentoo.org has address 209.177.148.229

www.gentoo.org has address 209.177.148.228

real    0m14.291s

user    0m0.000s

sys     0m0.004s

* Second round *

time host www.gentoo.org

www.gentoo.org has address 209.177.148.228

www.gentoo.org has address 209.177.148.229

real    0m9.287s

user    0m0.004s

sys     0m0.000s

```

Note: The first two lines came almost 'immediately', but then waits a few seconds to finish the job

Pinging the DNS

```

* First DNS server *

ping -c3 80.58.61.254

PING 80.58.61.254 (80.58.61.254) 56(84) bytes of data.

64 bytes from 80.58.61.254: icmp_seq=1 ttl=125 time=56.8 ms

64 bytes from 80.58.61.254: icmp_seq=2 ttl=125 time=55.7 ms

64 bytes from 80.58.61.254: icmp_seq=3 ttl=125 time=56.9 ms

--- 80.58.61.254 ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 2006ms

rtt min/avg/max/mdev = 55.711/56.474/56.911/0.575 ms

* Second DNS server *

ping -c3 80.58.61.250

PING 80.58.61.250 (80.58.61.250) 56(84) bytes of data.

64 bytes from 80.58.61.250: icmp_seq=1 ttl=125 time=58.3 ms

64 bytes from 80.58.61.250: icmp_seq=2 ttl=125 time=57.9 ms

64 bytes from 80.58.61.250: icmp_seq=3 ttl=125 time=58.1 ms

--- 80.58.61.250 ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 2007ms

rtt min/avg/max/mdev = 57.926/58.126/58.338/0.168 ms

```

Tracerouting to the DNS server

```

* First round - one dns server *

time traceroute -4 -I 80.58.61.254

traceroute to 80.58.61.254 (80.58.61.254), 30 hops max, 40 byte packets

 1  192.168.1.1 (192.168.1.1)  1.641 ms  2.580 ms  2.982 ms

 2  192.168.153.1 (192.168.153.1)  49.529 ms  52.759 ms *

 3  * * *

 4  * * *

 5  * * *

 6  * * *

 7  * 254.Red-80-58-61.staticIP.rima-tde.net (80.58.61.254)  60.064 ms  63.431 ms

real   0m10.295s

user   0m0.000s

sys   0m0.000s

* Second round - the other dns server*

time traceroute -4 -I 80.58.61.250

traceroute to 80.58.61.250 (80.58.61.250), 30 hops max, 40 byte packets

 1  192.168.1.1 (192.168.1.1)  1.879 ms  2.500 ms *

 2  * * *

 3  * * *

 4  * * *

 5  * * *

 6  * 250.Red-80-58-61.staticIP.rima-tde.net (80.58.61.250)  57.364 ms  60.707 ms

real   0m20.186s

user   0m0.000s

sys   0m0.000s

```

A friend of my suggest to use strace to see where the dns lookup hangs. A complete strace is located in http://pastebin.ca/1186065

As you can see there is a few timeouts there

```

     0.000068 gettimeofday({1219815148, 844521}, NULL) = 0

     0.000069 sendmsg(20, {msg_name(16)={sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("80.58.61.254")}, msg_iov(1)=[{"\266*\1\0\0\1\0\0\0\0\0\0\3www\6gentoo\3org\0\0\1\0\1", 32}], msg_controllen=0, msg_flags=0}, 0) = 32

     0.000177 gettimeofday({1219815148, 844769}, NULL) = 0

     0.000064 select(21, [20], [], NULL, {0, 0}) = 0 (Timeout)

     0.000071 gettimeofday({1219815148, 844902}, NULL) = 0

     0.000056 gettimeofday({1219815148, 844958}, NULL) = 0

     0.000057 select(21, [20], [], NULL, {0, 998818}) = 0 (Timeout)

     0.998101 gettimeofday({1219815149, 843118}, NULL) = 0

     0.000063 gettimeofday({1219815149, 843180}, NULL) = 0

     0.000059 select(21, [20], [], NULL, {0, 596}) = 0 (Timeout)

```

This happens with both network cards wired and wireless.

A really don't know how to solve the problem. My Windowz machine in my home's network with the same DNS works fine.  My gentoo laptop (with the same DNS) in my office's network goes like a rocket!!

Any clue, hint?

Update: changed the title of the thread. See the last post.

Best Regards,

----------

## Exil

Search for opendns and try that. It solved some people problems with crapy isp dns.

----------

## katratxo

Hi Exil,

I tried also with DNS server provided by OpenDNS, in fact with my ISP' DNS I got a better response time.

Anyway, thanks for the hint.

Best Regards,

----------

## PaulBredbury

I would check:

```
/etc/sysctl.conf

iptables -L -n
```

----------

## katratxo

Hi PaulBredbury,

I don't have iptables enabled. But I'll try your suggestion.

I have made other tests, booting my laptop with Ubuntu 7.10, Gentoo 2007, Gentoo 2008 LiveCDs and try to download the same small file.

Ubuntu 7.10 LiveCD

```

 time wget http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

--05:14:19--  http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

           => `stage3-i686-2008.0.tar.bz2.DIGESTS'

Resolving mirror.switch.ch... 130.59.10.36, 2001:620:0:8::20

Connecting to mirror.switch.ch|130.59.10.36|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 568 [application/x-bzip2]

 

100%[====================================>] 568           --.--K/s             

 

05:14:19 (46.16 MB/s) - `stage3-i686-2008.0.tar.bz2.DIGESTS' saved [568/568]

 

 

real    0m3.184s

user    0m0.004s

sys     0m0.012s

```

Tests with Gentoo 2007 LiveCD

```

livecd tmp # wget http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

--05:25:21--  http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

           => `stage3-i686-2008.0.tar.bz2.DIGESTS'

Resolving mirror.switch.ch... 130.59.10.36, 2001:620:0:8::20

Connecting to mirror.switch.ch|130.59.10.36|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 568 [application/x-bzip2]

100%[====================================================================================>] 568           --.--K/s             

05:25:42 (104.09 MB/s) - `stage3-i686-2008.0.tar.bz2.DIGESTS' saved [568/568]

livecd tmp # time wget http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

--05:25:48--  http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

           => `stage3-i686-2008.0.tar.bz2.DIGESTS.1'

Resolving mirror.switch.ch... 130.59.10.36, 2001:620:0:8::20

Connecting to mirror.switch.ch|130.59.10.36|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 568 [application/x-bzip2]

100%[====================================================================================>] 568           --.--K/s             

05:26:09 (103.14 MB/s) - `stage3-i686-2008.0.tar.bz2.DIGESTS.1' saved [568/568]

real   0m20.435s

user   0m0.000s

sys   0m0.000s

```

Tests with Gentoo 2008 LiveCD

```

livecd tmp # time wget http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

--05:31:59--  http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

           => `stage3-i686-2008.0.tar.bz2.DIGESTS'

Resolving mirror.switch.ch... 130.59.10.36, 2001:620:0:8::20

Connecting to mirror.switch.ch|130.59.10.36|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 568 [application/x-bzip2]

100%[====================================================================================>] 568           --.--K/s             

05:32:04 (32.32 MB/s) - `stage3-i686-2008.0.tar.bz2.DIGESTS' saved [568/568]

real   0m11.459s

user   0m0.000s

sys   0m0.030s

livecd tmp # time wget http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

--05:32:12--  http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

           => `stage3-i686-2008.0.tar.bz2.DIGESTS.1'

Resolving mirror.switch.ch... 130.59.10.36, 2001:620:0:8::20

Connecting to mirror.switch.ch|130.59.10.36|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 568 [application/x-bzip2]

100%[====================================================================================>] 568           --.--K/s             

05:32:12 (34.02 MB/s) - `stage3-i686-2008.0.tar.bz2.DIGESTS.1' saved [568/568]

real   0m0.262s

user   0m0.000s

sys   0m0.000s

livecd tmp # time wget http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

--05:32:19--  http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

           => `stage3-i686-2008.0.tar.bz2.DIGESTS.2'

Resolving mirror.switch.ch... 130.59.10.36, 2001:620:0:8::20

Connecting to mirror.switch.ch|130.59.10.36|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 568 [application/x-bzip2]

100%[====================================================================================>] 568           --.--K/s             

05:32:19 (35.91 MB/s) - `stage3-i686-2008.0.tar.bz2.DIGESTS.2' saved [568/568]

real   0m0.272s

user   0m0.010s

sys   0m0.000s

livecd tmp # time wget http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

--05:32:33--  http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

           => `stage3-i686-2008.0.tar.bz2.DIGESTS.3'

Resolving mirror.switch.ch... 130.59.10.36, 2001:620:0:8::20

Connecting to mirror.switch.ch|130.59.10.36|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 568 [application/x-bzip2]

100%[====================================================================================>] 568           --.--K/s             

05:32:38 (34.02 MB/s) - `stage3-i686-2008.0.tar.bz2.DIGESTS.3' saved [568/568]

real   0m5.259s

user   0m0.000s

sys   0m0.000s

livecd tmp # time wget http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

--05:32:43--  http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

           => `stage3-i686-2008.0.tar.bz2.DIGESTS.4'

Resolving mirror.switch.ch... 130.59.10.36, 2001:620:0:8::20

Connecting to mirror.switch.ch|130.59.10.36|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 568 [application/x-bzip2]

100%[====================================================================================>] 568           --.--K/s             

05:32:43 (34.02 MB/s) - `stage3-i686-2008.0.tar.bz2.DIGESTS.4' saved [568/568]

real   0m0.279s

user   0m0.000s

sys   0m0.000s

livecd tmp # time wget http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

--05:32:48--  http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

           => `stage3-i686-2008.0.tar.bz2.DIGESTS.5'

Resolving mirror.switch.ch... 130.59.10.36, 2001:620:0:8::20

Connecting to mirror.switch.ch|130.59.10.36|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 568 [application/x-bzip2]

100%[====================================================================================>] 568           --.--K/s             

05:32:48 (35.91 MB/s) - `stage3-i686-2008.0.tar.bz2.DIGESTS.5' saved [568/568]

real   0m0.267s

user   0m0.000s

sys   0m0.000s

livecd tmp # time wget http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

--05:33:20--  http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

           => `stage3-i686-2008.0.tar.bz2.DIGESTS.6'

Resolving mirror.switch.ch... 130.59.10.36, 2001:620:0:8::20

Connecting to mirror.switch.ch|130.59.10.36|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 568 [application/x-bzip2]

100%[====================================================================================>] 568           --.--K/s             

05:33:20 (34.02 MB/s) - `stage3-i686-2008.0.tar.bz2.DIGESTS.6' saved [568/568]

real   0m0.254s

user   0m0.000s

sys   0m0.000s

```

Note:  Look the difference between executions from 0m0.254s through 0m5.259s

Tests with Gentoo fresh installation

```

wget http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS                  mwget http://mirror.switc--2008-08-28 05:43:57--  http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGResolving mirror.switch.ch... 130.59.10.36switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

Connecting to mirror.switch.ch|130.59.10.36|:80... connected./gentoo/releases/x86

HTTP request sent, awaiting response... 200 OK

Length: 568 [application/x-bzip2]

Saving to: `stage3-i686-2008.0.tar.bz2.DIGESTS.1'

100%[======================================>] 568         --.-K/s   in 0s      

2008-08-28 05:44:08 (36.1 MB/s) - `stage3-i686-2008.0.tar.bz2.DIGESTS.1' saved [568/568]

real   0m10.300s

user   0m0.008s

sys   0m0.000s

es/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTSftp/mirror/gentoo/release

--2008-08-28 05:44:12--  http://mirror.switch.ch/ftp/mirror/gentoo/releases/x86/current/stages/stage3-i686-2008.0.tar.bz2.DIGESTS

Resolving mirror.switch.ch... 130.59.10.36

Connecting to mirror.switch.ch|130.59.10.36|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 568 [application/x-bzip2]

Saving to: `stage3-i686-2008.0.tar.bz2.DIGESTS.2'

100%[======================================>] 568         --.-K/s   in 0s      

2008-08-28 05:44:23 (38.8 MB/s) - `stage3-i686-2008.0.tar.bz2.DIGESTS.2' saved [568/568]

real   0m10.344s

user   0m0.000s

sys   0m0.004s

```

Update: Note that those tests were made with the same resolv.conf

----------

## katratxo

Can be my problem a out of sync clock?

Here you have a dmesg message on clock

```

dmesg | grep unstable

Marking TSC unstable due to: TSC halts in idle.

Clocksource tsc unstable (delta = -247855370 ns)

```

Then I start the ntp client and my drift file show a 6sec difference

```

cat /var/lib/ntp/ntp.drift 

6.063

```

----------

## katratxo

After a couple of days struggling with this problem, and making complicated tests; the problem was in my crappy router. I would like to give many thanks to my good friend iarwain, that help me tracing the problem.

Somehow the Windowz machine just works fine with the configuration of external DNS servers, but in my gentoo box i need to put the router as a DNS server (then the router forwards the requests to the DNS relay configurated servers).

Thanks to all for your suggestions.

Best Regards,

----------

