#!/bin/bash
#測試是否安裝bind
[ ! -f /etc/named.conf ] && echo "沒有安裝DNS服務,如今安裝" && yum -y install bind &> /dev/null
echo "DNS軟件包已安裝!"
#修改主配置文件
sed -ri 's/127.0.0.1/192.168.220.146/' /etc/named.conf
sed -ri '/allow-query/s/localhost/any/' /etc/named.conf
#修改區域配置和區域配置數據文件
[ -f /etc/named.rfc1912.zones ] && cp /etc/named.rfc1912.zones /etc/named.rfc1912.zones.bak
while : ;do
read -p "請輸入域名: " a
read -p "區域數據配置文件名: " b
echo "
zone \"$a\" IN {
type master;
file \"$b\";
allow-update { none; };
};" >> /etc/named.rfc1912.zones
cp -p /var/named/named.localhost /var/named/$b
sed -i '9,10d' /var/named/$b
sed -i "/SOA/s/A.*\./A $a. admin.$a./" /var/named/$b
sed -i "/NS/s/@/$a\./" /var/named/$b
read -p "請輸入域名解析地址: " e
echo " A $e" >> /var/named/$b
while :;do
echo -n "請輸入主機名+IP地址(例:www 192.168.100.100用空格分割,輸入q退出): "
read q w
if [ $q = "q" ];then
break
else
echo "$q IN A $w" >> /var/named/$b
fi
done
read -p "是否輸入下一個解析域名(回車爲繼續): " d
[ ! $d = " " ] && break
done
systemctl status named
if [ $? -eq 0 ];then
systemctl restart named
else
systemctl start named
fi
systemctl stop firewalld.servicebash