[SIZE=2]We were always looking for a solution to have at least one secondary DNS server with all zones of all our servers. So that mail wouldn’t get lost or to prevent that domains would end up in a blacklist because they do not resolv while a server is down.[/SIZE]
[SIZE=2]Well, I found a couple of things and it’s working perfectly at the moment, so I figured, “why don’t I share this and maybe somebody can improve it”.[/SIZE]
[SIZE=2]Note that this script needs some improvement here and there, so feel free to modify it and make it better. Also be nice and share your findings with us. Thanks![/SIZE]
[SIZE=2]First (like what gethosted said in his howto):[/SIZE]
[SIZE=2]Warning: This HOWTO and related scripts are provided with absolutely positively no warranty. Any damage they do to your system we are indeed sorry for, however we cannot be held liable. Proceed at your own risk…(it really isn’t that bad).[/SIZE]
[SIZE=2]Make backups of your original zone files![/SIZE]
[SIZE=2]Note that this works and is tested with Bind on Ensim Pro servers. We use it together with a sec. DNS server that also has the zones of all our interworx servers. The steps with scripts that might need some modification are RED.[/SIZE]
[SIZE=2]Everything that has to be done on the External Secondary DNS box are marked with a green (Sec. DNS) in the step, everything else has to be done on the Bind box.[/SIZE]
[SIZE=2]You have to be root to use this howto![/SIZE]
[SIZE=3]Step #1 (Sec. DNS):[/SIZE]
[SIZE=2]First you will have to install TinyDNS on a external server (or use your InterWorx server, not covered in this howto, maybe somebody else can cover this).[/SIZE]
[SIZE=2]You can do this very easily by following this howto:[/SIZE]
[SIZE=2]http://www.djbdnsrocks.com/[/SIZE]
[SIZE=2]If you are going to use this script, you will have to make the map “/etc/tinydns/root/zones”[/SIZE]
[SIZE=3]Step #2 (Sec. DNS):[/SIZE]
[SIZE=2]You can skip this step, we won’t be using gethosted’s script since it is too time consuming to export all the zones for the domains which we have our InterWorx boxes.[/SIZE]
[SIZE=2]After that you can use gethosted’s howto to sync your TinyDNS data to the external Secondary DNS server:[/SIZE]
[SIZE=2]http://www.interworx.com/forums/showthread.php?t=319[/SIZE]
[SIZE=2]You will have to modify gethosted’s script a bit if you want to get it to work with my solution. I won’t cover that here. Maybe somebody else wants to cover that, give me a PM I will add it to this howto![/SIZE]
[SIZE=3]Step #3:[/SIZE]
[SIZE=2]Since we have a couple of InterWorx servers and are stuck with some Ensim servers (and no it’s not easier to migrate all the sites to InterWorx), I had to find a solution to convert the Bind data to TinyDNS data. You will have to download the a tar.gz file (which can be downloaded here: [/SIZE][SIZE=2]http://www.erat.org/[/SIZE][SIZE=2] you’ll need “bind-to-tinydns”).[/SIZE]
[SIZE=2]So download the script to your server using bind:[/SIZE]
[SIZE=2]wget http://www.erat.org/files/bind-to-tinydns-0.4.3.tar.gz[/SIZE]
[SIZE=2]Now untar it:[/SIZE]
[SIZE=2]tar xzvf bind-to-tinydns-0.4.3.tar.gz[/SIZE]
[SIZE=2]Go to the just created map with the bind-to-tinydns files:[/SIZE]
[SIZE=2]cd bind-to-tinydns-0.4.3[/SIZE]
[SIZE=2]Compile it:[/SIZE]
[SIZE=2]make[/SIZE]
[SIZE=2]So now we have the bind-to-tinydns binary.[/SIZE]
[SIZE=2]You can test if it works by doing this:[/SIZE]
[SIZE=2]./bind-to-tinydns example-bind-zone.db foo foo1.tmp < example-bind-zone.db[/SIZE]
[SIZE=2]This will create the tinyDNS data file “foo” out of the “example-bind-zone.db”[/SIZE]
[SIZE=2]Check the content of the foo file:[/SIZE]
[SIZE=2]cat foo[/SIZE]
[SIZE=2]And it should look like this:[/SIZE]
[SIZE=2]Zexample.com.example-bind-zone.db.:dns1.example.com.:hostmaster.example.com.:2001062501:21600:3600:604800:86400[/SIZE]
[SIZE=2]&example.com.example-bind-zone.db.::dns1.example.com.:86400[/SIZE]
[SIZE=2]&example.com.example-bind-zone.db.::dns2.example.com.:86400[/SIZE]
[SIZE=2]@example.com.example-bind-zone.db.::mail.example.com.:10:86400[/SIZE]
[SIZE=2]@example.com.example-bind-zone.db.::mail2.example.com.:20:86400[/SIZE]
[SIZE=2]+example.com.example-bind-zone.db.:10.0.1.5:86400[/SIZE]
[SIZE=2]+server1.example.com.example-bind-zone.db.:10.0.1.5:86400[/SIZE]
[SIZE=2]+server2.example.com.example-bind-zone.db.:10.0.1.7:86400[/SIZE]
[SIZE=2]+dns1.example.com.example-bind-zone.db.:10.0.1.2:86400[/SIZE]
[SIZE=2]+dns2.example.com.example-bind-zone.db.:10.0.1.3:86400[/SIZE]
[SIZE=2]Cftp.example.com.example-bind-zone.db.:server1.example.com.example-bind-zone.db.:86400[/SIZE]
[SIZE=2]Cmail.example.com.example-bind-zone.db.:server1.example.com.example-bind-zone.db.:86400[/SIZE]
[SIZE=2]Cmail2.example.com.example-bind-zone.db.:server2.example.com.example-bind-zone.db.:86400[/SIZE]
[SIZE=2]Cwww.example.com.example-bind-zone.db.:server2.example.com.example-bind-zone.db.:86400[/SIZE]
[SIZE=2]OK, now this is working, proceed to the following step![/SIZE]
[SIZE=3]Step #4:[/SIZE]
[SIZE=2]Now we are going to create some maps (you can choose to use a different location):[/SIZE]
[SIZE=2]mkdir /root/scripts[/SIZE]
[SIZE=2]mkdir /root/scripts/bind-to-tinydns[/SIZE]
[SIZE=2]mkdir /root/scripts/bind-to-tinydns/zones[/SIZE]
[SIZE=2]mkdir /root/scripts/bind-to-tinydns/tmp[/SIZE]
[SIZE=2]mkdir /root/scripts/bind-to-tinydns/zones-named[/SIZE]
[SIZE=2]Then copy the bind-to-tinydns binary:[/SIZE]
[SIZE=2]cp bind-to-tinydns /root/scripts/bind-to-tinydns/[/SIZE]
[SIZE=3]Step #5:[/SIZE]
[SIZE=2]Now we are going to create the script that we are using:[/SIZE]
[SIZE=2]nano /root/scripts/bind-to-tinydns/export-all-bind-zones.sh[/SIZE]
[SIZE=2]And then we fill it with the script ;):[/SIZE]
[SIZE=2]#!/bin/bash[/SIZE]
[SIZE=2]BINDTOTINYDNSPATH=/root/scripts/bind-to-tinydns #bind-to-tinydns path, note lack of /[/SIZE]
[SIZE=2]NAMEDPATH=/var/named #path to your bind/named db files, note lack of /[/SIZE]
[SIZE=2]EXCLUDE=".jnl|webxtra" #db files we want to exclude, for shure the .jnl files and maybe some zones, for us the “webxtra” zones, since they are simply created on these servers because we had to ;-)[/SIZE]
[SIZE=2]cd $BINDTOTINYDNSPATH #change to bind-to-tinydns path[/SIZE]
[SIZE=2]rm -f data-local #delete the tinyDNS data-local file in $BINDTOTINYDNSPATH[/SIZE]
[SIZE=2]rm -f tmp/* #delete tmp files in $BINDTOTINYDNSPATH/tmp[/SIZE]
[SIZE=2]rm -f zones-named/* #delete named/bind db files in $BINDTOTINYDNSPATH/zones-named[/SIZE]
[SIZE=2]rm -f zones/* #delete tinyDNS zone data in $BINDTOTINYDNSPATH/zones[/SIZE]
[SIZE=2]#Now we are going to create a script to copy the original bind zones-named/db files to $BINDTOTINYDNSPATH/zones-named[/SIZE]
[SIZE=2]ls -1 $NAMEDPATH/db.* | grep -Ev "$EXCLUDE" | awk '{print "cp "$1" zones-named/"}' > tmp/copy-bind-zones.sh[/SIZE]
[SIZE=2]sh tmp/copy-bind-zones.sh #copy all bind zones/db files to $BINDTOTINYDNSPATH/zones-named[/SIZE]
[SIZE=2]cd $BINDTOTINYDNSPATH/zones-named #change to $BINDTOTINYDNSPATH/zones-named[/SIZE]
[SIZE=2]#create the conver-to-tinydns.sh script. This script will convert the bind zones/db files to tinyDNS data[/SIZE]
[SIZE=2]ls -1 db.* | grep -Ev "$EXCLUDE" | sed -e 's/db.//' | awk '{print "./bind-to-tinydns "$1" zones/data-"$1" tmp/data-"$1".tmp < zones-named/db."$1}' > ../tmp/convert-to-tinydns.sh[/SIZE]
[SIZE=2]cd $BINDTOTINYDNSPATH #change to bind-to-tinydns path[/SIZE]
[SIZE=2]sh tmp/convert-to-tinydns.sh [/SIZE][SIZE=2]# convert the bind zones/db files to tinyDNS data[/SIZE]
[SIZE=2]cat zones/data* >> data-local #merge all tinyDNS zone data in one file[/SIZE]
[SIZE=2]#scp/rsync code can be below here[/SIZE]
[SIZE=2]Test your script![/SIZE]
[SIZE=2]sh export-all-bind-zones.sh[/SIZE]
[SIZE=2]The scripts will end after a few seconds, your bind zones/db files should be copied in the zones-named map and your tinyDNS zone files should be created in the zones map.[/SIZE]
[SIZE=2]Check it![/SIZE]
[SIZE=2]ls zones-named/[/SIZE]
[SIZE=2]ls zones/[/SIZE]
[SIZE=2]Now check if the bind and tinyDNS zones have the same data (not the same, but you know what I mean):[/SIZE]
[SIZE=2]cat zones-named/db.domain.tld[/SIZE]
[SIZE=2]cat zones/domain.tld[/SIZE]
EDIT: Step 3: bind2tinydns --> bind-to-tinydns