Managing DNS with tinydns

(An abridged guide)

Version 1.1

Sample Code

This information and these programs are distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Use at your own risk.

Makefile

# THIS REPLICATES DATA FILE FROM NS1 TO NS2 AUTOMATICALLY

remote: data.cdb
       scp data.cdb ns2.domain.com:/etc/tinydns/root/data.cdb.tmp
       ssh ns2.domain.com mv /etc/tinydns/root/data.cdb.tmp /etc/tinydns/root/data.cdb

data.cdb: data
#       cat dynip.data >> data
#       The above line is part of a dynamic dns implementation, ignore
        /usr/local/bin/tinydns-data

valtz - validator for tinydns zone files

http://x42.com/software/valtz/

update-from-zones

#!/bin/sh
cd /service/tinydns/root/
DATE=`date +%Y%m%d-%H%M%S` ## FULL DATE and TIME
cp data backup_data/data_bak_$DATE
VERIFY=`./valtz "zones/*" 2>&1`
if [ "$VERIFY" != "" ]
then
        echo ""
        echo "*************** ERRORS FOUND ******************"
        echo "$VERIFY"
        echo "*************** ERRORS FOUND ******************"
        echo ""
        exit 1
fi

echo "Passed verify"

cat << EOF > data
##
##  DO NOT EDIT THIS FILE: It is automatically generated
##
##  by the individual zone files in the 'zones' directory.
##
## Written on: $DATE
##

EOF

sort -dui zones/* >> data
# -d defines sort order, -u removes duplicate lines, -i restricts
#    the logic to only base ascii characters. Leaving out -i
#    means wildcards +*.domain.com and  +domain.com are equal
#    and sort will remove one of them. Bad.
echo "------------------------------------------------------------"
echo "data now contains up-to-date zone info in tinydns format."
echo "run 'make' to start using this data and update the secondary."
echo "------------------------------------------------------------"
echo ""

get-all-old-zones.pl

#!/usr/local/bin/perl 
undef $cmd;
@authoritative = ('ns1.secure.net');
$infile = 'domainlist';

open(IN,"$infile");
@data = ;
close (IN);

foreach $domain (@data) {
        $found = 0;
        chomp($domain);
        $domain = lc($domain);
        foreach $ns (@authoritative) {
                print "Looking for $domain at $ns... ";
                # capture STDERR into STDOUT (2>&1)
                $cmd = `tcpclient $ns 53 axfr-get $domain zones/$domain zones/$domain.tmp 2>&1`;
                if (-f "zones/$domain") {
                        print "Found! \n";
                        $found = 1;
                        push (@found, $domain);
                        last;
                }
                if (!$found) {
                        print "ERROR \n";
                        push (@errors, $domain);
                }
        }

}
open(OUT, ">axfr_log");
print OUT "-------------------- \n Summary: Found these domains:\n";
$x=0;
foreach $item (@found) {
        print OUT "$item\n"; $x++;
        }
print "Found $x domains OK\n";
print OUT "-------------------- \n Summary: ERRORS on these domains:\n";
$x=0;
foreach $item (@errors) {
        print OUT "$item\n"; $x++;
        }
print "ERRORS on $x domains\n\n";
close(OUT);

commands-list

/usr/local/bin/dnscache
/usr/local/bin/dnscache-conf
/usr/local/bin/dnsfilter
/usr/local/bin/dnsip
/usr/local/bin/dnsipq
/usr/local/bin/dnsmx
/usr/local/bin/dnsname
/usr/local/bin/dnsq
/usr/local/bin/dnsqr
/usr/local/bin/dnstrace
/usr/local/bin/dnstracesort
/usr/local/bin/dnstxt
/usr/local/bin/resolveip

how-to-transfer-in.txt

tcpclient ns1.domain.com 53 axfr-get example.com zones/example.com zones/example.com.tmp

Document History

Version 1.1 of this document was created by Darien Kruss <darien [at] teamipc.com> on June 24, 2004.

Version 1.2 of this document included the -i flag to sort on July 28, 2004.