theMorgue.org
Pushing the Limits of Home Electronics  

Lightweight Caching Nameserver

1. Overview

If you have a few computers at home and would like to be able to address them by name rather than IP address, you generally have two options:

  1. add the names and IP addresses of each computer into the /etc/hosts or c:\windows\hosts file on every computer in your network

  2. install a caching nameserver on one of your machines and have it resolve all of your internal addresses

I'm sure you'll agree that the second option sounds like the more maintainable option. Plus, you'll get a little performance boost by caching frequently accessed internet addresses on your local network.

The following sections will show you how to install and configure a simple caching nameserver.

2. Server Setup

Nameservers are generally some pretty heavy-weight applications, and most of them are overkill for a small home network. The one I like to use is called pdnsd.

2.1. Installation

You can download pdnsd from http://home.t-online.de/home/Moestl/index.html. Both the source and an RedHat-compatible RPM are available. To install the RPM, you would type

   rpm -Uvh pdnsd-1.1.6-1.i386.redhat.rpm

Building the source is not much harder, if you choose that route.

   ./configure
   make
   make check
   make install  # as root

If you installed from the source, you'll have to copy the src/rc/RedHat/pdnsd file to /etc/rc.d/init.d/pdnsd.

You should run control-panel as root and make sure that the pdnsd service is started and stopped in level 3 and 5. A number of 78 for both start and stop should work fine.

2.2. Configuration

If your installation succeeded, you should have a configuration file called pdnsd.conf in /etc/. If not, you can check for pdnsd.conf.sample or just copy the sample configuration below.

There are lots of options discussed on the pdnsd web site, but a bare bones setup that should work for most people is shown below.

global {
	perm_cache=512;
	cache_dir="/var/cache/pdnsd";
	max_ttl=604800;
	run_as="nobody";
	paranoid=on;
}

server {
	ip="192.168.1.1";
	timeout=30;
	interval=30;
	uptest=ping;
	ping_timeout=50;
	purge_cache=off;
}

server {
	ip="xxx.xxx.xxx.xxx";  # Your ISPs first nameserver
	timeout=30;
	interval=30;
	uptest=ping;
	ping_timeout=50;
	purge_cache=off;
}

server {
	ip="xxx.xxx.xxx.xxx";  # Your ISPs second nameserver
	timeout=30;
	interval=30;
	uptest=ping;
	ping_timeout=50;
	purge_cache=off;
}

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

You should replace 192.168.1.1 with the IP address of the machine that pdnsd is running on, and replace xxx.xxx.xxx.xxx in the second and third "server" sections with the nameservers of your ISP. These are generally found in your /etc/resolv.conf.

Now that you have a local nameserver set up, you can replace the nameserver directives in /etc/resolv.conf with the new nameserver machine. Since the nameserver is running on your local host, your /etc/resolv.conf should look something like this.

   nameserver 127.0.0.1

The last thing you need to do is put all of the IP addresses and domain names for your internal network in /etc/hosts. As seen in the "source" section of the configuration file above, this file is read by pdnsd to resolve internal network addresses.

The hosts file has the following format.

   xxx.xxx.xxx.xxx hostname.domain.com hostname

The first field is the IP address of the host. The second field is the fully qualified hostname. And, the third field is an alias or shortcut name for the host.

2.3. Fire It Up

You should be all set to start your nameserver. This can be done with the following command.

   /etc/rc.d/init.d/pdnsd start

2.4. Configuring the Rest of the Network

Now that you have an internal nameserver, you should configure all of your computers to use this machine as their nameserver. Once this is done you should be able to ping all machines in your network by name.

3. Conclusion

By setting up a caching nameserver on your home network, you can eliminate the headache of modifying the hosts file on each computer, and get a little network performance boost as well. Considering that the time and effort is quite minimal, this project gives you a lot of bang for the buck.

Copyright © 2000 theMorgue.org. All Rights Reserved.