#!/bin/bash
yum -y install bind caching-nameserver
read -p "Please give your domain:(a.com)" MYDOMAIN
read -p "Please give your network:(192.168.0)" MYNETWORK
read -p "Please give your IP:(192.168.0.1)" MYIP
FNET=`echo "$MYNETWORK"|cut -d. -f3`.`echo "$MYNETWORK"|cut -d. -f2`.`echo "$MYNETWORK"|cut -d. -f1`
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 "$MYDOMAIN" IN {
type master;
file "$MYDOMAIN.zone";
};
zone "$FNET.in-addr.arpa" IN {
type master;
file "$MYNETWORK.zone";
};
EOF
echo "OK,/etc/named.conf create successfully! "
cat >> /var/named/$MYDOMAIN.zone << EOF
\$TTL 86400
\$ORIGIN $MYDOMAIN.
@ IN SOA $MYDOMAIN. root.$MYDOMAIN. (
`date +%Y%m%d`01
5H
10M
7D
1D )
IN NS ns
IN MX 10 mail
ns IN A $MYIP
mail IN A $MYIP
www IN A $MYIP
EOF
END=`echo $MYIP |cut -d"." -f4`
cat >> /var/named/$MYNETWORK.zone << EOF
\$TTL 86400
@ IN SOA $MYDOMAIN. root.$MYDOMAIN. (
`date +%Y%m%d`01
5H
10M
7D
1D )
IN NS ns.$MYDOMAIN.
$END IN PTR ns.$MYDOMAIN.
$END IN PTR mail.$MYDOMAIN.
$END IN PTR www.$MYDOMAIN.
EOF
chown :named /etc/named.conf /var/named/$MYDOMAIN.zone /var/named/$MYNETWORK.zone
echo "Ok,/var/named/$MYDOMAIN.zone , /var/named/$MYNETWORK.zone are created successfully!"
echo "Change the /etc/hosts..."
cp /etc/hosts /etc/hosts.bak
echo "
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
$MYIP mail.$MYDOMAIN mail" > /etc/hosts
echo "The /etc/hosts changed successfully!"
echo "Change the /etc/resolv.conf..."
cp /etc/resolv.conf /etc/resolv.conf.bak
echo "
search $MYDOMAIN
nameserver $MYIP " > /etc/resolv.conf
echo "The /etc/resolv.conf changed successfully!"