RedHat 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-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 "@    in    ns    $head">> $datadir/$domain
           fi
       ;;
       a)
           read -p "head of hostname:" head
           read -p "ip address:" ip
       echo "$head    in    a    $ip">> $datadir/$domain

       ;;
       ptr)
           read -p "ip address:" ip
           read -p "hostname of FQDN:" fqdn
           host=$(echo $ip | awk -F. '{print $4}')
       echo "$host    in    ptr    $fqdn.">> $datadir/$domain
       ;;
       mx)
           read -p "priority of recond:" priority
           read -p "head of hostname:" head
           read -p "ip address:" ip

       echo "@    in    mx    $priority    $head">>$datadir/$domain
       echo "$head    in    a    $ip">> $datadir/$domain
       ;;
       cname)
           read -p "please input aliase:" aliase
           read -p "head of hostname:" head
       echo "$aliase    in    cname    $head">> $datadir/$domain

       ;;
        esac
       read -p "continue to do (yes/no)?" yn
       if [ $yn = no ]; then
           exit 0
       fi

   done
fi


你可能感兴趣的:(File,domain,master)