Last active
August 29, 2015 14:07
-
-
Save Programie/fbe05c7a4db482c37a10 to your computer and use it in GitHub Desktop.
Simple DNS check script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/sh | |
| # Simple DNS check script | |
| # | |
| # Use it to test forward and reverse DNS entries for the given IP address. | |
| # It requires the dnsutils package which contains the dig command. | |
| IP="$1" | |
| if [ -z "$IP" ]; then | |
| echo "Usage: $0 {ip-address}" | |
| echo "" | |
| echo "Example: $0 192.168.1.42" | |
| exit 1 | |
| fi | |
| IP2DOMAIN=$(dig +short -x $IP) | |
| if [ -z "$IP2DOMAIN" ]; then | |
| echo "Missing reverse zone entry" | |
| exit 1 | |
| fi | |
| DOMAIN2IP=$(dig +short $IP2DOMAIN) | |
| if [ -z "$DOMAIN2IP" ]; then | |
| echo "Missing forward zone entry ($IP2DOMAIN)" | |
| exit 1 | |
| fi | |
| if [ "$IP" != "$DOMAIN2IP" ]; then | |
| echo "Mismatching forward zone entries for $IP2DOMAIN: $IP vs $DOMAIN2IP" | |
| exit 1 | |
| fi | |
| echo "OK" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment