Local DNS caching – pdnsd. Reduce name resolutions times. Run your own caching DNS server. And there’s something about OpenDNS.

Often, I find, You hit a website and you see “Looking up www.zzzzz.com” in status bar. This becomes intensified if you are running a P2P software like torrents.

Often people enable host name resolution in torrents. With hundreds of connections and name resolutions, I often feel the rates of “Looking up … ” continuously increases. These are most definitely DNS name resolution delays. Running a quick sniff for a un-responding website suggests a name resolution delay.

Ok so, I realized Airtel’s DNS servers were somehow exhausted. [May be an implication of upgraded speeds ;) ]

Local DNS serving/caching can make for a much more responsive browser and lesser timeouts.

So I searched around to find a local DNS cache implementation. Some I found were – dnsmasq, nscd, treewalk dns for windows and my favourite, pdnsd.

Now dnsmasq can do a lot more stuff, But I liked pdnsd more as it could cache the name resolutions on to disk for a more permanent effect. Provides a lot more meaningful and usable options. And above all its very easy to configure.

So here’s how to proceed.

Grab a terminal and sudo apt-get install pdnsd.

Lets edit /etc/pdnsd.conf to set up some meaning full options.

Here’s how my file looks like now:

global {
perm_cache=512;
cache_dir="/var/cache/pdnsd";
max_ttl=604800; # 1 week
run_as="pdnsd";
paranoid=on;
daemon=on;
# next setting allows ppp/ip-up update the name servers -- ABa / 20040213
status_ctl=on;
server_port=53;
server_ip="127.0.0.1";
}


server {
ip="10.1.1.1";
proxy_only=on;
timeout=10;
interval=10;
uptest=ping;
ping_timeout=20;
purge_cache=off;
}

Have a look at man pdnsd.conf to find what everything means. The important settings are:

  • max_ttl=604800; # 1 week : TTL after which the entry expires. I kept 1 week. You can keep sthing like 2h20m. Check out man for more formats.
  • run_as=”pdnsd”; : User context. If you don’t wanna mess around, you can just ensure proper read write permissions to /var/cache/pdnsd/pdnsd.cache
  • daemon=on;
  • status_ctl=on;
  • server_ip=”127.0.0.1″; : You can keep anything 127.0.0.X (X is any number < 254)
  • ip=”10.1.1.1″; This is ip of dns server you are currently using. I have given my router address which uses airtel servers to provide me resolutions.
  • proxy_only=on;
  • purge_cache=off;

Now edit /etc/resolv.conf to add local DNS server. So fireup a sudo gedit /etc/resolv.conf. Add an entry at the top as : nameserver 127.0.0.1. (This could be 127.0.0.X if you used sthing else previously). You can even get rid of other entries if you really want. The first entry becomes your primary dns.

Now lets make sure that the entry remains there in case a new DHCP lease is obtained.

Now edit /etc/dhcp3/dhclient.conf to add a line prepend domain-name-servers 127.0.0.1; such that the starting segment looks like :

#supersede domain-name "fugue.com home.vix.com";
prepend domain-name-servers 127.0.0.1;
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, host-name,
netbios-name-servers, netbios-scope;

Instead of editing above two files (resolv.conf and dhclient.conf) you can also install a tool resolvconf. In that case you might have to enable it in /etc/pdnsd.conf.

That’s it. We are done. Restart the service for new settings to take effect. sudo /etc/init.d/pdnsd restart.

Running a quick “dig ca.com” gave resolution time of 330ms. Running again gave 1ms. Oh by the way ‘dig’ is a nice small dns lookup utility.

OpenDNS

Since we have touched this topic. I would also recommend using opendns servers as name servers in pdnsd server list. The best advantage is they are better responsive dns servers. All you need is to setup some static opendns server ips as your name servers in server – ip area of pdnsd.conf file.

If your optionally register, and add your network, you can gather stats about your name resolution requests. They also support addition of dynamic ips by providing clients which can register your ip everytime. Moreover you can also integrate it with dynamic host services providers like dyndns.org

You can setup phishing filters, adult site blocking, domain blocking, typo corrections for your configured networks and keywords for domains. I truly like the concept. Its like you control which sites can get resolved for your internet connection.

Anyways for Windows folks -
TREEWALK DNS : Can be found at http://www.ntcanuck.com

4 Responses to “Local DNS caching – pdnsd. Reduce name resolutions times. Run your own caching DNS server. And there’s something about OpenDNS.”

  1. Anunay Says:

    wow good analysis and tips!
    btw, are u in line for becoming a linux sys admin? ! :O

  2. Leo Says:

    I had to manually start pdnsd after I restarted (dns weren’t being resolved).

    Is that supposed to happen? I could do a script to autostart it, but I thought pdnsd was going to start on its own.

  3. Kx Says:

    For me it autostarts. But at one point in time I noticed that it had created some 20 odd connections with my DNS server (I didnt like that…) and I am not sure whether the cache was being re-used(even for times like 6 mins.. ). May be I was speedy in judging it.

  4. Local dns cache with dnsmasq « Different.In a good way Says:

    [...] info on dnsmasq pdnsd info How to setup pdnsd Possibly related posts: (automatically generated)howto install window codecsLinux Debian [...]


Leave a Reply