Slow Ubuntu DNS (name) lookups - solution


Updated: September 22, 2012

In the more recent releases of Ubuntu and family, a strategic decision was made to replace the classic DNS (name) resolving with a lightweight implementation of DHCP and DNS called dnsmasq. Instead of relying on a static configuration, you get your local host to work on name resolution requests, which should supposedly help with VPN configurations and DNS failures.

In most cases, this works just fine, but in some, it does not. I encountered such a problem with a 32-bit edition of Xubuntu 12.04 Pangolin on my older T60 laptop, which I have not yet officially reviewed, unlike its 64-bit counterpart. Please note, I saw no such problem with approx. 10+ other installations of Ubuntu family members on a variety of other computers. End result, the name resolution is slow. Let's fix it.

dnsmasq at a glance

The big difference is in how your system behaves. The usual file /etc/resolv.conf, used to contain the name resolution entries, like nameservers, search and domain is no longer a file, but a symbolic link to /run/resolvconf/resolv.conf.

New location of resolv.conf

Now, with this configuration in place, you may discover that opening new websites takes time, pinging servers by their name takes time and the overall download and upload throughput is not quite as stellar as you expect it to be.

Solving the problem

In theory, there are many possible reasons for the problem. For example, IPv6 or the order or lookup listed in /etc/nsswitch.conf. Therefore, you should not hurry with making decisions what could be wrong. Or maybe your network card is flaky. Or a million other possible causes. Some investigation is needed. However, there's a reason why you should focus on the DNS first.

The reason is, I am telling you this. After working with Linux for a while, you get a feel for how things are working. And you really need to go after what has changed. Taking our problem into account, if the initial loading of your web pages takes a lot on first attempt, this usually means that your DNS is slow or the order of lookup is slow, going through a variety of services before hitting the right one and resolving. The default order of lookup has not changed in Ubuntu releases for several years, whereas the DNS method has. Therefore, this should be your first suspect.

There are a few ways you can fix the problem:

You could uninstall the package completely from your system.

You could edit the network manager configuration - see further below.

You could simply work around the symbolic link dependency.

We will attempt the third method, as it is the simplest one overall.

If you want your system to resort to using the standard configuration like in the past, simply remove the symbolic link and create an empty /etc/resolv.conf file. Restart your network. If you're leasing your address via DHCP, it should be populated with relevant nameserver entries. If you're using a static IP configuration, you might want to manually add the relevant lines.

sudo rm /etc/resolv.conf
sudo touch /etc/resolv.conf
sudo service networking restart

If this does not fix the problem, you can try other methods. To revert, delete the file and create a symbolic link again. And then explore a different option. But I believe that in most cases, you will not need that, as dnsmasq will be the culprit.

sudo rm /etc/resolv.conf
sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf
sudo service networking restart

Finally, when you update your system, you will see that /etc/resolv.conf will now not be overridden in the usual patching cycle.

Update

More reading

Dnsmasq on Ubuntu official documentation

How to disable dnsmasq in Ubuntu 12.04 Precise

Conclusion

Sometimes, I wonder why everything has to be a symbolic link to an autogenerated package. The same happened in GRUB, and you end up with more administrative overhead than before. What's wrong with inline editing? And why reinvent the wheel when you're running on skis?

Anyhow, in this case, I believe you will find a useful and super-quick workaround to handling slow DNS lookups due to dnsmasq. You also have two alternative methods for fixing the issue, as well as a handful of pointers in other directions. All in all, you get some command line, working with configuration files and services, a decent tutorial by all standards. Hopefully, it will also help you get your Internet speed back online just the way it used to be.

Cheers.

RSS Feed icon

del.icio.us del.icio.us stumbleupon stumble digg digg reddit reddit slashdot slashdot



Advertise!

Would you like to advertise your product/site on Dedoimedo?

Read more

Donate to Dedoimedo!

Do you want to
help me take early retirement? How about donating
some dinero to
Dedoimedo?

Read more

Donate