#!/bin/bash

echo "检测您现在是本地源还是网络源"

aa=`ls /etc/yum.repos.d | wc -l `

if [[ $aa == 1 ]]

then

echo "您现在是本地源"

touch /mnt/sr0

umount /dev/sr0

mount /dev/sr0 /mnt/sr0

yum clean all

else

echo "您现在是网络源"

yum clean all

fi

echo "开始yum下载dns服务"

yum clean all

yum -y install named

echo "开始备份named文件"

cp /etc/named.conf /etc/named.conf.bak

echo "dns服务文件开始配置"

cat /etc/named.conf

sed -i '13s/127.0.0.1/any/' /etc/named.conf

sed -i '21s/localhost/any/' /etc/named.conf

sed -i '35s/yes/no/' /etc/named.conf

sed -i '36s/yes/no/' /etc/named.conf

sed -i '/dnssec-validation no;/a\ dnssec-lookaside auto;' /etc/named.conf

read -p "请输入您的域名例:sbl" cc

read -p "请输入您的ip第三个地址段" dd

cat <<EOF >> /etc/named.conf

zone "${cc}" IN {

type master;

file "${cc}.zone";

};


zone "${dd}.168.192.in-addr.arpa" IN {

type master;

file "192.168.${dd}.zone";

};

EOF

echo "====================接下来开始配置正向代理解析域名操作==================="

read -p "请输入您要创建正向解析域名的文件例:sbl.com" ee

read -p "请输入您要解析的域名例:sbl.com" ff

cd /var/named/

touch ${ee}.zone

gg=`date +%Y%m%d`

cat <<EOF >> ${ee}.zone

\$TTL 86400

@ IN SOA www.${ff} root.${ff} (

                      $gg

                      3H

                      15M

                      1W

                      1D)

            NS www.${ff}

www A 192.168.141.129

wml A 192.168.141.130

ftp A 192.168.141.131

AAAA ::1

EOF

echo "===================接下来开始配置反向代理解析域名操作====================="

read -p "请输入您要创建正向解析域名的文件例:ip第三个值段" hh

read -p "请输入您要解析的域名例:sbl.com" ii

cd /var/named/

touch 192.168.${hh}.zone

jj=`date +%Y%m%d`

cat <<EOF >> 192.168.${hh}.zone

\$TTL 86400

@ IN SOA www.${ii} root.${ii} (

                                  $gg

                                   3H

                                   15M

                                   1W

                                  1D)

                                 IN NS www.${ii}

129       IN PTR www.${ii}

130       IN PTR www.${ii}

131       IN PTR ftp.${ii}

EOF

echo "===============开始修改权限================"

chgrp named ${ee}.zone

chgrp named ${hh}.zone

echo "===============开始重启服务================"

systemctl restart named.service

echo "===============开始测试================"

nslookup