Bash Ping Test for Domain Controllers

DNS can be a funny and unpredictable beast.

It is paramount that the DNS environment be stable and standardized in large environments, as well as small.  But in large environments particularly, you run into some weird happenings…  Like for instance, where an Active Directory exists separately from the DNS environment, the DNS world can sometimes get out of sync without all the AD controls.

So if you have an environment where you cannot be certain that all the “A” records for your parent domain are properly registered and represented, you might want to regularly check up on the domain’s records with a script.  I’ve tossed together a fairly simple script that prompts you for the parent domain name, an IP address of a reliable DNS server, and then it goes out and makes sure that all the hosts listed as “A” records for the parent domain are actually *up* and responding to ping…

Just copy/paste the following into a file, and chmod +x the file, and then run it.  Enjoy!

#!/bin/bash

echo "What is the domain name to check? (like example.com): "
read DOMNAME
echo ""
echo "What is an authoritative DNS server for that domain? (like 10.1.2.3): "
read AUTHDNS

for item in `nslookup $DOMNAME - $AUTHDNS| grep "Address:"| awk '{ print $2 }'|grep -v "#53"`; do echo "Checking $item... ";ping -q -c 2 $item > /tmp/lastitem.txt; temp="$?";if [ "$temp" == "1" ]; then echo $item is unreachable;fi; done

echo "...Done!"

I hope that helps someone out there…
🙂

Leave a Comment

Your email address will not be published. Required fields are marked *