Shell script strategy--DNS forward resolution one-click deployment

Article Directory


ready

  • Students who want to know more about DNS domain name resolution service can read my previous blog: DNS domain name resolution service
  • Don’t say much, just deliver dry goods
  • It is recommended to open two virtual machines, one is used to directly follow the steps and processes, and the other is used to follow my script to type commands (synchronize), which can better understand
  • The sed command is used more in the following, it is really fragrant

shell script

[root@localhost ~]# vim /opt/dns1.sh 

#!/bin/bash
#构建DNS域名解析服务器步骤之正向解析

#检测YUM源仓库是否挂载
df | grep "sr0"
if [ $? -eq 0 ]
        then
        yum -y install bind &> /dev/null
        #若已挂载则直接安装bind软件包
else
        mount /dev/cdrom /mnt &> /dev/null
        yum -y install bind &> /dev/null
        #若未挂载,则先挂载,再安装bind软件包"
fi

#关闭防火墙和强制访问控制安全系统
systemctl stop firewalld &> /dev/null
systemctl disable firewalld &> /dev/null
setenforce 0 &> /dev/null

#修改主配置文件
sed -i 's/127.0.0.1/any/' /etc/named.conf
sed -i 's/localhost/any/' /etc/named.conf

#修改区域配置文件,添加正向区域配置
sed -i 's/localhost.localdomain/xcf.com/' /etc/named.rfc1912.zones
sed -i 's/named.localhost/xcf.com.zone/' /etc/named.rfc1912.zones
sed -i '18,100d' /etc/named.rfc1912.zones

#配置正向区域数据文件
cd /var/named
cp -p named.localhost xcf.com.zone
sed -i 's/@/xcf.com./g' /var/named/xcf.com.zone
sed -i 's/rname.invalid./admin.xcf.com./' /var/named/xcf.com.zone
sed -i 's/127.0.0.1/192.168.126.15/' /var/named/xcf.com.zone
sed -i '9a www IN A  192.168.126.15' /var/named/xcf.com.zone
sed -i '/AAAA/d' /var/named/xcf.com.zone
sed -i '/::1/d' /var/named/xcf.com.zone

#启动服务
systemctl start named

#在客户端的域名解析配置文件中添加DNS服务器地址
sed -i '1a nameserver 192.168.126.15' /etc/resolv.conf

#重启下服务,有备无患
systemctl restart named

chmod +x /opt/dns1.sh

read -p "DNS正向解析已配置完毕,请输入域名:" p
host $p

mark

Guess you like

Origin blog.csdn.net/weixin_51486343/article/details/111939955