1 #!/bin/bash
2 #一键部署DNS正向解析
3
4 # 判断bind程序是否安装
5 if rpm -q bind &> /dev/null
6 then
7 continue
8 else
9 if yum install -y bind &> /dev/null
10 then
11 continue
12 else
13 echo "BIND installation failed....."
14 exit
15 fi
16 fi
17 read -p "输入域名(格式:baidu.com): " ym
18 read -p "输入要解析的IP: " ip
19
20 # 修改主配置文件
21 sed -i ‘s/127.0.0.1/any/‘ /etc/named.conf
22 sed -i ‘s/localhost;/any;/‘ /etc/named.conf
23
24 # 修改区域配置文件
25 echo ‘zone "‘$ym‘" IN {
26 type master;
27 file "‘$ym‘.zone";
28 allow-update { none; };
29 };‘ >> /etc/named.rfc1912.zones
30
31 # 复制区域数据文件模板并修改
32 cp -p /var/named/named.localhost /var/named/$ym.zone
33 sed -i ‘s/@ rname.invalid/‘$ym‘. admin.‘$ym‘/‘ /var/named/$ym.zone
34 sed -i ‘s/127.0.0.1/‘$ip‘/‘ /var/named/$ym.zone
35 sed -i ‘8 s/@/‘$ym‘./‘ /var/named/$ym.zone
36 echo ‘www IN A ‘$ip‘‘ >> /var/named/$ym.zone
37
38 # 判断named服务是否开启
39 if systemctl restart named &> /dev/null
40 then
41 echo "name启动完成...."
42 else
43 echo "name启动失败,已退出!"
44 exit
45 fi
46
47 # 修改临时DNS和IP的映射
48 echo ‘nameserver ‘$ip‘‘ > /etc/resolv.conf
49 echo "DNS正向解析已配置完成!"