newnameserver 2.34 KB
Newer Older
Nico Schottelius's avatar
init  
Nico Schottelius committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
#!/bin/bash
# Author: Nico Schottelius ( nicos@pcsystems.de )
# Last Modified by: 
# Date: 20th of January 2000
# Last Changed: 20th of January
# Description: Skript which does mapping and reverse
# 

# My variables :-)
host=""
ip=""
choice="y"
class=""
domain="mignet.magrathea.de"


# Title
echo "## Neuer Nameserver-Eintrag ##"
read -p "Bitte Domain eingeben ($domain) : " domain

# Check if zero domain
if [ -z "$domain" ]; then domain="mignet.magrathea.de";fi

# Main loop for more than one host in a domain
while [ "$choice" = "y" -o "$choice" = "Y" ] 
do 

read -p "Hostname tippen: " host
read -p "IP klopfen: " ip
read -p "NetClass eingeben: (a,b,c): " class

echo -n "Uno momento..."


# The real program

# First mapping
if [ -e /var/named/$domain ]; 
  then 
  echo "$host		IN	A		$ip" >> /var/named/$domain
else
  cat << EOF >> /etc/named.conf
  
zone "$domain"  in {
	type master;
	file "$domain";
};
EOF
  cat /var/named/sample/domain > /var/named/$domain
  echo "$host		IN	A		$ip" >> /var/named/$domain
fi
echo -n "."

# Lookup the host and net id, to choose the right arpa file
# For A it is net=172 host=16.1.1
if [ $class = a -o $class = A ];
 then 
  # Get the arpa file
  net=`echo $ip | cut -d. -f1`
  
  # Get the hostid.
  ho=`echo $ip |cut -d. -f2-4`

  # The reverse Net
  rnet=$net

# For B it is net=172.16 host=1.1
elif [ $class = b -o $class = B ];
 then
  # Get the arpa file
  net=`echo $ip | cut -d. -f1-2`
  
  # Get the hostid.
  ho=`echo $ip | cut -d. -f3-4`

  # The reverse Net
  rnet1=`echo $ip | cut -d. -f1`
  rnet2=`echo $ip | cut -d. -f2`
  rnet="$rnet2.$rnet1"
  
# For C it is net=172.16.1 host=1
elif [ $class = c -o $class = C ];
 then
  # Get the arpa file
  net=`echo $ip | cut -d. -f1-3`
  
  # Get the hostid.
  ho=`echo $ip | cut -d. -f4`
  
  # The reverse Net
  rnet1=`echo $ip | cut -d. -f1`
  rnet2=`echo $ip | cut -d. -f2`
  rnet3=`echo $ip | cut -d. -f3`
  rnet="$rnet3.$rnet2.$rnet1"
fi

echo -n "."

if [ -e /var/named/reverse/$net ];
  then 
  echo "$ho		IN	PTR	$host.$domain." >> /var/named/reverse/$net
  
else
  cat << EOF >> /etc/named.conf
  
zone "${rnet}.in-addr.arpa" in {
	type master;
	file "reverse/$net";
};
EOF

  cat /var/named/sample/reverse > /var/named/reverse/$net
  echo "$ho		IN	PTR	$host.$domain." >> /var/named/reverse/$net
fi
echo -n "."
echo 'Finito :-)'
read -p "Noch einen Host in $domain eintragen ? " choice
done