Skip to content

Instantly share code, notes, and snippets.

@bessangel
Created September 29, 2013 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bessangel/6752176 to your computer and use it in GitHub Desktop.
Save bessangel/6752176 to your computer and use it in GitHub Desktop.
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