Setting up a local DNS Cache

Whenever you type in a website, the domain name is converted to the IP address and sends the request to the machine. You can have a DNS cache which will speed up the domain name resolving time. I get a boost up of almost 250ms.

You just have to install a package called dnsmasq.

First install it by running (you need to enable the Universe repository)

$sudo apt-get install dnsmasq

Then, open this file /etc/dnsmasq.conf and uncomment(remove the #) the line listen-address=127.0.0.1

After that edit /etc/dhcp3/dhclient.conf and search for a line prepend domain-name-servers 127.0.0.1; and uncomment it. What this does is, whenever you get a new dhcp lease, the dhcp3 client tool on your computer gets the new lease and updates the /etc/resolv.conf file with the right values for the DNS server.

Using the prepend option, we make sure that 127.0.0.1 appears before the other DNS servers. So, if the details of a domain are already in the cache, it retrieves it fast - else it looks for the other DNS servers.

Now open /etc/resolv.conf and you can see that it doesn’t have 127.0.0.1 now.

search yourisp.com
nameserver 127.0.0.1
nameserver 192.168.1.1

The last line may be different for you. I have a router which is configured to use OpenDNS, so my entry points to it.

To check whether the cache really works, execute the following command.

$dig google.com

You will get something like ;; Query time: 252 msec

Executing the command again will get you ;; Query time: 1 msec.

Congrats, you have saved about 250msec by caching the DNS.


3 Responses to “Setting up a local DNS Cache”


  1. 1 computer software

    This here is a collection that any tech-freak would die for(in which case we’d be happy to welcome you over here). Anyways, we’ve got softwares that have been voted the darkest and best amongst all dark-apps that are available, individually tested by each of our testing team(even the Ghost Rider came in to do the Flametest, since he’s got a steady sourse of them). Let the downloads begin! Muahahahaha!!

    http://dilin-anand.blogspot.com/2008/03/darkest-freeware-within-netherworld.html

  2. 2 owen

    Caching DNS is a great thing to do. Setting up a Squid caching server is also good if you want to get even faster.

  3. 3 baby

    Nice website!!

Leave a Reply