This is Shell script i created which Collects the IPaddress details from the WAN routers using SNMP and creates the reverse DNS file for the same. Some times the reverse DNS of the links will be very helful for identifying and troubleshooting the link issue, without looking at your database.
Create a file called device_list in /var/named folder. Enter the device detail hostname or IP address from where you need to retrive the IP address details.
eg:
core1.pop1
core2.pop1
( or )
10.1.1.1
10.2.1.1
update the grep commands to include the links which you want reverse_dns
=================================================
#!/bin/bash
#This is a script to generate reverse DNS file for core links
DEVICELIST=/var/named/device_list
ALIASFILE=/tmp/ifalias
ADDRESSFILE=/tmp/ipaddress
REVERSEDNS=/tmp/reverse_dns
COREDNSFILE=core-reverse.inc
TMPCOREDNS=/tmp/$COREDNSFILE
BINDBASE=/var/named/inc-reverse
POPFILE=$BINDBASE/reversedns
##Empty the files
echo > $ALIASFILE
echo > $ADDRESSFILE
echo > $REVERSEDNS
echo > $TMPCOREDNS
for DEVICE in `cut -d " " -f 1 $POPLIST`
do echo "$DEVICE"
snmpwalk -v2c -c a0xCOWTF^@gXhgphcxMX! $DEVICE ifAlia | egrep 'pl2'| grep -v trunk | sed 's/-/ /g' | sed 's/::ifAlias./ /g' | sed 's/_/ /g' | cut -d ' ' -f 3,6,7,8,9,10 > $ALIASFILE 2>/dev/null
sed -i 's/[^ ]*/'$DEVICE'/6' $ALIASFILE
snmpwalk -v2c -c a0xCOWTF^@gXhgphcxMX! $DEVICE ipAdEntIfIndex | sed 's/-/ /g' | sed 's/::ipAdEntIfIndex./ /g' | sed 's/_/ /g' | cut -d ' ' -f 3,6 > $ADDRESSFILE 2>/dev/null
awk 'NR==FNR {a[$2]=$1;next} {$1=a[$1];print}' $ADDRESSFILE $ALIASFILE | sed 's/\./_/g' | sed 's/ /_/g' >> $REVERSEDNS
done
done
sed -i '/^$/d' $REVERSEDNS
awk -F '_' '{print $4"\."$3"\t""\t""IN""\t""PTR""\t"$5"-"$6"-"$7"-"$8"-"$9"-"$10"\."$11}' $REVERSEDNS > $TMPCOREDNS
#Move the files to bind base
mv $COREDNS $BINDBASE
chown root:named ${POPFILE}
chmod 640 ${POPFILE}
P.S: Use http://ipsubnetcalculator.net/ for calculating IP subnet mask Online
Create a file called device_list in /var/named folder. Enter the device detail hostname or IP address from where you need to retrive the IP address details.
eg:
core1.pop1
core2.pop1
( or )
10.1.1.1
10.2.1.1
update the grep commands to include the links which you want reverse_dns
=================================================
#!/bin/bash
#This is a script to generate reverse DNS file for core links
DEVICELIST=/var/named/device_list
ALIASFILE=/tmp/ifalias
ADDRESSFILE=/tmp/ipaddress
REVERSEDNS=/tmp/reverse_dns
COREDNSFILE=core-reverse.inc
TMPCOREDNS=/tmp/$COREDNSFILE
BINDBASE=/var/named/inc-reverse
POPFILE=$BINDBASE/reversedns
##Empty the files
echo > $ALIASFILE
echo > $ADDRESSFILE
echo > $REVERSEDNS
echo > $TMPCOREDNS
for DEVICE in `cut -d " " -f 1 $POPLIST`
do echo "$DEVICE"
snmpwalk -v2c -c a0xCOWTF^@gXhgphcxMX! $DEVICE ifAlia | egrep 'pl2'| grep -v trunk | sed 's/-/ /g' | sed 's/::ifAlias./ /g' | sed 's/_/ /g' | cut -d ' ' -f 3,6,7,8,9,10 > $ALIASFILE 2>/dev/null
sed -i 's/[^ ]*/'$DEVICE'/6' $ALIASFILE
snmpwalk -v2c -c a0xCOWTF^@gXhgphcxMX! $DEVICE ipAdEntIfIndex | sed 's/-/ /g' | sed 's/::ipAdEntIfIndex./ /g' | sed 's/_/ /g' | cut -d ' ' -f 3,6 > $ADDRESSFILE 2>/dev/null
awk 'NR==FNR {a[$2]=$1;next} {$1=a[$1];print}' $ADDRESSFILE $ALIASFILE | sed 's/\./_/g' | sed 's/ /_/g' >> $REVERSEDNS
done
done
sed -i '/^$/d' $REVERSEDNS
awk -F '_' '{print $4"\."$3"\t""\t""IN""\t""PTR""\t"$5"-"$6"-"$7"-"$8"-"$9"-"$10"\."$11}' $REVERSEDNS > $TMPCOREDNS
#Move the files to bind base
mv $COREDNS $BINDBASE
chown root:named ${POPFILE}
chmod 640 ${POPFILE}
P.S: Use http://ipsubnetcalculator.net/ for calculating IP subnet mask Online
No comments:
Post a Comment