脚本实现自动创建DNS域名服务器
前提:保证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
#!/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
相关推荐
windzoone 2020-07-29
hxf0 2020-07-10
dahege 2020-06-22
beiya 2020-06-03
chwzmx 2020-05-29
oLeiShen 2020-05-15
zhangskd 2020-05-15
AderStep 2020-11-09
82550294 2020-09-01
书弋江山 2020-08-11
windzoone 2020-08-06
clmngu 2020-07-26
niutingbaby 2020-06-14
tencentopen 2020-06-12
zhangskd 2020-06-04
岁月如歌 2020-05-19
末点 2020-05-17