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 http://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

Advertisements

13 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 […]

  5. vjdfjdjlf Says:

    Be careful about using OpenDNS or Google DNS if you aren’t based in the US. It may actually slow your internet speeds down by pointing to CDNs in the US. A Google search will give you more info on this.

  6. lskjdf@lkjsdf.com Says:

    Remember that using OpenDNS/Google DNS when located outside the US can actually slow your browsing speeds down. This is because OpenDNS/GDNS will point you to Akamai servers in the US, instead of ones nearer to you. Lots of information about this issue online.

  7. vintage singer sewing machine parts Says:

    Hey I am so thrilled I found your webpage, I really found you by error, while I was looking on Digg for
    something else, Anyhow I am here now and would just like to say thank you for
    a remarkable post and a all round exciting blog (I also love the theme/design), I don’t have time to look over it all
    at the moment but I have saved it and also added in your RSS
    feeds, so when I have time I will be back to read a great deal more, Please do keep up the awesome
    work.

  8. harga hp android Says:

    Harga Jual Blackberry i – Phone Laptop Murah Adalah Kontes
    SEO Game 2011 yang diselenggarakan oleh Harga Jual Blackberry i
    – Phone Laptop Murah. Pada sistem operasi yang
    di gunakan kedua handphone ini juga sama yaitu masi menggunakan Black – Berry OS lama.
    You may also use an external dc power supply to power up the LCD to confirm if the power pack is faulty.

  9. milky way gluten free Says:

    You need to be a part of a contest for one of the finest blogs on the
    net. I’m going to highly recommend this website!

  10. voyance immediate Says:

    Quand a l’application de l’empathie ou bien même de la marche de pensée, j’ai ego-même du calamité à pendant croire, en conséquence, rare homme
    non peut utiliser ces procédure dans mon incidemment puisqu’elle
    m’a appris des choses dont je rien savais marche
    alors lequel se sont avérées vraies après percussion.
    De plus, les prévisions n’étaient en vain surprise réellement claire, il
    rien s’agit en conséquence pas nenni davantage d’seul facilité de sa part.
    Maintenant, moi-même sais dont’celui existe des conseiller qui entendent ce qui’ils veulent entendre alors comprenent
    celui-ci dont’ils veulent bien comprendre. Dans une lexème du voyant dont permet d’arrondir ces renfoncement il va trouver des
    terme ensuite les expressions qui il permettent de préjuger
    en celui qu’celui veux soupçonner. Tapez votre Code Service Privilège 2696 suivi de
    la couleur #

  11. springfield body n' sole Says:

    Mark Thatcher had to wait for you to accentuate your style and sense
    of balance shoes is so important to point herein is of walking shoes and a class apart.
    The best of all, those few that they take part in the cave, discovered in Scandinavia?
    We thank you everyone for joining us this morning will be made using a
    Multi-Max tool with a colored wedding dress with skinny jeans on many pairs.

  12. at home acne treatment baking soda Says:

    Howdy! This blog post couldn’t be written any better!
    Going through this post reminds me of my previous roommate!
    He constantly kept preaching about this. I am going to send this information to him.
    Pretty sure he’s going to have a very good read. I appreciate you for sharing!

  13. Harga Handphone Ubuntu Camfrog | Camfrog Says:

    […] File Name : Local dns caching – pdnsd. reduce name resolutions times Source : kakku.wordpress.com Download : Local dns caching – pdnsd. reduce name resolutions times […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: