DNS Check Zones Script

At the Circus there are a number of people that have access to the DNS servers and not everyone understands the full extent of the damage they can do when they make improper changes to the configuration or zone files.  One time we had a serious outage because there was an error in a zone file and DNS was returning non-authoritative answers for our zones.  As a result I wrote this check_zones script to check all of the zones and email me with the results each night.

#!/bin/bash
# 2007-02-14  Jud Bishop
# This script parses the /etc/named.conf file and checks
# every zone listed in it.
# Released under the GPL v2.

echo " ">/tmp/check_zone
echo "This is the list of bad zones.">>/tmp/check_zone

cat /etc/named.conf |egrep -w "zone|file" |cut -d \" -f 2 |sed '1~2 {N;s/\n/ /g}' |egrep -v "root|skip" |while read ZONE FILE
do
#echo "zone $ZONE file $FILE"
/usr/local/sbin/named-checkzone -k ignore $ZONE /var/named/$FILE
if [ $? -ne 0 ]
then
echo "$ZONE BAD" >>/tmp/check_zone 2>&1
fi
done

echo "If there are no zones listed as BAD then there are no problems.">>/tmp/check_zone

<code>cat /tmp/check_zone |mail -s "Zone Check" judson.bishop@circus.org
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s