Get a faster browsing experience using a local caching DNS

Written by
Date: 2007-10-25 10:36:30 00:00


Some days ago while I was on a business trip, and trying to work in the Hotel, the second day the Internet connection was really slow, (maybe some other guest was downloading a lot of information), while trying to look for some information on the web, it took lots of seconds to even get the IP of the pages I was trying to visit.

I decided that I needed a local DNS on my PC to improve at least a little my speed experience.

Installing Bind

apt-get install bind9

As soon as it is installed it is ready to answer your queries, but here is a example of my configuration.

directory "/var/cache/bind";

auth-nxdomain no;    # conform to RFC1035

zone "." {
        type hint;
        file "/etc/bind/db.root";
};
zone "localhost" {
        type master;
        file "/etc/bind/db.local";
};

zone "127.in-addr.arpa" {
        type master;
        file "/etc/bind/db.127";
};

zone "0.in-addr.arpa" {
        type master;
        file "/etc/bind/db.0";
};

zone "255.in-addr.arpa" {
        type master;
        file "/etc/bind/db.255";
};

With these configuration files Bind is configured to answer queries and cache them for the time the computer is on, or until the TTL parameter instruct it to flush the data,and get a new copy of the DNS record.

Well this is with Bind, but Bind will store its cache on the PC RAM which is good if you do not turn your PC off, but if you usually turn it of, or if this configuration is intended for a Laptop, so it is maybe better to use pdnsd

PDNSD will save its cache from RAM to a file and it will be read next time Linux is booted, so this is a great utility for Laptops or dial-up users, it is also great for ADSL or Cable users, it will boost your browsing speed.

Installation

apt-get install pdnsd

Configuration

Once pdnsd is installed on your system, it needs to be configured, here is my configuration file, which is located at /etc/pdnsd.conf

global {
        perm_cache=2048;
        cache_dir="/var/cache/pdnsd";
        max_ttl=604800;
        run_as="pdnsd";
        paranoid=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="200.87.61.83";
        timeout=60;
        interval=900;
        uptest=ping;
        ping_timeout=500;
        purge_cache=off;
        caching=on;
}
server {
        ip="4.2.2.2";
        timeout=60;
        interval=900;
        uptest=none;
        ping_timeout=500;
        purge_cache=off;
        caching=on;
}

server {
    label="resolvconf";
}

source {
        ttl=86400;
        owner="localhost.";
        serve_aliases=on;
        file="/etc/hosts";
}

Once any of these servers is installed, Bind or Pdnsd there is only one step left.

If your PC gets its nameserver from a DHCP server, you will need to reconfigure dhclient.conf to make 127.0.0.1 your primary domain server.

Here is the file you need to edit /etc/dhcp3/dhclient.conf

be sure that this line is uncommented.

prepend domain-name-servers 127.0.0.1;

This line will tell to dhclient to put 127.0.0.1 as your first name server and the ones passed by the DHCP server will follow it, as the second, third and so on options.

Update

Check the part II of this article

as a suggestion of a reader of this site.