#!/bin/bash
# Just need to reset variable "MYIP" and "MYDOMAIN" to yourself.
MYIP="192.168.80.6"
MYDOMAIN="example.com"
export MYIP MYDOMAIN
#--------------------------------------
# Don't change anything in the below,
# unless you know what you are doing.
#--------------------------------------
# Install Packages.
#--------------------------------------
yum -y install bind bind-chroot
#--------------------------------------
# Modify "/etc/named.conf"
#--------------------------------------
sed -i 's/127.0.0.1;/any;/g' /etc/named.conf
sed -i 's/localhost;/any;/g' /etc/named.conf
#--------------------------------------
# Modify "/etc/named.rfc1912.zones"
#--------------------------------------
grep "$MYDOMAIN" /etc/named.rfc1912.zones > /dev/null
if [ $? -ne 0 ]; then
cat >> /etc/named.rfc1912.zones << _EOF_
zone "$MYDOMAIN" IN {
type master;
file "$MYDOMAIN.zone";
allow-update { none; };
};
zone "$(echo $MYIP | awk -F"." '{print $3"."$2"."$1}').in-addr.arpa" IN {
type master;
file "$(echo $MYIP | awk -F"." '{print $1"."$2"."$3}').zone";
allow-update { none; };
};
_EOF_
fi
#--------------------------------------
# Create forward and backward resolve file
#--------------------------------------
/bin/cp -p /var/named/named.localhost /var/named/"$MYDOMAIN".zone
/bin/cp -p /var/named/named.localhost /var/named/"$(echo $MYIP | awk -F"." '{print $1"."$2"."$3}')".zone
cat > /var/named/"$MYDOMAIN".zone << _EOF_
\$TTL 1D
@ IN SOA $MYDOMAIN. rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS $MYDOMAIN.
$MYDOMAIN. A $MYIP
www A $MYIP
ftp A $MYIP
$MYDOMAIN. MX 5 mail.$MYDOMAIN.
mail A $MYIP
_EOF_
cat > /var/named/"$(echo $MYIP | awk -F"." '{print $1"."$2"."$3}')".zone << _EOF_
\$TTL 1D
@ IN SOA $MYDOMAIN. rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS $MYDOMAIN.
$(echo $MYIP | awk -F"." '{print $4}') PTR $MYDOMAIN.
$(echo $MYIP | awk -F"." '{print $4}') PTR www.$MYDOMAIN.
$(echo $MYIP | awk -F"." '{print $4}') PTR ftp.$MYDOMAIN.
$(echo $MYIP | awk -F"." '{print $4}') PTR mail.$MYDOMAIN.
_EOF_
#--------------------------------------
# Modify "/etc/resolv.conf"
#--------------------------------------
cat > /etc/resolv.conf << _EOF_
search $MYDOMAIN
nameserver $MYIP
_EOF_
#--------------------------------------
# Restart DNS service
#--------------------------------------
/etc/init.d/named restart