脚本自动实现DNS服务各区域配置文件

#!/bin/bash
yum -y install bind  (安装DNS服务,如果没有yum源,可以使用rpm安装)    
yum -y install caching-nameserver
read -p "Please input your domainname:" DOMAIN

read -p "Please input your network:" NETWORK

read -p  "Please input your IP address:" IP

cat >> /etc/named.conf << EOF
options {
        directory "/var/named";
};

zone "." IN {
        type hint;
        file "named.ca";
};

zone "localhost" IN {
        type master;
        file "localhost.zone";
};

zone "0.0.127.in-addr.arpa" IN {
        type master;
        file "named.local";
};

zone "$DOMAIN" IN {
        type master;
        file "$DOMAIN.zone";
};

zone "$NETWORK.in-addr.arpa" IN {
        type master;
        file "$NETWORK.zone";
};
EOF
                 
echo "OK,/etc/named.conf is created!!! "

cat >> /var/named/$DOMAIN.zone << EOF
\$TTL 86400
\$ORIGIN $DOMAIN.
@       IN      SOA     $DOMAIN.        root.$DOMAIN.   (
                                        `date +%Y%m%d`01
                                        5H
                                        10M
                                        7D
                                        1D   )
           IN      NS      ns
           IN      MX 10   mail
ns        IN      A       $IP
mail     IN      A       $IP
www   IN      A       $IP
EOF

END=`echo $IP |cut -d"." -f4`                
cat >> /var/named/$NETWORK.zone << EOF
\$TTL 86400
@       IN      SOA     $DOMAIN.        root.$DOMAIN.   (
                                        `date +%Y%m%d`01
                                        5H
                                        10M
                                        7D
                                        1D   )
             IN           NS          ns.$DOMAIN.
$END   IN      PTR     ns.$DOMAIN.
$END   IN      PTR     mail.$DOMAIN.
$END   IN      PTR     www.$DOMAIN.
EOF

chown :named  /etc/named.conf /var/named/$DOMAIN.zone /var/named/$NETWORK.zone

echo "Ok,/var/named/$DOMAIN.zone , /var/named/$NETWORK.zone are created!!!"
echo "Good,the job is finished!!!"
 

你可能感兴趣的:(shell,脚本,shell脚本,dns,休闲)