[小芮]脚本安装bind-dns服务

自动创建dns服务,这个是给我的vsphere用的。大家也可以放在内网做dns。

这两天把智能dns的创建脚本也写下。。。。

#!/bin/bash    
iptables -I INPUT -p tcp --dport 53 -j ACCEPT 
yum -y install bind  caching-nameserver   
# install bind & caching-nameserver packages  
cp -f /etc/named.rfc1912.zones /etc/named.conf 
mv /etc/named.conf /etc/named.conf.old  
#configure the /etc/named.conf  
cat > /etc/named.caching-nameserver.conf << EOF
options { 
        listen-on port 53 { any; }; 
        listen-on-v6 port 53 { ::1; }; 
        directory       "/var/named"; 
        dump-file       "/var/named/data/cache_dump.db"; 
        statistics-file "/var/named/data/named_stats.txt"; 
        memstatistics-file "/var/named/data/named_mem_stats.txt"; 
   
        // Those options should be used carefully because they disable port 
        // randomization 
        // query-source    port 53; 
        // query-source-v6 port 53; 
   
        allow-query     { any; }; 
        allow-query-cache { any; }; 
}; 
logging { 
        channel default_debug { 
                file "data/named.run"; 
                severity dynamic; 
        }; 
}; 
view localhost_resolver { 
        match-clients      { any; }; 
        match-destinations { any; }; 
        recursion yes; 
        include "/etc/named.rfc1912.zones"; 
}; 
EOF 
cat  >> /etc/named.conf <<EOF
options {   
         directory "/var/named";  
     forwarders { 8.8.8.8;8.8.4.4; }; 
         allow-query {any;}; 
};   
zone "." IN {   
            type hint ;   
            file "named.ca";   
        };   
     
zone "0.0.127.in-addr.arpa" IN {   
            type master;   
            file "named.local";   
};   
zone "localhost" IN {   
            type master;   
            file "localhost.zone";   
};   
EOF 
read -p "please in put your domain name:" MYNET   
read -p "please in put your IP:" MYIP   
IP1=`echo $MYIP |cut -d. -f1`   
IP2=`echo $MYIP |cut -d. -f2`   
IP3=`echo $MYIP |cut -d. -f3`   
IP4=`echo $MYIP |cut -d. -f4`   
cat >> /etc/named.conf <<EOF  
zone "$MYNET" IN {   
    type master;   
    file "${MYNET}.zone";   
    };   
zone "$IP3.$IP2.$IP1.in-addr.arpa" IN {   
    type master;   
    file "$IP1.$IP2.$IP3.zone";   
    };   
EOF 
cat >> /var/named/${MYNET}.zone <<EOF
$TTL 86400   
$ORIGIN ${MYNET}.   
@   IN  SOA $MYNET  root.${MYNET}.  (   
            2011021201   
            1H   
            10M   
            7D   
            1D )   
    IN  NS  ns   
    IN  MX  10  mail   
ns  IN  A   $MYIP   
www IN  A   $MYIP   
mail    IN  A   $MYIP   
pop3    IN  CNAME   mail   
EOF 
cat >> /var/named/$IP1.$IP2.$IP3.zone<<EOF
$TTL 86400   
@       IN      SOA     $MYNET  root.${MYNET}.  (   
                        2011021201   
                        1H   
                        10M   
                        7D   
                        1D )   
        IN      NS  ns   
$IP4    IN  PTR mail.${MYNET}.   
EOF 
chown  named:named /etc/named.conf   
chown  named:named /var/named/$IP1.$IP2.$IP3.zone    
chown  named:named /var/named/${MYNET}.zone   
service named configtest   
chkconfig named on 
service named restart


你可能感兴趣的:(python,bind,bind,bind,dns,二次开发,dns脚本)