Monthly Archive for December, 2007

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.