首页 > 代码库 > shell脚本之dns安装配置

shell脚本之dns安装配置

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*

echo "

options {

directory \"/var/named\";

};

" > $conf

fi

read -p "please input domain:" 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. (

2014010101

3h

15m

1w

1d

)

" > $datadir/$domain

fi


while true

do

read -p "please type of record:(ns/a/mx/cname)" type

case $type in

ns)

read -p "head of FQDN:" head

read -p "ip address:" ip

read -p "Are you sure?(yes/no)" yn

if [ $yn != yes ];then

continue

fi


echo "

@ in ns $head

$head in a $ip

" >> $datadir/$domain

;;

a)

read -p "head of FQDN:" head

read -p "ip address:" ip

read -p "Are you sure?(yes/no)" yn

if [ $yn != yes ];then

continue

fi

echo "

$head in a $ip

" >> $datadir/$domain

;;

mx)

read -p "head of FQDN:" head

read -p "ip address:" ip

read -p "priority:" priority

read -p "Are you sure?(yes/no)" yn

if [ $yn != yes ];then

continue

fi

echo "

@ in mx $priority $head

$head in a $ip

" >> $datadir/$domain


;;

cname)

read -p "aliase of FQDN:" aliase

read -p "hostname:" hostname

read -p "Are you sure?(yes/no)" yn

if [ $yn != yes ];then

continue

fi

echo "

$aliase in cname $hostname

" >> $datadir/$domain

;;

*)

echo "usage: type of record (ns/a/mx/cname)"

esac

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

if [ $yn != yes ];then

break

fi

done

service named restart


shell脚本之dns安装配置