PoiNtEr->: Setting up local dns cache and public dns address

                             Difference between a dream and an aim. A dream requires soundless sleep, whereas an aim requires sleepless efforts.

Search This Blog

Wednesday, May 25, 2011

Setting up local dns cache and public dns address


When it comes to internet, reasonable speed is always an most important  thing that no one ready to compromise with. That may be a crucial reason for making you sit infront of your machines for hours and days. So the lightning speed can be achieved with your ubuntu box in two ways. They are 
  • Use faster and free domain name servers like google's pubic dns or OpenDNS (first throw the one provided by your service provider). .

  • Maintain a local dns cache in your machine itself.  So that you can do a good amount of address resolution for frequently used websites within your machine itself, and that saves a reasonable amount of time.

Here i am planning to bring both of these techniques together in a simple manner. Though there are many applications for local DNS caching in ubuntu [ such as dnsmasq, pdnsd, bind9 ] are available, bind9 seems to be a good option for me...

Starting with BIND9  DNS server in Ubuntu

Bind9 (Berkly Internet Naming Daemon)  is the most widely deployed DNS server. Bind9 is available in the ubuntu main repository itself. So you don't need to add some additional repository for installing it. Use the following command line or search for 'bind9' in Synaptic package manager to install it. 

$ sudo apt-get install bind9

Bind9 allows different type of configurations, and our point of view is on configuring it as a caching server. In this configuration BIND9 will find the answer to name queries and remember the answer for the next query. This can be useful for a slow internet connections especially based on mobile internet. By caching DNS queries, you will reduce bandwidth and (more importantly) latency. It increase network performance by caching IP addresses of commonly visited websites instead of retrieving them from the public DNS servers maintained by ISPs at each request.

Configuring the BIND server 

#  First you have to set your machine's address (127.0.0.1) itself as the primary dns address.  This can be done with the help of Network manager or by editing the /etc/resolv.conf file in your ubuntu box. Check the screenshot below..

  • using Network manager:: select the connection and click on the edit. Then choose the IPv4 settings tab and add 127.0.0.1 to the DNS servers field.

  • editing the resolv.conf file:: If you are using DHCP then you may have to edit the resolv.conf file every time you connect to the internet to make bind work properly.



Now change the bind configuration file to add some external DNS servers for resolving a new address that is not cached on your local cache at that time. If you are not adding an external dns server, then it will not be possible to resolve a new address request comes from the browser.  Here i recommend google's public dns(8.8.8.8) or OpenDNS addresses to add in the BIND configuration file. This servers may be sometimes faster and reliable than your ISP's Domain Name Servers. You can find the best DNS server applicable for you by googling. Here is how i have added it

#  First open the file 'named.conf.options

$ sudo gedit /etc/bind/named.conf.options

#  Now uncommend the section 'forwarders'. Replace the '0.0.0.0' with the dns server address applicable to you (Check the figure).

 

 

#  Restart  the BIND server:

$ sudo /etc/init.d/bind9 restart

 

Thatz it. We are almost done. Now use the dig command to see the change in speed. If you "dig" a domain name multiple times you should see a drastic decrease in query time: between the first and second query. This is due to the server caching the query. See what happened when i dig twitter from my terminal three times concecutively. See the change in the Query time.

$ dig twitter.com

 

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu May 26 01:50:14 2011
;; MSG SIZE  rcvd: 295
 

 

No comments:

Post a Comment