背景:
阅读新闻
脚本实现自动创建DNS域名服务器
[日期:2011-06-20] 来源:Linux社区 作者:fighter [字体:]
前提:保证yum可以正常使用!
#!/bin/bash
read -p "Please input your domain name:" DOMAIN
read -p "Please input your IPaddress:" NET
hostname $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 $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 $DOMAIN." >> /var/named/$a.$b.$c.arpa
echo "$d IN PTR mail.$DOMAIN." >> /var/named/$a.$b.$c.arpa
echo "$d IN PTR $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
本文评论 查看全部评论 (0)
尊重网上道德,遵守中华人民共和国的各项有关法律法规 承担一切因您的行为而直接或间接导致的民事或刑事法律责任 本站管理人员有权保留或删除其管辖留言中的任意内容 本站有权在网站内转载或引用您的评论 参与本评论即表明您已经阅读并接受上述条款
评论声明
最新资讯