User Tools

Site Tools


info:devel:dnssync

This is an old revision of the document!


DNS Synchronisation

On complex environments, it is sometimes quite a chore to keep primary and secondary DNS servers in sync. These scripts are designed to export a list of DNS zones from a Blueonyx primary server, with the intent that they will be able to be imported as secondary DNS zones on another server.

There are two settings that you should change in these scripts

  1. In the dnssecondary.sh script, you need to change the MASTERIP address to be the real ip address of your primary DNS server.
  1. This script publishes a list of all of your domain names to a URL on your primary DNS server. If you are concerned about someone accessing this data, you should take a few possible measures. Two options are:
    1. Change the filename used for DOMAINS and SUBNETS to be something unique for your server.
    2. Use other .htaccess style protections to limit the IP address to your secondary DNS server.

Once you get these scripts, put them in say an hourly cron job, and its all done.

dnsprimary.sh
#!/bin/bash
cd /etc/named/named
CCE=/usr/sausalito/bin/cceclient
 
DOMAINS=/var/www/html/dnsdomains.txt
SUBNETS=/var/www/html/dnssubnets.txt
 
ls db*.com db*.org db*.net | sed -e "s/^db.//" > $DOMAINS
if [ -e $SUBNETS ]; then 
  rm $SUBNETS
fi
 
for X in `echo find DnsSOA domainname = \"\" | $CCE| grep ^104 | cut -d " " -f 3`
do
  MASK=`echo get $X | $CCE | grep netmask | grep ^102 | cut -d "\"" -f 2`
  IP=`echo get $X | $CCE | grep ipaddr  | grep ^102 | cut -d "\"" -f 2`
  echo $IP:$MASK >> $SUBNETS
done
exit 0
dnssecondary.sh
#!/bin/bash
DOMAINS=/tmp/dnsdomains.txt
SUBNETS=/tmp/dnssubnets.txt
CCE=/usr/sausalito/bin/cceclient
MASTERIP=1.2.3.4
 
wget -q -O- http://$MASTERIP/dnsdomains.txt > $DOMAINS
wget -q -O- http://$MASTERIP/dnssubnets.txt > $SUBNETS
COUNT=`cat $DOMAINS | wc -l`
if [ $COUNT -lt 1 ];
then
  echo Did not find domain list - Bailing
fi
/root/dnsDeleteAllRecords.pl --delete-confirm
 
for X in `cat $DOMAINS`
do
  echo CREATE  DnsSlaveZone masters = \"$MASTERIP\" domain = \"$X\" | $CCE
done
 
for X in `cat $SUBNETS`
do
  IP=`echo $X | cut -d ":" -f 1`
  NETMASK=`echo $X | cut -d ":" -f 2`
  echo CREATE  DnsSlaveZone masters = \"$MASTERIP\" netmask = \"$NETMASK\" ipaddr = \"$IP\" | $CCE
done
info/devel/dnssync.1462914259.txt.gz · Last modified: 2016/05/11 07:04 by