通过脚本完成DNS自动配置,要求如下:

1、完成DNS基本配置

2、根据提示输入域名、区域文件名、记录类型、主机头、IP地址等信息完成添加域及记录的工作


#!/bin/bash

conf=/var/named/chroot/etc/named.conf

datadir=/var/named/chroot/var/named


rpm -q bind &> /dev/null

if [ $? -ne 0 ]; then

yum -y install bind bind-chroot caching-nameserver

fi


if [ ! -f $conf ];then

echo "options {

directory \"/var/named\";

};" > $conf

fi


read -p "please input domain_name:" domain

grep $domain $conf &> /dev/null

if [ $? -ne 0 ]; then

echo "zone \"$domain\" in {  

type master;

file \"$domain\";

};" >> $conf

echo "\$ttl 86400

@ in soa ${domain}. root.${domain}. (

2013010101

3h

15m

1w

1d

)"> $datadir/$domain

while true

do

read -p "Type of recond(ns/a/cname/mx/ptr):" type

case $type in

ns)

echo $domain | grep "in-addr.arpa" &> /dev/null


if [ $? -eq 0 ]; then

read -p "hostname of FDQN:" fdqn

               echo "@ in      ns      $fdqn.">> $datadir/$domain


else

read -p "head of hostname:" head

echo "@inns$head">> $datadir/$domain

fi

;;

a)

read -p "head of hostname:" head

read -p "ip address:" ip

echo "$headina$ip">> $datadir/$domain


;;

ptr)

read -p "ip address:" ip

read -p "hostname of FQDN:" fqdn

host=$(echo $ip | awk -F. '{print $4}')

echo "$hostinptr$fqdn.">> $datadir/$domain

;;

mx)

read -p "priority of recond:" priority

read -p "head of hostname:" head

read -p "ip address:" ip

echo "@inmx$priority$head">>$datadir/$domain

echo "$headina$ip">> $datadir/$domain

;;

cname)

read -p "please input aliase:" aliase

read -p "head of hostname:" head

echo "$aliaseincname$head">> $datadir/$domain

;;

esac

read -p "continue to do (yes/no)?" yn

if [ $yn = no ]; then

exit 0

fi

done

fi