Hi All,
I have created a script which basicly synchronize all DNS zones from a remote
DirectAdmin server,
the script can be usefull for creating a secondary DNS without doing a MultiServers Link in the DA,
It also can be use if you want to create a secondary DNS that will do only DNS without panel at all.
For automation script i used SSH public/private key infastracutre,
i will be happy to hear your comments.
#----------------- Code From Here
#!/bin/bash
# All Rights reserverd Juda Barnes (c) 2010
# This Script is usefull to copy all DNS domain files from a remote
# directadmin server to your local server
# it can be usefull to create secondary DNS server to several directadmin
# servers without using the DIRECTADMIN MultiServer synch option
#
# Basicly if you addent to have a secondary linux server that use for
# Secondary DNS then you shall run the script from the secondary server
# the script will remote copy *.db files from the remote directadmin server
# and also copy the servered domains from the remote directadmin server
# all the necesery files will be copied localy to directory /etc/bind/transfer
# and the IP Address of the server
# after you run the script you will have a file /etc/bind/transfer/named.ip.conf
# just load this configuration file to your orginal named.conf
# and you can start run a secondary dns server
# without use the DA MultiServer option
#
# ------------------------------------------------------------------------
# Parameters that need to be added when you run the command
# $1 Remote directAdmin server IP Address
# $2 Local Ident file to be use for remote ssh FILE
# $3 Remote username to be used
# For example
# ./get-domain.sh 222.222.222.222 /home/myuser/my-private-key judab
#
# Confiure remote user
# It is suggested not to use root as remote user
# Therefore i have created user name judab
# i have generated public/private key and copy the public key signature
# to the remote user directory into /home/judab/.ssh/authorized_keys file
# You can find information how to generate the Signature in this Link
# http://troy.jdmz.net/rsync/index.html
REMOTEUSER="$3"
# This user shall have access to read /etc/virtual/domains
# And to read /etc/bind/* files
#
#-------------------------------
if [ "$1" = "" ] ; then
echo Error: Please sepcifiy server IP Address
echo Syntax ./get-domain [remote server] [ident file] [remote username]
exit
else
echo start copy domains from server $1
fi
if [ "$2" = "" ] ; then
echo Error: No ident file
echo Syntax ./get-domain [remote server] [ident file] [remote username]
exit
else
echo Using ident
fi
if [ "$3" = "" ] ; then
echo Error: No remote user speicifed
echo Syntax ./get-domain [remote server] [ident file] [remote username]
exit
else
echo Using username $3
fi
if [ "$3" = "root" ] ; then
echo Error: You can not use root remote account for security reason
echo Syntax ./get-domain [remote server] [ident file] [remote username]
exit
fi
#Check server alive
ping -c 1 $1 > /dev/null
if [ "$?" = "0" ] ; then
echo Server alive
else
echo Server is not answering ping.. exiting ..
exit 1
fi
#mkdir
mkdir /etc/bind/transfer
mkdir /etc/bind/transfer/$1
#Copy Domain Files
scp -B -i $2 $REMOTEUSER@$1:/etc/bind/*.db /etc/bind/transfer/$1
if [ "$?" = "0" ] ; then
echo Copy name File OK
else
echo Copy Name file FAIL .
exit 1
fi
scp -B -i $2 $REMOTEUSER@$1:/etc/virtual/domains /etc/bind/transfer/$1
if [ "$?" = "0" ] ; then
echo Copy Domain list OK
else
echo Copy Domain list FAIL .
exit 1
fi
cd /etc/bind/transfer/$1
echo Generate conf fle
cat domains | awk -v namesrv=$1 '{ print "zone \"" $1 "\"" " { type master; file
\"/etc/bind/transfer/" namesrv "/" $1 ".db\"; }; " }' > /etc/bind/trans
fer/named.$1.conf
#------------------ End of File
I have created a script which basicly synchronize all DNS zones from a remote
DirectAdmin server,
the script can be usefull for creating a secondary DNS without doing a MultiServers Link in the DA,
It also can be use if you want to create a secondary DNS that will do only DNS without panel at all.
For automation script i used SSH public/private key infastracutre,
i will be happy to hear your comments.
#----------------- Code From Here
#!/bin/bash
# All Rights reserverd Juda Barnes (c) 2010
# This Script is usefull to copy all DNS domain files from a remote
# directadmin server to your local server
# it can be usefull to create secondary DNS server to several directadmin
# servers without using the DIRECTADMIN MultiServer synch option
#
# Basicly if you addent to have a secondary linux server that use for
# Secondary DNS then you shall run the script from the secondary server
# the script will remote copy *.db files from the remote directadmin server
# and also copy the servered domains from the remote directadmin server
# all the necesery files will be copied localy to directory /etc/bind/transfer
# and the IP Address of the server
# after you run the script you will have a file /etc/bind/transfer/named.ip.conf
# just load this configuration file to your orginal named.conf
# and you can start run a secondary dns server
# without use the DA MultiServer option
#
# ------------------------------------------------------------------------
# Parameters that need to be added when you run the command
# $1 Remote directAdmin server IP Address
# $2 Local Ident file to be use for remote ssh FILE
# $3 Remote username to be used
# For example
# ./get-domain.sh 222.222.222.222 /home/myuser/my-private-key judab
#
# Confiure remote user
# It is suggested not to use root as remote user
# Therefore i have created user name judab
# i have generated public/private key and copy the public key signature
# to the remote user directory into /home/judab/.ssh/authorized_keys file
# You can find information how to generate the Signature in this Link
# http://troy.jdmz.net/rsync/index.html
REMOTEUSER="$3"
# This user shall have access to read /etc/virtual/domains
# And to read /etc/bind/* files
#
#-------------------------------
if [ "$1" = "" ] ; then
echo Error: Please sepcifiy server IP Address
echo Syntax ./get-domain [remote server] [ident file] [remote username]
exit
else
echo start copy domains from server $1
fi
if [ "$2" = "" ] ; then
echo Error: No ident file
echo Syntax ./get-domain [remote server] [ident file] [remote username]
exit
else
echo Using ident
fi
if [ "$3" = "" ] ; then
echo Error: No remote user speicifed
echo Syntax ./get-domain [remote server] [ident file] [remote username]
exit
else
echo Using username $3
fi
if [ "$3" = "root" ] ; then
echo Error: You can not use root remote account for security reason
echo Syntax ./get-domain [remote server] [ident file] [remote username]
exit
fi
#Check server alive
ping -c 1 $1 > /dev/null
if [ "$?" = "0" ] ; then
echo Server alive
else
echo Server is not answering ping.. exiting ..
exit 1
fi
#mkdir
mkdir /etc/bind/transfer
mkdir /etc/bind/transfer/$1
#Copy Domain Files
scp -B -i $2 $REMOTEUSER@$1:/etc/bind/*.db /etc/bind/transfer/$1
if [ "$?" = "0" ] ; then
echo Copy name File OK
else
echo Copy Name file FAIL .
exit 1
fi
scp -B -i $2 $REMOTEUSER@$1:/etc/virtual/domains /etc/bind/transfer/$1
if [ "$?" = "0" ] ; then
echo Copy Domain list OK
else
echo Copy Domain list FAIL .
exit 1
fi
cd /etc/bind/transfer/$1
echo Generate conf fle
cat domains | awk -v namesrv=$1 '{ print "zone \"" $1 "\"" " { type master; file
\"/etc/bind/transfer/" namesrv "/" $1 ".db\"; }; " }' > /etc/bind/trans
fer/named.$1.conf
#------------------ End of File