Categories

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

Automatically clone zone from a bind master

My situation, ns1 and ns2, master and slave. On ns1 I’ve installed smbind to simply manage my zones.

Now I want that ns2 will be automatically updated with the new zones from ns1 but, unfortunately, I wasn’t able to find anything ready on internet.

At the end I wrote a simple script that simply connect to the first machine via ssh, take the bind file with zones, and, if anything changed, adapt it for the slave server, copy in the bind directory and reload bind.

Obviously it needs to be adapted to your needs, I run it every hour.

#!/bin/bash

VERSION=”0.1″

# bind_auto_slave
# Author:  info@farlock.org
#
# Description: copy bind file from master server, edit it and reload bind on slave
#
# ChangeLog: 0.1 – 28/04/17 – First Release

MASTER_SERVER=”ns1.xxx.com”
MASTER_SERVER_PORT=”22″
MASTER_SERVER_USER=”root”
MASTER_FILE=”/etc/smbind/smbind.conf”

SLAVE_FILE=”/etc/bind/ns1.conf”
SED_ARGUMENT=”s/master;/slave;\n\t\t\tmasters { servers_name; };/” # Argument that must be passed to sed

#SED_ARGUMENT=”s/master;/slave;/”

# First of all download file from master
TMP_FILE=$(mktemp)
chmod g+r,o+r $TMP_FILE
scp -q -P $MASTER_SERVER_PORT $MASTER_SERVER:$MASTER_FILE $TMP_FILE
if [ $? -ne 0 ] ; then

echo “Error downloading file from $MASTER_SERVER”
exit 11
fi

# Execute sed on it
#echo sed $SED_ARGUMENT $TMP_FILE
sed -i “$SED_ARGUMENT” $TMP_FILE
if [ $? -ne 0 ] ; then
echo “Error executing sed on file $TMP_FILE”
exit 12
fi

# Check differences
diff -q $TMP_FILE $SLAVE_FILE > /dev/null
if [ $? -ne 0 ] ; then # files differ
mv $TMP_FILE $SLAVE_FILE
service bind9 reload
if [ $? -ne 0 ] ; then
echo “Error reloading bind9 on slave server”
exit 13
fi
else
rm $TMP_FILE
fi

exit 0

 

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

*