提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
DNS正向解析shell脚本
代码如下(示例):
#!/bin/bash
echo -e "\033[31m =====正在验证当前为仅主机还是NAT模式===== \033[0m"
ping -c1 -W1 www.baidu.com &> /dev/null
if [ $? -eq 0 ];then echo -e "\033[31m 检测当前为NAT模式,为您配置在线yum源 \033[0m"
mkdir -p /etc/yum.repos.d/repo.bak
mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/null
yum clean all &> /dev/null
yum list &> /dev/null
echo -e "\033[31m 在线源已配置完成 \033[0m"
else
echo -e "\033[31m 检测当前为仅主机模式,为您配置本地yum源 \033[0m"
mount /dev/sr0 /mnt &> /dev/null
cd /etc/yum.repos.d/
mkdir -p /etc/yum.repos.d/repo.bak
mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null
echo '[local]
name=local
baseurl=file:///mnt
enabled=1
gpgcheck=0' > /etc/yum.repos.d/local.repo
yum clean all &> /dev/null
yum makecache &> /dev/null
df -h | grep "/mnt"
if [ $? -ne 0 ];then
echo -e "\033[31m 检测当前为仅主机模式,但光盘未连接! \033[0m"
else
echo -e "\033[31m 本地yum源已配置完成 \033[0m"
fi
fi
yum -y install bind &> /dev/null
#修改主配置文件 :/etc/named.conf
sed -i 's/127.0.0.1;/any;/' /etc/named.conf
sed -i 's/localhost;/any;/' /etc/named.conf
for ((;;))
do
read -p "请输入你需要配置的域名(例www.abc.com):" a
b=`echo $a | awk -F "." 'BEGIN{OFS="."}{$2=$2;print$2,$3}'`
c=`ip a | grep "ens33" | awk NR==2'{print}' | awk -F/ '{print$1}' | awk '{print$2}'`
#修改区域配置文件 :/etc/named.rfc1912.zones
echo "zone \"$b\" IN {
type master;
file \"$b.zone\";
allow-update { none; };
};" >> /etc/named.rfc1912.zones
#修改区域数据配置文件 :/var/named/named.localhost
cd /var/named
cp -p named.localhost $b.zone
sed -i "2c @ IN SOA $b. rname.invalid. (" /var/named/$b.zone
sed -i "8c NS $b." /var/named/$b.zone && sed -i "8 s/^/\t/" /var/named/$b.zone
sed -i "9c A $c" /var/named/$b.zone && sed -i "9 s/^/\t/" /var/named/$b.zone
sed -i "10c www IN A $c" /var/named/$b.zone
#添加指定dns服务器
sed -i "2c nameserver $c" /etc/resolv.conf
read -p "是否需要继续添加(y/n):" d
case $d in
y)
continue
;;
n)
#关闭系统防火墙和系统安全机制
systemctl stop firewalld
setenforce 0
#开启dns服务
systemctl restart named
break
;;
*)
echo "请正确输入"
systemctl stop firewalld
setenforce 0
systemctl restart named
break
esac
done