# DNS resolv is SLOW!!

## Klebel

It takes about 10 sec for me to resolv a DNS when i  ping a host, but when i ping an ip address it is blazing fast. why?

I have disabled IPv6 in my kernel, commented out all the IPv6 stuff from my /etc/hosts, added -ipv6 to my make.conf and recompiled everything. I have also switched NIC cards, went back and fourth from DHCP to STATIC, and still no go.

is there anything else I am missing? any help will be apreciated.

----------

## wmgoree

Maybe your nameservers are just slow? Can you show the contents of /etc/resolv.conf?

If you have the net-dns/bind-tools package installed, run dig or nslookup and see how long it takes. If you don't have that package installed, install it. It's awesome.

----------

## moocha

One possible cause for something like this is having more than one nameserver line in resolv.conf, and one or more of them not responding. The resolver library tries all name servers specified there in a round robin fashion, but tries the next one only after the query to the previous one timed out. You could try and ping the nameservers, determine which one times out, and remove it from resolv.conf.

Note that if that was the cause and you're using DHCP, resolv.conf gets overwritten on each IP lease refresh, getting you back to square one. You then might want to look around /etc/conf.d/net.example in the DHCP section to see how to prevent that from happening.

Edit: Crossed posts with wmgoree  :Smile: .

----------

## wmgoree

Incidentally, how you keep dhcpcd from overwriting your /etc/resolv.conf is

```
dhcpcd -R $INTERFACE
```

Since I run (and trust) my own nameservers I end up doing that a lot on my laptop.

----------

## CoolAJ86

My DNS resolution is terribly slow. In fact, it will often time-out! If I use an IP address instead of a domain name, everything works fine. This problem started happening several weeks ago and since then I've reinstalled Gentoo (because I dramatically changed my CFLAGS [less ricing] and wanted to change my partition scheme - thus quicker to reinstall than emerge -e world). Immediately after installing there were a few hours when I had no DNS slowness. Now it's back again!

I've checked all the basics:

I've tested IP vs DNS, it's DNS

I've pinged the nameservers while everything is going doggedly slow or timing out and yet I get a quick reply from them (or ANY ip-based request).

```
emerge net-analyzer/dnstracer

emerge net-analyzer/traceroute

emerge net-dns/bind-tools

dnstracer www.google.com

nslookup www.google.com

dig www.google.com

traceroute www.google.com
```

None of these tools will consistently resolv any Internet address, not even my own (coolaj86.homedns.org). It's all hit-and-miss.

/etc/resolv.conf:

```
domain coolaj86.homedns.org

nameserver 151.203.0.85
```

 (Verizon is my ISP)

/etc/make.conf:

```
USE="-ipv6"
```

zgrep -i ipv6 /proc/config.gz:

```
# CONFIG_IP_TCPDIAG_IPV6 is not set

# CONFIG_IPV6 is not set
```

I even took my firewall down for a few minutes!

```
/etc/init.d/iptables stop
```

Others on my network seem to be doing fine.

What performs the name resolution? Is it in the kernel?

Possibly due to building said 'performer-of-name-resolution' being built with unsafe CFLAGS?

Is there any sort of local cache which stores this information and may be goofing up?

Any additional troubleshooting tips?

Are there any others that are experiencing this problem? Solved this problem?

My next step is to locally cache DNS, I'll report on how that goes.

```
emerge djbdns && dnscache-setup 
```

My next next step is to reinstall Ubuntu and Windows on a spare drive and see what results they yield (may be a router issue locally?)

WOW!! It's only been a few minutes, so there's no telling for sure that this is a solution, however

```
emerge djbdns && /etc/init.d/svscan start && dnscache-setup && rc-update add svscan default
```

 seems to have done the trick. One other note: I told djdns to use the router which is connected to the DSL modem (192.168.2.1) instead of directly my ISP's DNS servers.

----------

## wmgoree

 *CoolAJ86 wrote:*   

> 
> 
> What performs the name resolution? Is it in the kernel?
> 
> Possibly due to building said 'performer-of-name-resolution' being built with unsafe CFLAGS?
> ...

 

The C library performs name resolution.

```
man 3 resolver
```

for more information.

