LINUX GAZETTE

[ Prev ][ Table of Contents ][ Front Page ][ Talkback ][ FAQ ][ Next ]

"Linux Gazette...making Linux just a little more fun!"


Speeding Up Your Net Browsing with PDNSD Domain Name Caching

By


1. Where to find this document
2. About PDNSD
3. Installation
4. Sample configuration file
5. Tweaking configuration files
6. FAQs
7. Credits

1. Where to find this document


http://geocities.com/sunil_tt/pdnsd.txt

2. About PDNSD.

DNS is is the Domain Name System. DNS converts machine names to the IP addresses that all machines on the net have. Name serving on Unix is commonly done by a program called named. This is a part of the ``BIND'' package which is coordinated by Paul Vixie for The Internet Software Consortium.

PDNSD is a caching DNS proxy server. Unlike BIND, it saves the RAM cache to a file and the same is read up by PDNSD for the next Dial-Up session. BIND when acting as a cacheing nameserver on your local Dial-Up machine stores/caches the name to number translation data in your RAM. This is not written back to the hard-disk upon disconnection 'coz it is not intended for a user/site who/which is not always connected to the Net.

PDNSD can be configured to speed up Net Surfing on a Dial-Up connection. Since DNS resolution is referenced from the cached file, time is not wasted on the name to number lookup. This in turn speeds up the name to number translation, which actually accelerates your surfing.

PDNSD is distributed under the GNU/GPL and is available for download at: http://home.t-online.de/home/Moestl/

Redhat RPMS are at:

http://home.t-online.de/home/Moestl/

Debian DEBS are at:

ftp://ftp.debian.org/debian/pool/main/p/pdnsd/pdnsd_1.1.2.a-2_i386.deb

3. Installation.

Download pdnsd-<version>.tar.gz from the above source.

Decompress and untar using

tar zxvf pdnsd-<version>.tar.gz
Change directory to pdnsd-<version> and type
$ ./configure
Configure script accepts a number of parameters, see manual.txt file supplied with the PDNSD source. Command line parameters --prefix and --with-distribution are interesting.
$ ./configure --help
will list all options

I am assuming that you have not specified any command line options. Makefile generated by configure will have the following defaults: (It is worth taking a look at the generated Makefile)

Default installion directory for PDNSD is /usr/local (can be changed with --prefix option to configure). Default location of the PDNSD cache is /var/cache/pdnsd. PDNSD configuration file pdnsd.conf will be found in /etc.

Now type:

$ make
This will compile pdnsd. I did not face any problem compiling it on both Debian 2.2 and Redhat 6.1. Next su to root, as installation requires root previleges. Then type:
# make install
This step will do the following (quoted from pdnsd manual.txt):
  1. Copies pdnsd to $(prefix)/sbin/

  2. Copies pdnsd-ctl to $(prefix)/sbin/

  3. Copies docs/pdnsd.conf (a sample configuration) to /etc/ (and backs up /etc/pdnsd.conf to /etc/pdnsd.conf.old). If you have an /etc/pdnsd.conf.old you do not want to be overwritten, save it to another place/name before doing 'make install'

  4. Creates your cache directory if it is not there. After installation, you should check the file permissions and edit /etc/pdnsd.conf to fit your needs . If you use the run_as option, please make sure that your cache directory is owned by the user you specified with this option! Please note that the permission issue has been fixed as of the latest releases. Now /usr/local/sbin will contain two binaries pdnsd and pdnsd-ctl. 'pdnsd' is the proxy DNS daemon and 'pdnsd-ctl' is a program to control the cache.

The cache is located at /var/cache/pdnsd/pdnsd.cache.The cache file size will be 4 initially and will grow as and when you browse.This aspect of the /etc/pdnsd.conf viz. 'perm_cache=<value>;'. By default it is set as 512(KB).Increase it according to your judgement and a safe value would be 2048(KB) for a machine having 64MB RAM. The cache file size will be 4 bytes initially and will grow as and when you browse. Cache growth will be observed only after a reboot or after restart of the PDNSD daemon. This is due to the fact that PDNSD saves the RAM cache upon exit only.

PDNSD must be started up each time you boot the system . For this, you have to install start up scripts. rc folder of the source distribution contains startup scripts for Redhat, SuSE and Debian. I have not tested the SuSE scripts.

Do the following depending on your distribution.

3.a) Debian GNU/Linux.

Copy pdnsd-{version}/src/rc/Debian/pdnsd to /etc/init.d and type update-rc.d Stop bind if you have it installed on your system. Edit /etc/resolv.conf and add the following.
      nameserver 127.0.0.1
 

Comment out entries for all other name servers. Start pdnsd by typing /etc/init.d/pdnsd start. Test pdnsd by typing nslookup. On my system it diplays:

     Default Server: debian
     Address: 127.0.0.1
     >

Stop pdnsd by typing /etc/init.d/pdnsd stop.
Fire up your editor and add a line like this to the end of your /etc/hosts file:

     127.0.0.2    testhost

Save the file and start pdnsd once again. Type nslookup. Inside nslookup type 'testhost'.

    > testhost
      Server: debian
      Address: 127.0.0.1
      Non-authoritative answer:
      Name: testhost
      Address: 127.0.0.2
If this answer is obtained it shows that your pdnsd is working (remember to remove the last line from /etc/hosts)

3.b) Redhat Linux


Copy pdnsd-{version}/src/rc/Redhat/pdnsd to /etc/rc.d/init.d Stop bind if you have it installed on your system. Edit /etc/resolv.conf and add the following

    nameserver 127.0.0.1
 

