脚本功能:
你只需为DNS指定域名和IP便可创建一个功能完善的DNS服务器
如果有其余DNS记录的需求,可在此脚本中直接添加
前提:
保证有可用的yum安装环境
脚本内容如下:
#!/bin/bash
# Author: Vivid
# Date & Time: 2011-02-10 09:53:38
# Description:
read -p "Your domain:" DOMAIN
#read -p "Your network:" $NETWORK
read -p "Local IP:" IP
IP1=`echo $IP | cut -d"." -f1`
IP2=`echo $IP | cut -d"." -f2`
IP3=`echo $IP | cut -d"." -f3`
IP4=`echo $IP | cut -d"." -f4`
NETWORK="$IP1.$IP2.$IP3"
echo "Installing bind,caching-nameserver..."
yum -y install bind &> /dev/null
yum -y install caching-nameserver &> /dev/null
yum -y remove bind-chroot &> /dev/null
touch /etc/named.conf &> /dev/null
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 "IP3.IP2.IP1.in-addr.arpa" IN {
type master;
file "NETWORK.zone";
};
EOF
sed -i 's/DOMAIN/'$DOMAIN'/g' /etc/named.conf
sed -i 's/NETWORK/'$NETWORK'/g' /etc/named.conf
sed -i 's/IP2/'$IP2'/g' /etc/named.conf
sed -i 's/IP3/'$IP3'/g' /etc/named.conf
sed -i 's/IP1/'$IP1'/g' /etc/named.conf
touch /var/named/$DOMAIN.zone &> /dev/null
cat > /var/named/$DOMAIN.zone << "EOF"
$TTL 86400
$ORIGIN DOMAIN.
@ IN SOA DOMAIN. root.DOMAIN. (
2011021101
1H
10M
7D
1D )
IN NS ns
IN MX 10 mail
ns IN A IP
mail IN A IP
www IN CNAME mail
EOF
sed -i 's/DOMAIN/'$DOMAIN'/g' /var/named/$DOMAIN.zone
sed -i 's/IP/'$IP'/g' /var/named/$DOMAIN.zone
touch /var/named/$NETWORK.zone &> /dev/null
cat > /var/named/$NETWORK.zone << "EOF"
$TTL 86400
@ IN SOA DOMAIN. root.DOMAIN. (
2011021101
1H
10M
7D
1D )
IN NS ns.DOMAIN.
IP4 IN PTR ns.DOMAIN.
IP4 IN PTR mail.DOMAIN.
EOF
sed -i 's/DOMAIN/'$DOMAIN'/g' /var/named/$NETWORK.zone
sed -i 's/IP4/'$IP4'/g' /var/named/$NETWORK.zone
chown :named /var/named/$DOMAIN.zone /var/named/$NETWORK.zone /etc/named.conf
echo "Startint named service..."
service named start
chkconfig named on
echo "Named started!"
sed -i 's/^search.*$/search '$DOMAIN' /g' /etc/resolv.conf
sed -i 's/^nameserver.*$/nameserver 127.0.0.1/g' /etc/resolv.conf
完!
为了保证你所yum在创建完DNS,修改过本地DNS指向过依旧可用楞执行如下命令:
# sed -i 's/instructor.example.com/yum源位路径或IP/g' /etc/yum.repos.d/server.repo