D. J. Bernstein
Internet publication
djbdns
Frequently asked questions

Load-balancing DNS server


How do I configure a load-balancing DNS server? I have fifty identical web servers running on IP addresses 1.2.3.150, 1.2.3.151, and so on. I'd like to run pickdns on IP address 1.2.3.20 to spread www.heaven.af.mil requests among those servers. I'm already handling heaven.af.mil with tinydns on IP address 1.2.3.5.

Answer: Note that, in versions 1.04 and above, you do not need to use pickdns. The features of pickdns have been incorporated into tinydns.

This answer assumes that your boot scripts are already running svscan in a /service directory. pickdns relies on svscan to start it and to restart it at boot time.

You will have to make three decisions:

Create the service directory by running the pickdns-conf program, with your IP address at the end of the line:
     pickdns-conf pickdns dnslog /etc/pickdns 1.2.3.20
Tell svscan about the new service:
     ln -s /etc/pickdns /service
svscan will start the service within five seconds.

Now change directory to /service/pickdns/root, and create a new data file listing the web-server IP addresses in pickdns-data format:

     +www.heaven.af.mil:1.2.3.150
     +www.heaven.af.mil:1.2.3.151
     +www.heaven.af.mil:1.2.3.152
     +www.heaven.af.mil:1.2.3.153
     # and so on
Run
     make
to tell pickdns about the data.

On the heaven.af.mil DNS server, delegate www.heaven.af.mil to 1.2.3.20:

     cd /service/tinydns/root
     ./add-childns www.heaven.af.mil 1.2.3.20
     make

How do I send different clients to different clusters of servers? I'd like our local users in 1.2.* and 1.5.* to be directed to a separate cluster of web servers.

Answer: Change directory to /service/pickdns/root, and add location lines to data in pickdns-data format:

     %LU:1.2
     %LU:1.5
     +www.heaven.af.mil:1.2.3.220:LU
     +www.heaven.af.mil:1.2.3.221:LU
     +www.heaven.af.mil:1.2.3.222:LU
The location code LU must be 1 or 2 bytes long.

Run

     make
to tell pickdns about the data.
Is there a table mapping IP addresses to countries? We have clusters of web servers in several countries, and I'd like to send each client to a nearby cluster.

Answer: IANA has a summary of IP address locations, which I've converted into a Network Continent Guide in pickdns-data format.


How do I direct traffic away from a dead server? If one of my servers dies, I want pickdns to stop providing that server's IP address, so clients won't waste time trying that server.

Answer: pickdns is designed to work with external programs that monitor the health of your servers. An external program can remove an IP address from the list by simply changing + to - on each line with that IP address, then running make.

Note that standard client behavior is to try each of the three addresses provided by pickdns, so a server outage will merely produce delays, not failures. To minimize the delay, smart clients will try each address with a two-second timeout before retrying each address with a long timeout.