#!/bin/bash
echo "DNS 的安装配置"
rpm -q bind
if [[ $? -eq 0 ]];then
echo "DNS软件已安装"
else
echo "安装DNS软件"
yum install -y bind
if [[ $? -eq 0 ]];then
echo "安装完成"
else
echo "安装失败"
fi
fi
cd /etc
test -e /etc/named.conf.bak || cp /etc/named.conf /etc/named.conf.bak
echo "DNS配置"
read -p "是否配置DNS: [y/n] " ap
if [ ${ap} = "y" ]; then
sed -i 's/127.0.0.1/any/g' named.conf
sed -i 's/localhost/any/g' named.conf
while true; do
read -p "创建区域名称:" -t 20 qname
grep ${qname} named.conf
if [[ $? -eq 0 ]];then
echo "区域名称已被使用"
else
break;
fi
done
cat << EOF >> named.conf
zone "${qname}" IN {
type master;
file "${qname}.zone";
allow-update {none;};
};
EOF
ip=`ifconfig|grep inet | awk 'NR==1 {print $2}'`
echo ">>>>>>> ${ip}"
cd /var/named
echo "创建资源记录文件....."
cp -a named.localhost ${qname}.zone
cat << EOF > ${qname}.zone
\$TTL 1D
@ IN SOA ${qname}. root.${qname}. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS ds.${qname}.
ds IN A ${ip}
EOF
while true; do
read -p "输入主机名:" -t 20 n
read -p "输入主机名对应IP:" -t 20 p
cat << EOF >> ${qname}.zone
${n} IN A ${p}
EOF
read -p "是否继续添加:[y/n]" -t 20 op
if [ ${op} = n ]; then
break;
fi
done
read -p "是否定义别名:[y/n]" -t 20 s
if [ ${s} = "y" ]; then
while true; do
read -p "输入主机别名:" -t 20 na
read -p "输入主机名" -t 20 hn
cat <<- EOF >> ${qname}.zone
${na} CNAME ${hn}
EOF
read -p "是否继续添加:[y/n]" -t 20 op
if [ ${op} = n ]; then
break;
fi
done
fi
uname -a | grep el7
if [[ $? -eq 0 ]]; then
service firewalld stop
else
service iptables stop
fi
named-checkconf
named-checkzone ${qname} /var/named/${qname}.zone
service named restart
else
echo "退出脚本..."
fi
网友评论