#!/bin/bash
#create a DNS server
yum install -y bind &> /dev/null
read -p "Please input your doamin name :" DOMAIN
read -p "Please input your 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`
cat > /etc/named.conf <<!
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 "name.local";
};
zone "$DOMAIN" IN {
type master;
file "${DOMAIN}.zone";
};
zone "$IP3.$IP2.$IP1.in-addr.arpa" IN {
type master;
file "$IP1.$IP2.$IP3.zone";
};
!
cat > /var/named/localhost.zone <<EOF
$TTL 86400
@ IN SOA ns1.$DOMAIN.org. admin.$DOMAIN.org. (
2011053101
30M
5M
1W
1D )
IN NS localhost.
localhost. IN A 127.0.0.1
EOF
cat > /var/named/name.local <<EOF
$TTL 86400
@ IN SOA ns1.a.org. admin.a.org. (
2011052901
30M
5M
1W
1D )
IN NS localhost.
1 IN PTR localhost.
EOF
cat > /var/named/named.ca <<EOF
; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5 <<>> -t NS .
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13386
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 15
;; QUESTION SECTION:
;. IN NS
;; ANSWER SECTION:
. 79991 IN NS j.root-servers.net.
. 79991 IN NS f.root-servers.net.
. 79991 IN NS e.root-servers.net.
. 79991 IN NS c.root-servers.net.
. 79991 IN NS a.root-servers.net.
. 79991 IN NS l.root-servers.net.
. 79991 IN NS k.root-servers.net.
. 79991 IN NS g.root-servers.net.
. 79991 IN NS i.root-servers.net.
. 79991 IN NS d.root-servers.net.
. 79991 IN NS m.root-servers.net.
. 79991 IN NS h.root-servers.net.
. 79991 IN NS b.root-servers.net.
;; ADDITIONAL SECTION:
a.root-servers.net. 339055 IN A 198.41.0.4
b.root-servers.net. 359473 IN A 192.228.79.201
c.root-servers.net. 359374 IN A 192.33.4.12
d.root-servers.net. 351807 IN A 128.8.10.90
e.root-servers.net. 344312 IN A 192.203.230.10
f.root-servers.net. 359369 IN A 192.5.5.241
g.root-servers.net. 341419 IN A 192.112.36.4
h.root-servers.net. 344665 IN A 128.63.2.53
i.root-servers.net. 351493 IN A 192.36.148.17
i.root-servers.net. 416510 IN AAAA 2001:7fe::53
j.root-servers.net. 341358 IN A 192.58.128.30
j.root-servers.net. 577954 IN AAAA 2001:503:c27::2:30
k.root-servers.net. 344634 IN A 193.0.14.129
l.root-servers.net. 344544 IN A 199.7.83.42
l.root-servers.net. 365933 IN AAAA 2001:500:3::42
;; Query time: 39 msec
;; SERVER: 202.102.224.68#53(202.102.224.68)
;; WHEN: Sun May 29 18:24:19 2011
;; MSG SIZE rcvd: 504
EOF
cat > /var/named/${DOMAIN}.zone <<!
\$TTL 86400
\$ORIGIN ${DOMAIN}.
@ IN SOA $DOMAIN admin.$DOMAIN. (
2011053101
10M
5M
7D
1D )
IN NS ns
IN MX 10 mail
ns IN A $IP
www IN A $IP
mail IN A $IP
!
cat > /var/named/$IP1.$IP2.$IP3.zone << EOF
\$TTL 86400
@ IN SOA $DOMAIN admin.$DOMAIN. (
2011053101
10M
5M
7D
1D )
IN NS ns
$IP4 IN PTR mail.$DOMAIN.
$IP4 IN PTR www.$DOMAIN.
EOF
chown named:named /var/named/* /etc/named.conf
service named configtest
service named start