#!/bin/sh # # Checks that a zonetransfer can't be made. # # Usage: check_noaxfr.sh [server] [domain] # # [server] is the name of the server to ask, i.e. "ns.xx.com" # [domain] is the name of the domain to ask for, i.e. "xx.com" # # (c) Rickard Dahlstrand, rd@tilde.se 20050901 # NOTE! Only tested with dig 9.3.x # ###################################################### # Paths ###################################################### DIG=/usr/bin/dig [ -x ${DIG} ] || DIG=`which dig` PID=/tmp/check_axfr.pid ###################################################### # Defaults ###################################################### critical() { echo $1 exit 2 } warning() { echo $1 exit 1 } ###################################################### # Check command line arguments ###################################################### if [ $# -gt 1 ] ; then SRV=$1 ZONE=$2 else ###################################################### # Help ###################################################### awk 'NR>1 && NR<13 {print $0}' $0 exit 3 fi ###################################################### # Check if PID file exists ###################################################### if [ -f ${PID} ] ; then echo "$0 already running - remove PID file ${PID}" exit 3 fi ###################################################### # Create new PID file ###################################################### echo $$ > ${PID} # Ask the server for the localhost record and collect the query time. x=`${DIG} @${SRV} AXFR ${ZONE} -4 +norec +ignore 2> /dev/null | grep "ransfer failed"` # Debugoutput #echo ${ZONE}@${SRV}: ${x} # If not successful issue a critical alert. if [ "${x}" = "" ] ; then rm -f ${PID} critical "CRITICAL - host down or zonetransfer allowed" fi rm -f ${PID} echo "OK - axfr not allowed" exit 0