Faster internet connection with a local DNS cache
One of the things you can do to speed up browsing and general internet activity is to create a local DNS cache. A DNS is a Domain Name Server and its purpose is to convert domain names to IP addresses. Every time you type in a domain name your computer has to ask a DNS to convert it to an IP address. Occasionally a website’s IP address will change so you can’t store an IP address forever, but it is worth cacheing it locally, even just for 24 hours or so considering the number of times we hit some sites during the day.
In Ubuntu (and debian, and other flavours of linux, though this tutorial is written for ubuntu) we can install a little helper application to cache the DNS results for a time and thus speed up our internet experience in general! It is called dnsmasq and the first step is to install it:
sudo apt-get install dnsmasq
Then at the terminal we need to edit the config file:
gksudo gedit /etc/dnsmasq.conf
Then find the line that says “#listen-address” and remove the leading # (if there is one) and make it say:
listen-address=127.0.0.1
Save and exit. Now edit /etc/dhcp3/dhclient.conf:
gksudo gedit /etc/dhcp3/dhclient.conf
Edit the line that says “prepend domain-name-servers” to say:
prepend domain-name-servers 127.0.0.1;
or if you want to use OpenDNS.org’s DNS servers (which I recommend) then change that line to:
prepend domain-name-servers 127.0.0.1, 208.67.222.222, 208.67.220.220;
Now at this point if you were to get a new IP lease it would all work, but that’s a bit of hassle so lets make it work now without rebooting the hardware. Edit /etc/resolv.conf:
gksudo gedit /etc/resolv.conf
Insert the following line at the top of the nameserver list:
nameserver 127.0.0.1
Finally we need to restart our little utility to take into account the new settings:
sudo /etc/init.d/dnsmasq restart
Now it is time to test it! At the terminal type:
dig news.bbc.co.uk
…and take note of the query time. Then run the same command again and note the improvement. You should be looking at around 2ms for the 2nd time whereas the first one will be dependant upon your internet connection - for me it was about 50ms - so for me this makes the DNS query portion of browsing about 25 times quicker. Enjoy.
Related posts
Reduce the “Looking up” time to speed up your browser
Ubuntu: Ctrl-C no longer works in terminal
Using Alien to convert .rpm packages to lpia .deb
Moving your website? Check your TTL!
Linux: Bash Scripting: Search Bash History
March 26th, 2009 at 4:37 pm
Very concise, I’m gonna try this later, thanks!
On Windows I used to use ExtraDNS. In addition to caching it also fired out each query to up to 10 user defined DNS servers.
One of the interesting things I found using it was how one of Verizon’s servers (formally MCI Worldcom, formally UUNET / Pipex etc!) is overall the best performing for me, over the past decade using several different providers, none of which with on the same network either.
Can you dig it? :P (Sorry, couldn’t help myself!) :)