shell脚本一键部署——DNS正向解析

DNS正向解析

一、脚本如下

#!/bin/bash
#一键部署DNS正向解析
 
# 判断bind程序是否安装
rpm -q bind
if [ $? -eq 1 ];then
yum install -y bind &> /dev/null
fi

read -p "输入域名(格式:baidu.com): " ym
read -p "输入要解析的IP:  " ip
 
# 修改主配置文件
sed -i 's/127.0.0.1/any/' /etc/named.conf
sed -i 's/localhost;/any;/' /etc/named.conf
 
# 修改区域配置文件
echo 'zone "'$ym'" IN {
        type master;
        file "'$ym'.zone";
        allow-update { none; };
};' >> /etc/named.rfc1912.zones
 
# 复制区域数据文件模板并修改
cp -p /var/named/named.localhost /var/named/$ym.zone
sed -i 's/@ rname.invalid/'$ym'. admin.'$ym'/' /var/named/$ym.zone
sed -i 's/127.0.0.1/'$ip'/' /var/named/$ym.zone
sed -i '8 s/@/'$ym'./' /var/named/$ym.zone
echo  'www IN  A        '$ip'' >> /var/named/$ym.zone
 
# 判断named服务是否开启
systemctl start named
systemctl stop firewalld
setenforce 0

 
# 修改临时DNS和IP的映射
echo 'nameserver '$ip'' > /etc/resolv.conf
echo "DNS正向解析已配置完成!"

二、实例操作

[root@192 ~]# vim demo1.sh
[root@192 ~]# chmod +x demo1.sh 
[root@192 ~]# ./demo1.sh 
未安装软件包 bind 
输入域名(格式:baidu.com): ly.com
输入要解析的IP:  192.168.229.90
setenforce: SELinux is disabled
DNS正向解析已配置完成!
[root@192 ~]# nslookup www.ly.com
Server:		192.168.229.90
Address:	192.168.229.90#53

Name:	www.ly.com
Address: 192.168.229.90

  

  

posted on 2021-08-05 10:57  笑洋仟  阅读(182)  评论(0编辑  收藏  举报

levels of contents