One-click deployment of DNS forward resolution
- This script is not perfect, it will be improved in time
- Before using this script, please make sure that the local yum source or the online yum source is connected
- Please do not run this script repeatedly, or it will be added repeatedly, you can uninstall bind before installation and execute this script
#!/usr/bin/expect
#编写主配置文件函数
zhupeizhi() {
sed -i "13 s/127.0.0.1/any/1" /etc/named.conf
sed -i "19 s/localhost/any/1" /etc/named.conf
}
#编写区域配置文件函数
quyupeizhi() {
sed -i '12a zone "lisi.com" IN { \n type master; \n file "lisi.com.zone"; \n allow-update { none; }; \n }; ' /etc/named.rfc1912.zones
}
#编写正向配置文件函数
zhengxiang() {
cp -p /var/named/named.localhost /var/named/lisi.com.zone
sed -i '2 s/@/lisi.com./2' /var/named/lisi.com.zone
sed -i '8 s/@/lisi.com./1' /var/named/lisi.com.zone
sed -i '9 s/127.0.0.1/192.168.163.10/1' /var/named/lisi.com.zone
sed -i '10d' /var/named/lisi.com.zone
sed -i '9a www IN A 192.168.163.10' /var/named/lisi.com.zone
}
#判断是否安装bind,没有就安装
rpm -q bind &>/dev/null
if [ $? -eq 1 ];then
yum -y install bind &>/dev/null
fi
#调用函数
zhupeizhi
quyupeizhi
zhengxiang
sed -i '1a nameserver 192.168.163.10' /etc/resolv.conf
#启动服务
systemctl start named
#关闭防火墙
systemctl stop firewalld
setenforce 0 &>/dev/null