I'll say that again just incase you missed it
DO NOT ATTEMPT THIS IF YOU USE A CONTROL PANEL LIKE CPANEL, PLESK OR ENSIM
What is DJBDNS?
DJBDNS is a dns server package writen by Dr D.J Bernstein, also the author of qmail, its writen in C and like all DJB programs is seperated into "small" chunks.
These are
dnscache - a DNS resolver (like what you set your clients dns settings to be)
tinydns - the DNS server itself
axfrdns - an implementation of a zone transfer server
A few "special" servers (loadbalancer, rbl server, "wall"dns etc)
DnsClients that will not be covered here
Why DJBDNS ?
Its secure. DJB has $500 of his own money riding on the securty guarantee. Which, at the time of writing this, has not been claimed.
Its Light weight (11000 lines of code if i remeber right) and VERY light on resources.
Its "zones" file makes sense (after you get used to it)
Requirements
a Unix OS (Linux, *BSD, Solaris etc). No windows here, sorry. (it *might* in a month of sundays work under that terible hack that is cygwin, but i'm not even going to suggest looking at that)
Preferably at least 2 IP's.
PreInstall
CODE
mkdir /downloads/
cd /downloads/
wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
wget http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
wget http://cr.yp.to/djbdns/djbdns-1.05.tar.gz
cd /downloads/
wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
wget http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
wget http://cr.yp.to/djbdns/djbdns-1.05.tar.gz
This is just creating a working folder (/downloads) and downloading the source for us to compile
Installing
First off, daemontools. Daemontools is a program that makes sure services are running, and if not, are restarted. Its also wrien by DJB.
CODE
mkdir -p /package
chmod 1755 /package
cd /package
tar zxvf /downloads/daemontools-0.76.tar.gz
chmod 1755 /package
cd /package
tar zxvf /downloads/daemontools-0.76.tar.gz
Now if your a redhat / Fedora user, you will need to do the following to fix an issue with the glibc thats used in RH/Fedora
CODE
cd /package/admin/daemontools/src
wget http://www.wheely-bin.co.uk/sm/patch/daemontools_errnopatch
patch < daemontools_errnopatch
wget http://www.wheely-bin.co.uk/sm/patch/daemontools_errnopatch
patch < daemontools_errnopatch
Ok back to the install now
CODE
cd /package/admin/daemontools-0.76
./package/install
./package/install
tada! daemon tools is installed!
Now for UCSPI-TCP, it contains tcpserver, whihc is much like inetd, except not.
CODE
cd /downloads/
tar zxvf ucspi-tcp-0.88.tar.gz
cd ucspi-tcp-0.88
tar zxvf ucspi-tcp-0.88.tar.gz
cd ucspi-tcp-0.88
Now if your a redhat / Fedora user, you will need to do the following to fix an issue with the glibc thats used in RH/Fedora
CODE
wget http://www.wheely-bin.co.uk/sm/patch/ucspi-tcp_errnopatch
patch < ucspi-tcp_errnopatch
patch < ucspi-tcp_errnopatch
back to the install
CODE
make && make setup check
tada! done. See its not that painful is it!
Djbdns its self needs to be installed now
CODE
cd /downloads/
tar zxvf djbdns-1.05.tar.gz
cd djbdns-1.05
tar zxvf djbdns-1.05.tar.gz
cd djbdns-1.05
Guess what! Yup thats right RH/Fedora users, heres an extra step for you
CODE
wget http://www.wheely-bin.co.uk/sm/patch/djbdns_errnopatch
patch < djbdns_errnopatch
patch < djbdns_errnopatch
and back to sanity again
CODE
make && make setup check
Thats now djbdns installed. Walk in the park really isnt it!
Adding Users
Lets Add the users the daemons will run as
Linux
CODE
/usr/sbin/useradd -s /sbin/nologin -d /dev/null tinydns
/usr/sbin/useradd -s /sbin/nologin -d /dev/null dnslog
/usr/sbin/useradd -s /sbin/nologin -d /dev/null dnscache
/usr/sbin/useradd -s /sbin/nologin -d /dev/null dnslog
/usr/sbin/useradd -s /sbin/nologin -d /dev/null dnscache
(Free)BSD
CODE
pw useradd tinydns -s /sbin/nologin -d /dev/null
pw useradd dnslog -s /sbin/nologin -d /dev/null
pw useradd dnscache -s /sbin/nologin -d /dev/null
pw useradd dnslog -s /sbin/nologin -d /dev/null
pw useradd dnscache -s /sbin/nologin -d /dev/null
Other OS'es.... work it out your self :P
Setting Up DNSCache
This step is completley optional, however i do recommend this, especially if your running qmail. This is the DNS Resolver.
We are going to set it up so that it only listens on 127.0.0.1, this can be any ip address*, however we don't want others wasting our bandwidth now do we!
* It can't share ip addreses with TinyDNS
CODE
dnscache-conf dnscache dnslog /etc/dnscache 127.0.0.1
ln -s /etc/dnscache /service
cp /etc/resolv.conf /etc/resolv.conf.pre-dnscache
echo "nameserver 127.0.0.1" > /etc/resolv.conf
ln -s /etc/dnscache /service
cp /etc/resolv.conf /etc/resolv.conf.pre-dnscache
echo "nameserver 127.0.0.1" > /etc/resolv.conf
Tada! A dnscache instance is setup and listening on 127.0.0.1, your system should now also be using it to resolve names.
Setting Up TinyDNS
Supprisingly, this step is also optional, if your not wanting to run a dns server, you don't have to do this step.
However, i'm sure that you do :P
In this example we'll set up TWO TinyDNS instances, both sharing the same data files
The IP's we're using here are 9.8.7.6 and 9.8.7.5
CODE
/usr/local/bin/tinydns-conf tinydns dnslog /etc/tinydns 9.8.7.6
/usr/local/bin/tinydns-conf tinydns dnslog /etc/tinydns2 9.8.7.5
cd /etc/tinydns2
rm -rf root
ln -s /etc/tinydns/root
ln -s /etc/tinydns /service
ln -s /etc/tinydns2 /service
/usr/local/bin/tinydns-conf tinydns dnslog /etc/tinydns2 9.8.7.5
cd /etc/tinydns2
rm -rf root
ln -s /etc/tinydns/root
ln -s /etc/tinydns /service
ln -s /etc/tinydns2 /service
And there we go, TinyDNS should be setup on both ip's sharing /etc/tinydns's data file.
Lets check that they really are running
CODE
root@morningside# ps aux |grep tinydns
root 96785 0.0 0.1 1476 828 p3 S+ 9:58PM 0:00.00 grep tinydns
root 397 0.0 0.0 1188 92 d0- I 31May05 0:00.05 supervise tinydns
root 399 0.0 0.0 1188 92 d0- I 31May05 0:00.05 supervise tinydns2
tinydns 412 0.0 0.0 1328 136 d0- S 31May05 0:12.16 /usr/local/bin/tinydns
tinydns 415 0.0 0.0 1328 136 d0- I 31May05 0:11.77 /usr/local/bin/tinydns
root 96785 0.0 0.1 1476 828 p3 S+ 9:58PM 0:00.00 grep tinydns
root 397 0.0 0.0 1188 92 d0- I 31May05 0:00.05 supervise tinydns
root 399 0.0 0.0 1188 92 d0- I 31May05 0:00.05 supervise tinydns2
tinydns 412 0.0 0.0 1328 136 d0- S 31May05 0:12.16 /usr/local/bin/tinydns
tinydns 415 0.0 0.0 1328 136 d0- I 31May05 0:11.77 /usr/local/bin/tinydns
If thats similar to what you see, all is fine
Editing your data file
I know what your saying, "great i've got a dns server, how do i change my zones". This is only a small subset of the record types covered here. If your wanting more, go to http://cr.yp.to/djbdns/tinydns-data.html
Lets say we have the domain wheely-bin.co.uk.
CODE
##########
# wheely-bin.co.uk
##########
#SOA
.wheely-bin.co.uk:70.84.53.139:ns1.wheely-bin.co.uk
.wheely-bin.co.uk:70.84.53.138:ns0.wheely-bin.co.uk
#MX
@wheely-bin.co.uk::wheely-bin.co.uk:10:86400
#A
+wheely-bin.co.uk:70.84.53.138:86400
+*.wheely-bin.co.uk:70.84.53.138:86400
# wheely-bin.co.uk
##########
#SOA
.wheely-bin.co.uk:70.84.53.139:ns1.wheely-bin.co.uk
.wheely-bin.co.uk:70.84.53.138:ns0.wheely-bin.co.uk
#MX
@wheely-bin.co.uk::wheely-bin.co.uk:10:86400
#A
+wheely-bin.co.uk:70.84.53.138:86400
+*.wheely-bin.co.uk:70.84.53.138:86400
"what the heck are these symbols"... calm down dear, its a comerci^Wdata file.
CODE
# Comment
.domain:ip:x This Creates a NS record (x.ns.domain, or just x if its a fqdn its self), an A record (for x.ns.fqdn) or none if X is a fqdn, and a SOA record for domain
@domain:ip:x:priority:ttl This Creates a MX record showing x.mx.domain (or just x if its a full name, as in this case) with the priority of pri, an A record of x as x.mx.domain (or not as in this case)
+domain:ip:ttl creates a A record for domain pointing to IP
.domain:ip:x This Creates a NS record (x.ns.domain, or just x if its a fqdn its self), an A record (for x.ns.fqdn) or none if X is a fqdn, and a SOA record for domain
@domain:ip:x:priority:ttl This Creates a MX record showing x.mx.domain (or just x if its a full name, as in this case) with the priority of pri, an A record of x as x.mx.domain (or not as in this case)
+domain:ip:ttl creates a A record for domain pointing to IP
So in the case of wheely-bin.co.uk the following records are created
CODE
A Records for ns1.wheely-bin.co.uk & ns0.wheely-bin.co.uk pointing to 70.84.53.139 and .138 respectivly. a MX record for wheely-bin.co.uk, priority 10, pointing to wheely-bin.co.uk. An A record for wheely-bin.co.uk pointing to 70.84.53.138. and a Wildcard *.wheely-bin.co.uk pointing to 70.84.53.138
So, edit your /etc/tinydns/root/data file adding your domains as needed, then when done
CODE
cd /etc/tinydns/root
make
make
Thats your TinyDNS now running with the latest data file
UhOh Burnt milk
Ok this sections only really for when something/someone fscks up :P
For now, i'll tell you how to restart services running under daemontools. And add more as needed
CODE
svc -t /service/tinydns - This Restarts tinydns
svc -d /service/tinydns - This Stops tinydns
svc -u /service/tinydns - This starts tinydns
svc -d /service/tinydns - This Stops tinydns
svc -u /service/tinydns - This starts tinydns
[size=7]all typos, spelling mistakes etc etc are completley intentional
