Resilient DNS cache on Ubuntu

One of the most irritating things about being a geek (though far from the most irritating thing) is becoming annoyed with apparently foolish or below par performances from technical widgets. What gets you is that you know exactly what’s wrong, it all seems apparently obvious that either a) its simple and common and should have been prevented or fixed already or b) that the hazard was so clearly obvious that it should have received a higher priority. Today, I’m talking about the internet’s obvious single point of failure: DNS.

Have you ever noticed that Firefox is sitting there apparently inactive (translation: nothing is flashing) with a status bar message like “Looking up feelitlive.com…” despite the fact that you looked it up just fine a few minutes earlier? You want to find out whats on and go out, not debug your network, so you never investigate it and never call your ISP because it does work eventually and ISPs use call queuing technology rather than investing in extra human beings.

Anyway, this malady affected some of my favourite political blogs on the night of the US election and it didn’t take too much F5 bashing to work out that popular sites like sky.com worked fine and less popular sites like bbc.co.uk worked slowly and really mediocre sites like er… ubuntu.wordpress.com, for example, didn’t work at all. Since it was election night I wasn’t going anywhere so I called O2 to have them confirm the obvious - a DNS server somewhere on BTs network was broken and local caches were filled with the more frequently hit domains so that was all you got. Hmmnn… big event happening, everyone looking for news? Might it get busy on the web? Do you think?

I figured, “this is stupid, I visited the site earlier, why doesn’t my computer keep the IP address and re-use it?” I wanted a DNS cache! That way, my ISP’s DNS service only needed to work once and I would be protected from such foolishness.

Luckily, the article I wanted was in Google’s cache (accessed using an IP number not a DNS name, so working just fine…)  but its proper URL is http://ubuntu.wordpress.com/2006/08/02/local-dns-cache-for-faster-browsing/

The article is a little over complicated for a laptop user, since most laptop users know the button to reset their wireless connection and aren’t DSL users as such either. I got away with simply installing dnsmasq using Synaptic Package Manager and editing two files using “sudo vim <filename>”.

First I opened /etc/dnsmasq.conf and uncommented the line:

#listen-address=

and entered my loopback IP so it looked like:

listen-address=127.0.0.1

You can also listen on the loopback interface “lo” by editing the line above instead, if you prefer.

Then, if I recall correctly, in /etc/dhcp3/dhclient.conf I found the line:

#prepend domain-name-servers 127.0.0.1;

and removed the “#” to make it active:

prepend domain-name-servers 127.0.0.1;

I gave dnsmasq a precautionary restart with:

sudo /etc/init.d/dnsmasq restart

and after pressing the button to reset my wireless connection - which on Ubuntu is the little blue bar chart thing on the bar at the top right, followed by the little blue round widget for the network your on.

Anyway, that clearly didn’t work because the ISPs DNS server didn’t work at all for the little web sites, so reducing the minimum to having it work one time was still too high a burden on the overloaded machinery.  I didn’t find a solution until just now, after another server blip. OpenDNS allow you to use their DNS servers for free, no questions asked, but with a DNS cache installed it seems silly to use the OpenDNS server as the main server.

Luckily, there is a command to append the OpenDNS servers to the end of your nameservers list, it goes in the file /etc/dhcp3/dhclient.conf :

append domain-name-servers 208.67.222.222,208.67.220.220;

When I checked resolve.conf I saw the .222 address listed at the end, and the .220 server has gone astray, but I still have a local cache, and two independent nameservers and my blip is gone, so am quite content.

No comments yet.

Write a comment: