Thursday, 9 October 2014

script what will configure a local DNS for you.

script what will configure a local DNS for you. In Debian/Ubuntu machin. 

writer: Anuj Borah
Email: Anujborah1@gmail.com


#!/bin/bash
clear
echo "**************This is a script that will make a local DNS with any domain name*************"
if [ $UID -eq 0 ]
then
echo "***********I gonna check whether bind is installed on your system or not ??************"
dpkg -l bind9 >/dev/null
if [ $? -eq 0 ]
then
echo "************OK. Everything fine . We will go further************"
 rm /etc/hosts /dev/null
read -p  "What ip address you would like to have for your DNS...." a
read -p  "What host name you would like to have for your system...." q
read -p  "What will be the website name [ex----example.com]...." e
echo "127.0.0.1    localhost
127.0.0.2    $q
192.0.2.1    $q.$e" >> /etc/hosts > /dev/null
echo "Configuring main file ...."
mkdir -p /etc/bind/zones/db.$e > /dev/null
echo "zone "$e" {
    type master;
    file "/etc/bind/zones/db.$e";
};" >> /etc/bind/named.local.conf >> /dev/null
sleep 2
echo "creating Forward zone..."
echo "'$TTL'    604800
@       IN      SOA     ns1.$e. admin.example.com. (
                              5         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;

; Name servers
$e.    IN      NS      $q.$e.


; A records for name servers
$q             IN      A       $a


; Other A records
@               IN      A       $e
www             IN      A       $e" >> /etc/bind/zones/db.$e > /dev/null
sleep 2
echo "Doing Final config ...."
rm /etc/resolve.conf > /dev/null
echo "nameserver 127.0.0.1" >> /etc/resolve.conf > /dev/null
clear

echo -e "***********ALL DONE************"

else
echo "************Sorry no bind installed************ " ; read -p "Press "Enter" to install bind"; apt-get install bind >/tmp/1 2>&1
fi
else
clear
echo "************Sorry login as ROOT and try again  $0************"
fi

No comments:

Post a Comment

Popular Posts