Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Synchronize slave dns zone between bind9 servers
cd /etc/bind
MASTERS=`grep "type master" -B1 named.conf.local | perl -ne '/"(.*)"/ && print "$1\n"'`
for i in $MASTERS;do perl -i -pe "if(/zone \"$i\"/){ \$_=''} " slave-zones.conf.tmp ; done
test `diff -w slave-zones.conf slave-zones.conf.tmp | wc -l` -gt 0 && cp slave-zones.conf{.tmp,} && /etc/init.d/bind9 reload
cd /etc/bind
(for i in `grep "type master" -B1 named.conf.local | perl -ne '/"(.*)"/ && print "$1\n"' `;
echo "zone \"$i\" { type slave; allow-transfer {none;}; masters {$MASTER_IP;}; file \"/var/lib/bind/slave-$\";};";
done;) | \
ssh -i /home/bind9sync/.ssh/id_rsa "(cd /etc/bind; cat - > slave-zones.conf.tmp)"
#### add in named.conf
include "/etc/bind/slave-zones.conf";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.