主服务器配置
#!/bin/bash
#分分彩程序制作q<277.03.4.83.6>
#DNS主从同步——主服务器
rpm -q bind
if [ $? -ne 0 ];then
yum install bind -y
systemctl start named
fi
#判断DNS服务是否安装
read -p "请输入主服务器地址:" zhu
read -p "请输入从服务器地址:" cong
read -p "域名(请带后缀):" 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
#备份全局、区域配置文件
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
#判断域名是否存在,如果不存在进行添加
sed -i -e '2d' -e "1a@ 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
#修改区域文件
while [ 1 -ge 0 ];do
read -p "请输入自定义指针(例:www IN A 8.8.8.8)" zhen
echo $zhen >> /var/named/$yu.dns
read -p "是否继续添加(y/n)" a
if [ $a != "y" ];then
break
fi
done
#循环
systemctl stop firewalld.service
setenforce 0
systemctl restart named
jieguo=`systemctl status named | grep "active" &>/dev/null`
if [ $? -eq 0 ];then
echo "服务启动"
else
echo "启动失败"
fi
#判断服务是否能正常启动
sed -i -e '3d' -e "2anameserver $zhu" /etc/resolv.conf
#用于自检
从服务器配置
#!/bin/bash
#DNS主从同步——从服务器
rpm -q bind
if [ $? -ne 0 ];then
yum install bind -y
fi
#判断DNS服务是否安装
read -p "请输入主服务器地址:" zhu
read -p "请输入从服务器地址:" cong
read -p "域名(请带后缀):" 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
#备份全局、区域配置文件
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
#判断域名是否存在,如果不存在进行添加
systemctl restart named
systemctl stop firewalld.service
setenforce 0
jieguo=`systemctl status named | grep "active" &>/dev/null`
if [ $? -eq 0 ];then
echo "服务启动"
else
echo "启动失败"
fi
#判断服务是否能正常启动
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。