前提:保证yum可以正常使用!
#!/bin/bash
read -p "Please input your domain name:" DOMAIN
read -p "Please input your IPaddress:" NET
hostname www.$DOMAIN
yum install bind caching-nameserver -y
a=`echo $NET |cut -d"." -f1`
b=`echo $NET |cut -d"." -f2`
c=`echo $NET |cut -d"." -f3`
d=`echo $NET |cut -d"." -f4`
cat > /etc/named.conf << "EOF"
options {
directory "/var/named" ;
};
zone "." IN {
type hint;
file "named.ca";
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.local";
};
zone "DOMAIN" IN {
type master;
file "DOMAIN.zone";
};
zone "FAN.in-addr.arpa" IN {
type master;
file "PTR.arpa";
};
EOF
sed -i 's/DOMAIN/'$DOMAIN'/g' /etc/named.conf
sed -i 's/FAN/'$c.$b.$a'/g' /etc/named.conf
sed -i 's/PTR/'$a.$b.$c'/g' /etc/named.conf
cat > /var/named/$DOMAIN.zone << "EOF"
$TTL 36400
@ IN SOA DOMAIN. admin.DOMAIN. (
2011024
3H
15M
1W
1D)
EOF
echo "@ IN NS www.$DOMAIN." >>/var/named/$DOMAIN.zone
echo " IN MX 10 mail.$DOMAIN." >> /var/named/$DOMAIN.zone
echo "www IN A $NET" >> /var/named/$DOMAIN.zone
echo "mail IN A $NET" >> /var/named/$DOMAIN.zone
sed -i 's/DOMAIN/'$DOMAIN'/g' /var/named/$DOMAIN.zone
cat > /var/named/$a.$b.$c.arpa << "EOF"
$TTL 36400
@ SOA DOMAIN. admin.DOMAIN. (
20110224
3H
15M
1W
1D)
EOF
echo "@ IN NS www.$DOMAIN." >> /var/named/$a.$b.$c.arpa
echo "$d IN PTR mail.$DOMAIN." >> /var/named/$a.$b.$c.arpa
echo "$d IN PTR www.$DOMAIN." >> /var/named/$a.$b.$c.arpa
sed -i 's/DOMAIN/'$DOMAIN'/g' /var/named/$a.$b.$c.arpa
echo "nameserver $NET" >>/etc/resolv.conf
ifconfig eth0 $NET
chown named /var/named/*.arpa
chown named /etc/named.conf
chown named /var/named/$DOMAIN.zone
service named restart
本文转自 张玉坡 51CTO博客,原文链接:http://blog.51cto.com/fighter/500005