DNS master slave synchronization script instance in shell script combat

Time:2020-10-30

DNS master slave synchronization script instance

PS: after the two servers are up, it is better to restart both services

Master server configuration

#!/bin/bash
#DNS master slave synchronization -- master server

rpm -q bind
if [ $? -ne 0 ];then
  yum install bind -y
  systemctl start named
fi
#Determine whether DNS service is installed

Please enter the primary server address: "read - P"
Please enter the slave address: "Cong
Read - P "domain name (Please add suffix):" Yu "
quanju="/etc/named.conf"
quyu="/etc/named.rfc1912.zones"
[ ! -e $quanju.bak ] && cp $quanju $quanju.bak
sed -i -e "13s/127.0.0.1/$zhu/" -e '21s/localhost/any/' $quanju
[ ! -e $quyu.bak ] && cp $quyu $quyu.bak
#Backup global and regional configuration files

grep "$yu" $quyu &> /dev/null
while [ $? -ne 0 ];do
 sed -i "18azone \"$yu\" IN {\n type master\;\n file \"$yu.dns\"\;\n allow-   transfer { $cong\; }\;\n}\;\n" $quyu
 peizhi="/var/named/$yu.dns"
cp -p /var/named/named.localhost $peizhi
done
#Determine whether the domain name exists, and add it if not

sed -i -e '2d' -e "[email protected]    IN SOA "$yu"\. admin\."$yu"\. (" /var/named/$yu.dns
sed -i '8d' /var/named/$yu.dns
sed -i '$d' /var/named/$yu.dns
sed -i -e "7a\   NS   $yu." -e "/A/s/127.0.0.1/$zhu/" /var/named/$yu.dns
#Modify area file

while [ 1 -ge 0 ];do
Read - P "please input custom pointer (e.g. WWW in a 8.8.8.8)"
 echo $zhen >> /var/named/$yu.dns
 Read - P "continue adding (Y / N)" a
if [ $a != "y" ];then
 break
fi
done
#Circulation

systemctl stop firewalld.service
setenforce 0
systemctl restart named
jieguo=`systemctl status named | grep "active" &>/dev/null`
if [ $? -eq 0 ];then
 Echo "service startup"
else
 Echo "start failed"
fi
#Judge whether the service can start normally

sed -i -e '3d' -e "2anameserver $zhu" /etc/resolv.conf
#For self-test

Configure from server

#!/bin/bash
#DNS master slave synchronization -- slave server

rpm -q bind
if [ $? -ne 0 ];then
  yum install bind -y
fi
#Determine whether DNS service is installed

Please enter the primary server address: "read - P"
Please enter the slave address: "Cong
Read - P "domain name (Please add suffix):" Yu "
quanju="/etc/named.conf"
quyu="/etc/named.rfc1912.zones"
[ ! -e $quanju.bak ] && cp $quanju $quanju.bak
sed -i -e "13s/127.0.0.1/$cong/" -e '21s/localhost/any/' $quanju
[ ! -e $quyu.bak ] && cp $quyu $quyu.bak
#Backup global and regional configuration files

grep "$yu" $quyu &> /dev/null
while [ $? -ne 0 ];do
 sed -i "18azone \"$yu\" IN {\n type slave\;\n file \"slaves\/$yu.dns\"\;\n  masters { $zhu\; }\;\n}\;\n" $quyu
done
#Determine whether the domain name exists, and add it if not

systemctl restart named
systemctl stop firewalld.service
setenforce 0
jieguo=`systemctl status named | grep "active" &>/dev/null`
if [ $? -eq 0 ];then
 Echo "service startup"
else
 Echo "start failed"
fi
#Judge whether the service can start normally

The above is the whole content of this article, I hope to help you in your study, and I hope you can support developeppaer more.