#!/bin/bash
#this script install bind for linux or centos 5.x version
#The original is only for your reference(原创仅供大家参考)
IP=`ifconfig | grep "inet addr" | grep -v "127.0.0.1" | cut -d: -f2 | cut -d' ' -f1` #get ip address(获取IP地址)
#IP=`ifconfig | grep -A 1 "eth0" | grep "inet addr" | cut -d: -f2 | cut -d' ' -f1 ` #if you have many network card,please use this
NIP=`echo $IP | awk -F . -v OFS="." '{print $3,$2,$1}'` #Reverse output IP(逆序输出ip的前三位)
FIP= `echo $IP | awk -F . -v OFS="." '{print $4}'` #output the fourth IP(输出ip的第四位)
mount /dev/cdrom /media/
echo "/dev/cdrom /media iso9660 defaults 0 0 " >> /etc/fstab
cat >> /etc/yum.repos.d/iso.repo << EOF
[redhat]
name=redhat5.4
baseurl=file:///media/Server/
gpgecheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
EOF
yum -y install bind-* caching-nameserver-*
#The main configuration file(主配置文件)
main_conf=/var/named/chroot/etc/named.caching-nameserver.conf
#Regional configuration file(区域配置文件)
reg_conf=/var/named/chroot/etc/named.rfc1912.zones
#According to the template set up positive and negative zone data configuration file(根据模板建立正反区域数据配置文件)
read -p "please input you company domain name(like abc.com):" domain
cd /var/named/chroot/var/named/
cp -p localdomain.zone $domain.zone
cp -p named.local $domain.local
cd /
#Positive regional data configuration file(正向区域数据配置文件)
pos_conf=/var/named/chroot/var/named/$domain.zone
#Reverse zones data configuration file(反向区域数据配置文件)
rev_conf=/var/named/chroot/var/named/$domain.local
#change or set this all configure file
sed -i 's/127\.0\.0\.1/any/g' $main_conf #the 127.0.0.1---->to--->any
sed -i 's/localhost\;/any\;/g' $main_conf
cat >> $reg_conf <<EOF
zone "$domain" IN {
type masteain.zone";
allow-updar;
file "$domte { none; };
};
zone "$NIP.in-addr.arpa" IN {
type master;
file "$domain.local";
allow-update { none; };
#Modify Positive regional data configuration file(修改正向区域数据配置文件)
sed -i "s/localhost/$domain\./g" $pos_conf
sed -i "s/root/root\.$domain\./g" $pos_conf
sed -i "s/127\.0\.0\.1/$IP/g" $pos_conf
echo "www IN A $IP" >> $pos_conf
#Modify Reverse zones data configuration file(修改反向区域数据配置文件)
sed -i "s/localhost\./$domain\./g" $rev_conf
sed -i "/PTR/s/$domain\./www\.$domain\./g" $rev_conf
sed -i "s/1/$FIP/g" $rev_conf
#start server
service named restart
chkconfig --add named
chkconfig --level 35 named on