There generally is not a cache if you're using the vanilla libc.

There are tons of troubleshooting tips. Step one is to install bind-tools and see how your response is from other nameservers. As an example, Verizon's nameservers are publicly usable and generally pretty fast, so try

```
dig somehost.somedomain.com @otherguy.gte.net
```

Or find some other nameservers you trust. If you can get fast responses from one of those nameservers, it's probably just that the server you are using is not being fast enough.

----------

## CoolAJ86

Nice Tip!

keeping in mind that I installed djdns (working well so far)

```
dig www.google.com @127.0.0.1 # FAST

dig www.google.com @192.168.2.1 # OK~SLOW

dig www.google.com @151.203.0.85 # SLOW~TIME-OUT

dig www.google.com @otherguy.gte.net # (206.46.254.13) FAST

dig www.google.com @bigguy.gte.net # (206.124.64.1) FAST
```

Since my router (192.168.2.1) forwards to my ISP (151.203.0.85) I have no idea what the deal is with the time-outs.

Are there any netiquette and or legal issues with using someone else's DNS server instead of the one provided by my ISP?

----------

## kar1107

I faced the slow DNS from firefox. After lots of tries (disable ipv6, enable firefox dns caching, fixup /etc/hosts files), I think I have found the real solution  :Smile:   again its gathered from other posts. The solution is just to reverse the order of entries in /etc/resolv.conf. 

Using dig on both the name server there is a HUGE difference in response. Something like 22msec for one..and 500 msec for another.

I guess its just that my ISP doesn't evenly distributed the (primary, secondary) pairs across customers. So primary is getting overloaded big time but secondary is relatively free.

I think probably I need to find a way to do this automatically on getting the results from dhcpd.. but thats more of a luxury to have  :Cool: 

About your legal question, I don't think it is an issue. But the ISP may fail to honor requests from non-customers thru' ACLs. But I don't they do it.

----------

## CoolAJ86

you might try putting something like 

```
#/bin/bash

cat /etc/resolv.conf | sort | while read DNS; do echo ${DNS} > /etc/resolv.conf; done
```

in /etc/rc.d/init.d/boot.local or /etc/init.d/local

you can use sort -r to reverse the order

or you edit the file that has your network information and add the "-R" option to dhcpcd-opts.

/etc/conf.d/net # Gentoo

/etc/sysconfig/network-scripts/ifcfg-eth0 # Redhat/Fedora

If you use dhclient or pump instead they probably have a similar option which disables overwriting the DNS info. Read the man page.

----------

## anomalizer

 *moocha wrote:*   

> One possible cause for something like this is having more than one nameserver line in resolv.conf, and one or more of them not responding. The resolver library tries all name servers specified there in a round robin fashion, but tries the next one only after the query to the previous one timed out. You could try and ping the nameservers, determine which one times out, and remove it from resolv.conf.
> 
> 

 

I hit this problem! Any idea on how long the offending server is not tried i.e. does a failing server get removed off the list for a while?

----------

## bunder

if you got a spare box, you could always run your own dns server... don't need any zones, but it can do the resolving for you and it has access to the root servers. (so it doesn't contact your isp's dns server)

----------

## arnuld

 *Klebel wrote:*   

> It takes about 10 sec for me to resolv a DNS when i  ping a host, but when i ping an ip address it is blazing fast. why?
> 
> I have disabled IPv6 in my kernel, commented out all the IPv6 stuff from my /etc/hosts, added -ipv6 to my make.conf and recompiled everything. I have also switched NIC cards, went back and fourth from DHCP to STATIC, and still no go.
> 
> is there anything else I am missing? any help will be apreciated.

 

OUCH! i had the same problem, exactly same problem in Debian, Fedora and BLAG. solution was simple. try it if that helps you:

1.) disable dhcp. my style is to "unmerge" it too. use Static IPs

2.) restart the network.

3.) disable IPv6 (you have already done). on BLAG/Fedora i had to add these 2 lines to "/etc/modprobe.conf": 

alias net-pf-10 off

alias ipv6 off

on Debian i had to add "blacklist ipv6" in my "/etc/modprobe.d/blacklist".

3.) reboot

post back the results  :Smile: 

----------

