Installing and Configuring TinyDNS

TinyDNS is the name server from djbDNS, a DNS toolset created by Daniel J. Bernstein. By default, the server only responds to queries for previously declared zones — it does not handle reverse lookups or zone transfers. Those are handled by other tools in the suite. This modularity makes it powerful, versatile, and fast.

By the end of this guide you will have an authoritative DNS server responding on port 53.

djbDNS is composed of 6 tools:

djbDNS has 2 dependencies, daemontools 0.70+ and ucspi-tcp, which must be installed first.

Setup

Create a directory to store the downloads.

mkdir /package
chmod 755 /package
cd /package

Compiling Daemontools

Daemontools is a collection of tools for managing UNIX services.

Download daemontools 0.76 and extract.

wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
tar xvfz daemontools-0.76.tar.gz

Compile

If working on Linux (not BSD or Solaris), you may receive the following error when compiling:

/usr/bin/ld: errno: TLS definition in /lib64/libc.so.6 section .tbss mismatches non-TLS reference in envdir.o.

Edit /package/admin/daemontools-0.76/src/conf--cc and append -include /usr/include/errno.h to the end of the first line.

It should look like this:

gcc -O2 -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized -Wshadow -Wcast-qual -Wcast-align -Wwrite-strings -include /usr/include/errno.h

cd admin/daemontools-0.76/
package/install

By default the installation adds svscan to the boot routine and appends SV:12345:respawn:/command/svscanboot to /etc/inittab. Start svscan:

svscan /service &

Installing ucspi-tcp

ucspi-tcp (UNIX Client-Server Program Interface for TCP) is a command-line tool for building TCP client-server applications.

Download ucspi-tcp 0.88 and extract.

cd /package
wget http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
tar xvzf ucspi-tcp-0.88.tar.gz

Compile

As with daemontools, you may get a libc.so error when compiling. Edit /package/ucspi-tcp-0.88/conf-cc and append -include /usr/include/errno.h to the end of the first line.

It should look like this:

gcc -O2 -include /usr/include/errno.h

cd ucspi-tcp-0.88/
make
make setup check

Installing djbDNS and TinyDNS

Download and extract djbDNS.

cd /package
wget http://cr.yp.to/djbdns/djbdns-1.05.tar.gz
tar xvzf djbdns-1.05.tar.gz
cd djbdns-1.05/

Compile

echo gcc -O2 -include /usr/include/errno.h > conf-cc
make
make setup check

With djbDNS and its dependencies installed, create two users: Gtinydns and Gdnslog.

useradd Gtinydns
useradd Gdnslog

Run tinydns-conf to create the service directory at /etc/tinydns.

Remember to run the command with your server’s public IP.

tinydns-conf Gtinydns Gdnslog /etc/tinydns <public-ip>

The IP must be configured on the server and must not be used by DNScache or any other service on port 53. If you want to use DNSCache on the same server, use a different interface.

Notify svscan of the new service and use svstat to verify it is running.

ln -s /etc/tinydns /service/tinydns
svstat /service/tinydns

If you get a supervise error, check that the process is running.

ps aux | grep sv

If it is not running, start it manually with svscan /service &

Running svstat /service/tinydns again should return the pid.

/service/tinydns: up (pid ####) ## seconds

Delegation and zones

First, configure your domain registrar (GoDaddy, Namecheap, etc.) to register a nameserver with your IP. Once done, configure your server to respond for your domain.

Use the add-host and add-alias commands located in /etc/tinydns/root. These commands edit the /etc/tinydns/root/data file. After editing, compile it with make.

You can also edit the data file manually.

Add the NS record to the data file and compile.

cd /etc/tinydns/root
./add-ns example.com 1.2.3.4
make

To add a new domain, use add-host.

./add-host new-domain.com 1.2.3.4

Alternatively, edit the data file manually using the following format:

=tiger.heaven.af.mil:1.8.7.5   # equivalent to add-host
+www.heaven.af.mil:1.8.7.4     # equivalent to add-alias

Remember to compile the data file after editing.