Comment out entries for all other name servers. Start pdnsd by typing /etc/rc.d/init.d/pdnsd start. Test pdnsd by typing nslookup. On my system it diplays

    Default Server: Redhat
    Address: 127.0.0.1
    >

Stop pdnsd by typing /etc/rc.d/init.d/pdnsd stop.
Fire up your editor and add a line like this to the end of your /etc/hosts file.

 
    127.0.0.2    testhost

Save the file and again start pdnsd. Type nslookup. Inside nslookup type 'testhost'.

  > testhost
  Server: Redhat
  Address: 127.0.0.1
  Non-authoritative answer:
  Name: testhost
  Address: 127.0.0.2
 

If this answer is obtained it shows that your pdnsd is working (remember to remove the last line from /etc/hosts)

4. Sample configuration file.

My pdnsd.conf looks like this
global {
 perm_cache=2048;
 cache_dir="/var/cache/pdnsd";
 max_ttl=204800;
 run_as="nobody";
 paranoid=on;
 server_port=53;
 server_ip="127.0.0.1";
}
server {
 ip="202.54.6.5";
 timeout=260;
 interval=900;
 uptest=none;
 ping_timeout=500;
 purge_cache=off;
 caching=on;
}
server {
 ip="202.54.1.30";
 timeout=260;
 interval=900;
 uptest=none;
 ping_timeout=500;
 purge_cache=off;
 caching=on;
}
server {
 ip="202.9.128.6";
 timeout=260;
 interval=900;
 uptest=none;
 ping_timeout=500;
 purge_cache=off;
 caching=on;
}
source {
 ttl=86400;
 owner="localhost.";
 serve_aliases=on;
 file="/etc/hosts";
}
/*
rr {
 ttl=86400;
 owner="localhost.";
 name="localhost.";
 a="127.0.0.1";
 soa="localhost.","root.localhost.",42,86400,900,86400,86400;
}
rr {
 ttl=86400;
 owner="localhost.";
 name="1.0.0.127.in-addr.arpa.";
 ptr="localhost.";
 soa="localhost.","root.localhost.",42,86400,900,86400,86400;
} */

This is a sample working configuration (DNS servers are of VSNL an Indian ISP).You must edit servers section of pdnsd.conf to suit your needs.(Fill in DNS servers of your ISP aginst IP entry). Start PDNSD once more and connect to the Internet. Type nslookup and do a query for say, yahoo.com. The server will respond somthing like:

> yahoo.com
Server: debian
Address: 127.0.0.1
Non-authoritative answer:
Name: yahoo.com
Addresses: 204.71.200.245
Stop PDNSD and disconnect from the Internet. Start PDNSD again and query for yahoo.com through nslookup. If you are geting the same answer as above , fine have a coffee and relax. Else if, there is something wrong and ....??

5. Tweaking configuration files.

If you are using BIND as your primary nameserver, one can very well make PDNSD the secondary one. But here you have Catch-22 situation, on which local IP and port would you make PDNSD listen ? Look at ragOO's pdnsd.conf file and named.conf file:

[pdnsd.conf]

global {
perm_cache=2048;
cache_dir="/var/cache/pdnsd";
max_ttl=604800;
run_as="nobody";
paranoid=off;
server_port=53
server_ip="127.0.0.2";
}
[named.conf--relevant section only]
options {
directory "/var/cache/bind";
forward first;
forwarders {127.0.0.2;202.54.6.1;202.54.1.30};
};
ragOO's GNU/Linux machine has local (lo) IP addresses from 127.0.0.1 to 8.This is the same in all GNU/Linux systems and one has the option to specify 127.0.0.2 to be the alternate local server. PDNSD listens on Port 53 and note that 127.0.0.2 is the first forwarder in named.conf. This means that your machine/BIND looks up the PDNSD cached records for a number match of the address you/the client program has requested, if not there then it queries the DNS resolvers of your ISP; in order it goes.

6. FAQs.

The follwing question and answer is from the correspondence I had with Thoams Meostl author of pdnsd.

Q. I had some problem with your default installation. The cache was not growing. It was stuck at 4 bytes. I changed permissions to 'nobody' and it started growing. Probably a problem with my configuration. Will you please let me know the correct file permissions for /var/cache/pdnsd and /var/cache/pdnsd/pdnsd.cache ?

A. The best thing is to give the user who runs pdnsd write permissions to the cache directory (and of course to the cache file): chown <user> /var/cache/pdnsd chmod 0700 /var/cache/pdnsd chown <user> /var/cache/pdnsd.cache chmod 0600 /var/cache/pdnsd/pdnsd.cache

Where the permissions can of course be more liberal, if you want. The ones given are the minimum required permissions. The default permissions "make install" sets on the files are also OK. The only important thing is to chown the file. Normally, "make install" should also chown the cache file (maybe a bug? If it didn't for you, please drop me a mail).

7. Credits.

Thanks to the author of this nifty utility, Thomas Moestl for clarifying certain points and doubts. He made me a better user of PDNSD :-) !

Thanks to and (ragOO) for mentioning about 'pdnsd' during one of the ILUG-Cochin meets. ragOO edited and modified the draft heavily and encouraged me to keep on modifying the draft.

Last but not the least, to all users of this elegant program who may have found this rant useful. Enjoy....;


Copyright © 2001, Sunil Thomas Thonikuzhiyil.
Copying license http://www.linuxgazette.com/copying.html
Published in Issue 65 of Linux Gazette, April 2001

[ Prev ][ Table of Contents ][ Front Page ][ Talkback ][ FAQ ][ Next ]