DNS正向解析

<pre class="brush:bash;gutter:true;">#!/bin/bash<br></br>#配置正向解析
#安装bind软件包
cd ~
yum -y install bind

read -p "请输入想要解析的域名,譬如(www.baidu.com): " a

b=`echo $a | awk -F '.' 'BEGIN{OFS="."}{$2=$2;print $2,$3}'`

c=`ifconfig | grep "inet" | awk 'NR==1 {print $2}'`

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

#修改区域配置文件
sed -i '18,50d' /etc/named.rfc1912.zones
sed -i 's/localhost.localdomain/'$b'/' /etc/named.rfc1912.zones
sed -i 's/named.localhost/'$b'.zone/' /etc/named.rfc1912.zones

#修改区域数据配置文件
#备份区域数据配置文件
cd /var/named
cp -p named.localhost $b.zone

sed -i 's/@/'$b'./2' /var/named/$b.zone
sed -i 's/rname.invalid./admin.abc.com./' /var/named/$b.zone
sed -i '8s/@/'$b'./' /var/named/$b.zone
sed -i 's/127.0.0.1/'$c'/' /var/named/$b.zone
sed -i '10c www IN A '$c'' /var/named/$b.zone

#启动服务,关闭防火墙
systemctl stop firewalld
setenforce 0

systemctl start named
systemctl restart named
#named -u named

#如果服务启动卡住,可以执行下面命令解决
#rndc-confgen -r /dev/urandom -a

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

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

标签: shell, 配置文件, etc, zone, DNS, named, var, sed, 一键

相关文章推荐

添加新评论,含*的栏目为必填