Notes on seeking wisdom and crafting software

How to : Setup a Local DNS Cache

DNS(Domain Name System) is used to get the ip addresses of the domains. Basically whenever we enter an address in our browser, the browser sends a request to the “Nameserver” for the ip address of the domain. After the nameserver returns the ip address, the browser opens sockets(http, ftp etc) to the particular ip address and sends data to the server and waits for response. On response from the server, the browser shows us the content. They teach all this in a semester CS course :-)

Lets get into the “Name Resolution” part once again. So our browser would send a request to the Nameserver for the ip address of the domain we type in the address bar. A Nameserver is a box in your local network/ISP’s network which listens on a certain port for DNS requests and responds to each request with the IP address of the domain. If your browser gets stuck in the “Looking up hostname : xxx” part, then know that your ISP sucks and the nameserver box is too busy to cater to your browser’s name resolution request :P

Generally what ISPs do is : forward all their clients dns requests to nearest high level nameserver. And each of these requests by the clients are cached in the ISP’s nameserver to fasten up queries about the same domain name. So if some guy A queries up the ip address of “www.google.com”, the first time nameserver would forward this request to another high level nameserver and the return the ip address. But when another guy B asks for the ip address of “www.google.com”, our nameserver would return the ip address from its own cache.

But by whatever misses, there are times when you know that your ISP sucks. We will look into a few solutions to this :

1. Use an alternative Nameserver : This is where the OpenDNS people have done an amazing work. To use their nameservers, just put these two lines in your /etc/resolv.conf
</p>
`nameserver 208.67.222.222 `

nameserver 208.67.220.220  

nameserver your*ISP's*nameserver<em>here  

<p>
</code>

2. Use a local DNS cache : Ah, this is the topic of this post. I’ll show the procedure for Arch Linux and OpenSuSE. So lets start -

</p>
-   Install BIND : [They](http://en.wikipedia.org/wiki/BIND) call
    BIND as Berkeley Internet Name Domain. For us BIND is a simple
    daemon program which will listen for dns requests on any box and
    send the ip addresses. Our idea is to run it in "localhost",
    i.e, my own box and use my own box as my nameserver. This would
    save me the name resolution query time.  

    </p>
    For Arch : pacman -S bind  

    For OpenSuSE : search for package "bind" in Yast and install
    it.  

    <p>
-   Setup the forwarders : Now localhost must access some highlevel
    nameservers to get the ip addresses of the domains requested for
    the first time. After getting the ip address, it is stored in
    BIND's cache. To setup the highlevel nameservers (they call them
    forwarders) :  

    </p>
    \* Open /etc/named.conf as root.

    \* See the "options" block and insert/overwrite this line in
    there :

      `forwarders { 208.67.222.222; 208.67.220.220; ispnameserver; };`

    Well  

    <p>
-   Start BIND as a service everytime system starts :  

    </p>
    For Arch : Change this in /etc/rc.conf Add "capability" to the
    MODULES list and add "named" to the DAEMONS list. Here's my
    rc.conf :  

    `MODULES=(blah blah blah soundcore capability) `

    DAEMONS=(syslog-ng network named !netfs !crond alsa mpd)</code>  

    For OpenSuSE : Type in `yast2 runlevel` in terminal with root.
    Then change the runlevel settings for "named" there.  

    <p>

Blogged with Flock

Tags: opensuse, archlinux, dns, bind, named, resolv, name+resolution