Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Synchronize slave dns zone between bind9 servers
## slave-dns-reload.sh
#!/bin/bash
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
###slave-dns-send.sh
#!/bin/sh
cd /etc/bind
MASTER_IP=XXX.XXX.XXX.XXX
(for i in `grep "type master" -B1 named.conf.local | perl -ne '/"(.*)"/ && print "$1\n"' `;
do
echo "zone \"$i\" { type slave; allow-transfer {none;}; masters {$MASTER_IP;}; file \"/var/lib/bind/slave-$i.host\";};";
done;) | \
ssh -i /home/bind9sync/.ssh/id_rsa bind9sync@srv2.mitalex.org "(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.