FreeBSD DJBDNS: Create Secondary TinyDNS Server

by on July 8, 2007 · 0 comments· LAST UPDATED July 8, 2009

in , ,

How do I create a secondary djbdns dns name server to resolve names if primary went down?

You can easily create secondary dns server using djbdns. Type the following commands to install secondary DNS server on FreeBSD server itself (type all the following commands on ns2.nixcraft.in):

ns2.nixcraft.in Secondary NameServer Installation and Configuration

Install djbdns:
# portsnap fetch update
# cd /usr/ports/dns/djbdns
# make install clean && rehash

Create users and required directories:
# pw groupadd dnsusers
# pw useradd tinydns -s /bin/nologin -G dnsusers
# pw useradd dnslog -s /bin/nologin -G dnsusers
# pw useradd axfrdns -s /bin/nologin -G dnsusers
# mkdir /var/service/
# echo 'svscan_enable="YES"' >> /etc/rc.conf
# /usr/local/etc/rc.d/svscan.sh start

Create Directory For Your Zone File

You need to create /var/ns2.nixcraft.in/ as follows:
# mkdir /var/ns2.nixcraft.in
# tinydns-conf tinydns dnslog /var/ns2.nixcraft.in 203.51.2.1
# ln -s /var/ns2.nixcraft.in /var/service/
# sockstat -4 -p 53

Now, your secondary tinydns server is running.

How Do I Replicate My DNS Data From ns1.nixcraft.in (first tinydns server)?

You have two options here as follows:

Replicating Your DNS Data Using axfrDNS Program

axfrdns bind to TCP port # 53. It reads a zone-transfer request in DNS-over-TCP format from its standard input, and responds with locally configured information. This program is useful to talk with external dns servers such as BIND. Using tcp client one can request a zone-transfer request for secondary tinydns. It is also useful to answer queries on TCP port # 53. Usually most client will use UDP port. See how to setup axfrdns on primary name server to accept a zone-transfer requests.

Replicating Your DNS Data (ns1.nixcraft.in) Using rsync or scp

You can just copy the generated data.cdb to the second tinydns name server using rsync or scp. This is preferred method when you just want to talk between your own two tindydns servers. Simply use scp command as follows to copy data.cdb from primary name server ns1.nixcraft.in:
# scp user@ns1.nixcraft.in:/var/ns1.nixcraft.in/root/data.cdb /var/ns2.nixcraft.in/root/
You can automate this procedure from ns1.nixcraft.in itself. Login to your primary name server and cd to /var/ns1.nixcraft.in/root
# cd /var/ns1.nixcraft.in/root
Open Makefile file, enter:
# vi Makefile
Update file as follows (to avoid password prompt setup ssh-key based login between ns1.nixcraft.in and ns2.nixcraft.in):

remote: data.cdb
	/usr/local/bin/rsync -az -e ssh data.cdb user@ns2.nixcraft.in:/var/ns1.nixcraft.in/root/data.cdb
data.cdb: data
	/usr/local/bin/tinydns-data

Save and close the file. Finally, update Makefile on ns2.nixcraft.in as follows:
# cd /var/ns2.nixcraft.in/root
# vi Makefile

Append the following line protects data.cdb by stopping make:
# echo "foo" > Makefile

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 0 comments… add one now }

Leave a Comment

Tagged as:

Previous Faq:

Next Faq: