Wednesday, February 17, 2016

DNS server configuration by shell scripting

******************************************************
Just copy the content and save it to dns.sh file. set permission like
******************************************************    
     # chmod 777 dns.sh
     #./dns.sh
*******************************************************



echo "write down the domain name"
read "l"

echo "write down the iP address blockwise"
echo "First Block:"
read "i1"
echo "Second Block"
read "i2"
echo "Third Block"
read "i3"
echo "Fourth Block"
read "i4"
echo "Write down Subnet Mask"
read "s"
sleep 1

echo "*****************************************************************"
echo "*     '$i1'.'$i2'.'$i3'.'$i4'                     *"
echo "*                   '$s'                                        *"
echo "* ***************************************************************"
echo ""
echo "" 
echo "write down the host name"

read "h"
echo ""
hostname $h
echo 'hostname'
hostname
hostname 
echo > /etc/resolv.conf '
search '$l'
nameserver '$i1'.'$i2'.'$i3'.'$i4''
echo > /etc/sysconfig/network-scripts/ifcfg-eth0 '
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR='$i1'.'$i2'.'$i3'.'$i4'
NETMASK='$S'
'


service network restart

echo > /etc/sysconfig/network '
NETWORKING=yes
HOSTNAME='$h''

#echo >> /etc/resolv.conf '
#nameserver '$i1'.'$i2'.'$i3'.'$i4''

echo > /etc/named.conf '

options {
 listen-on port 53 { 127.0.0.1; '$i1'.'$i2'.'$i3'.'$i4'; };
 listen-on-v6 port 53 { ::1; };
 directory  "/var/named";
 dump-file  "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
// allow-query     { localhost; };
 recursion yes;

 dnssec-enable yes;
 dnssec-validation yes;
 dnssec-lookaside auto;

 bindkeys-file "/etc/named.iscdlv.key";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "'$l'" IN {
 type master;
 file "'$l'.for";
 allow-update { none; };
};

zone "'$i3'.'$i2'.'$i1'.in-addr.arpa" IN {
 type master;
 file "'$l'.rev";
 allow-update { none; };
};
'

touch /var/named/$l.for

touch /var/named/$l.rev

echo "***************************************************************"

echo > /var/named/$l.for '
$TTL 1D
@    IN SOA '$h'.'$l'. root.'$l'. (
     0  ; serial)
     1D  ; refresh
     1H  ; retry
     1W  ; expiry
     3H )  ; minimum

         IN NS '$h'.'$l'.
'$h'  IN A '$i1'.'$i2'.'$i3'.'$i4'
www.'$l'. IN A '$i1'.'$i2'.'$i3'.'$i4''

sleep 1
echo "****************************************************************"

echo ""
echo ""

echo > /var/named/$l.rev '
$TTL 1D
@       IN      SOA     '$h'.'$l'. root.'$l'.  (
                                      0          ; Serial
                                      1D         ; Refresh
                                      1H         ; Retry
                                      1W         ; Expire
                                      3H  )      ; Minimum
              IN      NS      '$h'.'$l'.

'$i4'       IN      PTR     '$h'.'$l'. '
echo ""
killall named
echo ""
echo "*****************************************************************"
service named start
echo ""
echo ""
chown root.named /var/named/$l.for
chown root.named /var/named/$l.rev

echo "******************************************************************"
ping www.$l -c 4
echo "******************************************************************"
clear
 
echo ""
echo ""
echo "**************************************************************"
echo "*      DNS Server Configuration has been Completed           *"
echo "*      Please Check Your Configuration by nslookup command   *"
echo "**************************************************************"
echo ""

2 comments: