Print View

How to check for forward and reverse DNS in a shell script

Issue

In a number of situations, such as kerberos operations, forward and reverse DNS is required for operations to complete successfully. This can be determined from within the shell script.

Resolution

DNS_FORWARD=$(dig $(hostname) +short)
DNS_REVERSE=$(dig -x $(ifconfig eth0 | grep "inet addr" | cut -f2 -d: | cut -f1 -d " ") +short)

if [ -z $DNS_FORWARD ] || [ -z $DNS_REVERSE ]
then
        echo
	echo "ERROR: Forward and reverse DNS must be configured"
	echo "	Forward DNS: $DNS_FORWARD"
	echo "	Reverse DNS: $DNS_REVERSE"
	echo
        exit 1
fi

Products

Ubuntu Desktop 9.10 (Karmic Koala)
Ubuntu Desktop 9.04 (Jaunty Jackalope)
Ubuntu Desktop 8.10 (Intrepid Ibex)
Ubuntu Desktop 8.04 (Hardy Heron)
Ubuntu Desktop 7.10 (Gutsy Gibbon)
Ubuntu Desktop 7.04 (Feisty Fawn)
Ubuntu Desktop 10.04 (Lucid Lynx)
Red Hat Enterprise Linux 4
Debian GNU/Linux 6.0.1 (Squeeze)
Debian GNU/Linux 5.02 (lenny)

Created: 28th September 2011
Updated: 28th September 2011

Print View

© 2005-2024 Jamie Morrison