Page 1 of 5 123 ... LastLast
Results 1 to 10 of 44

Thread: HOWTO: Persistant DNS Caching with pdnsd.

  1. #1
    Join Date
    Aug 2006
    Location
    SW France
    Beans
    90
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    HOWTO: Persistent DNS Caching with pdnsd.

    A common complaint on the Ubuntu forums (and many other Linux sites, it seems) is the slow DNS look-up performance, especially compared with the same hardware running Windows.

    One way of improving performance is to provide DNS caching on the local machine, so that repeated look-ups are quicker -- a local request rather than a trip out to the Internet and back. Although some client programs do this for themselves (notably web browsers), many don't (notably mail clients, it seems to me).

    This being Linux, there are many ways to achieve local DNS caching, of course, ranging from the simple to the complicated. I have looked at several methods and this is the one that suits my needs. I'm running a desktop installation on a small home network and the machine is rebooted daily. This means that I need a solution that remembers its cache after a reboot -- I don't want to have to cache everything every morning. This requirement for persistence let me to pdnsd (p for persistent ), but it suffers from a remarkable lack of documentation for the novice. Eventually, I found this article on the Debian Administration site, which got me going in the right direction, but there are a couple of things to be clarified.

    This is the procedure as I did it.

    Note that these details are for Dapper with Gnome and without resolvconf installed. I don't think anything will break if these changes are made to a different setup, but it may not work. I haven't tried it.

    Install pdnsd -- either by Synaptic or apt:

    Code:
    sudo apt-get install pdnsd
    Now some editing of the pdnsd.conf file. Start gedit as root user in a terminal (or Alt-F2):

    Code:
    gksudo gedit /etc/pdnsd.conf
    Substitute your preferred editor, as required.

    Save a back-up of the original -- e.g., Save As -> pdnsd.conf.orig

    Now, find the part of pdnsd.conf that contains the DNS server to be used:

    Original:
    Code:
    /*
    server {
    	ip="192.168.0.1";
    	timeout=30;
    	interval=30;
    	uptest=ping;
    	ping_timeout=50;
    	purge_cache=off;
    }
    */
    and change it to read:

    Modified:
    Code:
    server {
    	label=OpenDNS;
    	ip=208.67.222.222;
    	ip=208.67.220.220;
    	timeout=30;
    	interval=30;
    	uptest=ping;
    	ping_timeout=50;
    	purge_cache=off;
    }
    Notes:
    1. It is vital to remove the '/*' and '*/'. These are comment markers and nothing will work if they are left in! Not obvious if you're not familiar with coding conventions (that's me!).
    2. It is vital to include the semi-colon at the end of each line.
    3. The 'label=' entry is optional, but may be useful for future diagnostics.
    4. I have used the OpenDNS IP addresses. These will work, but you may prefer to use your ISP's or other DNS servers.

    Summary: I removed the comment signs and added a label and the two IP addresses. Other entries are unchanged.

    Next, comment out the part referring to resolvconf by adding /* and */ so that it looks like this:

    Modified:
    Code:
    /*
    # if you installed resolvconf, and status_ctl=on
    server {
        label="resolvconf";
    }
    */
    Save the file as /etc/pdnsd.conf but don't close the editor window yet.

    Most of us, I expect, use DHCP to set IP addresses on boot, so we need to make sure that our settings survive a reboot. Amongst other things, DHCP tells the system where to find DNS servers, so open /etc/dhcp3/dhclient.conf in the editor.

    Remove the comment mark (#) from the beginning of this line:

    Code:
    #prepend domain-name-servers 127.0.0.1;
    and save the file.

    In order to avoid having to reboot immediately, edit /etc/resolv.conf and add this line at the top of the file:

    Code:
    nameserver 127.0.0.1
    (This is what the changes to dhclient.conf will do automatically at boot.)

    The system will now look to the local cached DNS information rather than going directly to the Internet.

    Restart pdnsd to make our changes active:

    Code:
    sudo /etc/init.d/pdnsd restart
    If you want to test this arrangement and compare results, that is explained in the reference article, but I found that it was pretty obvious just by browsing to websites.

    The first time a site is visited, there will be a delay while pdnsd finds the IP address from the external DNS servers, but subsequently it will just pull it from its cache -- like lightning!

    References:
    Steve Kemp's article on Debian Administration -- thank you very much.
    man pdnsd
    man pdnsd.conf
    pdnsd homepage: Comprehensive documentation is here, but it may not be very accessible to us novices.
    Also mentioned in this thread in connection with Internet Connection Sharing.

    Uninstallation:
    Remove the pdnsd package with Synaptic or apt:
    Code:
    sudo apt-get remove pdnsd
    Restore original backup file for /etc/dhcp3/dhclient.conf (or add the # to the beginning of the 'prepend' line).
    Restore original backup file for /etc/resolv.conf (or remove the 'nameserver 127.0.0.1' line).

    Support:
    I am not an expert. I'll answer questions if I can, but mostly I'd have to research the answers first. Or you could do the research and tell the rest of us.

    Applicable to:
    Ubuntu 6.06 Desktop i386, up to date today, Friday, 5 January 2007.

    Please form an orderly queue with corrections.
    Last edited by bmt; October 26th, 2007 at 12:32 PM. Reason: Minor typo corrections; added pdnsd homepage reference.

  2. #2
    Join Date
    Nov 2006
    Location
    Istanbul,Turkey
    Beans
    6
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: HOWTO: Persistant DNS Caching with pdnsd.

    won't work man

  3. #3
    Join Date
    Mar 2006
    Location
    NoVA
    Beans
    73
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: HOWTO: Persistant DNS Caching with pdnsd.

    Quote Originally Posted by madrano View Post
    won't work man
    Works fine for me, with both 6.10 and 7.04 with the settings mentioned in this guide.
    Laptops: Dell Latitude D620, Ubuntu 11.04 | MacBook Pro Santa Rosa, OS X 10.6 | HP Mini 10, Ubuntu 11.04

  4. #4
    Join Date
    May 2007
    Beans
    373
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: HOWTO: Persistant DNS Caching with pdnsd.

    using the dig feature to test this, and the cache doesn't appear to work

  5. #5
    Join Date
    Mar 2007
    Beans
    6
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: HOWTO: Persistant DNS Caching with pdnsd.

    I use my laptop on more than one network. If I append the ip="192.168.1.1";
    after the ip="..." that are for the network I use most frequently will it work?

  6. #6
    Join Date
    Feb 2006
    Location
    Aksaray, Turkey
    Beans
    4
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: HOWTO: Persistant DNS Caching with pdnsd.

    thaks for howto, dns caching is working and feisty is faster than before.
    Code:
    xxx@ubuntu:~$ dig  @localhost youtube.com mx
    
    ; <<>> DiG 9.3.4 <<>> @localhost youtube.com mx
    ; (1 server found)
    ;; global options:  printcmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50474
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2
    
    ;; QUESTION SECTION:
    ;youtube.com.                   IN      MX
    
    ;; ANSWER SECTION:
    youtube.com.            191     IN      MX      10 sjl-mbox1.sjl.youtube.com.
    
    ;; AUTHORITY SECTION:
    youtube.com.            720     IN      NS      dns1.sjl.youtube.com.
    youtube.com.            720     IN      NS      dns2.sjl.youtube.com.
    
    ;; ADDITIONAL SECTION:
    sjl-mbox1.sjl.youtube.com. 191  IN      A       208.65.153.154
    dns2.sjl.youtube.com.   705     IN      A       208.65.152.137
    
    ;; Query time: 34 msec
    ;; SERVER: 127.0.0.1#53(127.0.0.1)
    ;; WHEN: Sat Sep 22 23:16:46 2007
    ;; MSG SIZE  rcvd: 129
    Code:
    xxx@ubuntu:~$ dig  @localhost youtube.com mx | grep time
    ;; Query time: 0 msec
    Last edited by eXSiR; September 22nd, 2007 at 09:21 PM. Reason: Added dig test

  7. #7
    Join Date
    Apr 2007
    Beans
    337

    Re: HOWTO: Persistant DNS Caching with pdnsd.

    It works for me. Much faster internet now.

    I don't know enough about OpenDNS to use their servers though. I'll stick to my isp's dns servers.

  8. #8
    Join Date
    Aug 2005
    Beans
    994

    Re: HOWTO: Persistant DNS Caching with pdnsd.

    do you recommend this for users with routers? I already have opendns set on my router.

  9. #9
    Join Date
    Apr 2007
    Beans
    337

    Re: HOWTO: Persistant DNS Caching with pdnsd.

    Yes, it will make dns searches faster even if your router is providing the dns resolution. With pdnsd your local machine keeps a small cache of the dns data and thus avoids repeated resolution out on the 'net (via the router). For a big network with a lot of computers it would not be feasible to put pdnsd on all computers. In that case you'd want a local dns cache for your lan. But for one or a few computers it isn't much of a problem to set up.
    Last edited by trak87; September 26th, 2007 at 05:02 PM.

  10. #10
    Join Date
    Apr 2007
    Location
    Tasmania, Australia
    Beans
    52

    Re: HOWTO: Persistant DNS Caching with pdnsd.

    Thanks for the great instructions. Just a couple of questions please:

    On the Open DNS page:

    https://www.opendns.com/start/ubuntu.php

    It has the following instructions to make Open DNS work in Ubuntu:

    Code:
    $ sudo cp /etc/resolv.conf /etc/resolv.conf.auto
    $ sudo gedit /etc/dhcp3/dhclient.conf
    # append the following line to the document
    prepend domain-name-servers 208.67.222.222,208.67.220.220;
    # save and exit
    $ sudo ifdown eth0 && sudo ifup eth0
    I followed these instruction before yours as I am trying to make the Adult Content Filter work as well as improve my Internet speed.

    My first question is should I have the line;

    prepend domain-name-servers 208.67.222.222,208.67.220.220;

    present in /etc/dhcp3/dhclient.conf after following your instructions or is it not required as it was inserted by following the Open DNS guide.

    Second question please, when I use the code:

    Code:
    sudo ifdown eth0 && sudo ifup eth0
    Should the correct response be:

    ifdown: interface eth0 not configured
    Ignoring unknown interface eth0=eth0.

    I am using 7.10 32 bit

    Thanks again for sharing the knowledge.

    Cheers
    Lonoy
    Last edited by lonoy; October 26th, 2007 at 07:56 AM. Reason: Added Ubuntu Version

Page 1 of 5 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •