Basic dns verify shell script

Questions and answers about how to do stuff
Post Reply
henk
Posts: 171
Joined: 14 Dec 2015 22:16
Location: Netherlands
Contact:

Basic dns verify shell script

Post by henk » 28 Mar 2018 12:15

As DNS is essential for EFA, you can do a basic test to verify your DNS setup.
You can provide a space separated list of all of the (private)networks you want to check.

Original script from https://calomel.org/unbound_dns.html

Code: Select all

#### dns_verify.sh
#
DOMAIN="google.com"             # change domain to own domain
#NETS="172.16.1 xxx.xxx.xxx"    # multiple networks
NETS="172.16.1"
IPS=$(seq 1 254)  ## for Linux
#
echo
echo -e "\tip        ->     hostname      -> ip"
echo '--------------------------------------------------------'
for NET in $NETS; do
  for n in $IPS; do
    A=${NET}.${n}
    HOST=$(dig -x $A +short)
    if test -n "$HOST"; then
      ADDR=$(dig $HOST +short)
      if test "$A" = "$ADDR"; then
        echo -e "ok\t$A -> $HOST -> $ADDR"
      elif test -n "$ADDR"; then
        echo -e "fail\t$A -> $HOST -> $ADDR"
      else
        echo -e "fail\t$A -> $HOST -> [unassigned]"
      fi
    fi
  done
done

echo ""
echo "*** Check unbound config"
CMD=$(unbound-checkconf  /etc/unbound/unbound.conf)
echo "$CMD"

echo ""
echo "*** dig test.uribl.com.multi.uribl.com txt +short"
CMD=$(dig test.uribl.com.multi.uribl.com txt +short)
echo "$CMD"
echo ""

echo "*** dig 2.0.0.127.zen.spamhaus.org +short"
CMD=$(dig 2.0.0.127.zen.spamhaus.org +short)
echo "$CMD"
echo ""

echo "***Check domain unbound: $DOMAIN"
CMD=$(unbound-host -C /etc/unbound/unbound.conf -v "$DOMAIN")
echo "$CMD"
echo ""

echo "***Check domain dig: $DOMAIN"
CMD=$(dig "$DOMAIN" @127.0.0.1 +short)
echo "$CMD"
echo ""

echo "***check domain TXT: $DOMAIN"
CMD=$(host -tTXT "$DOMAIN")
echo "$CMD"
echo ""

echo "***Check domain MX nslookup: $DOMAIN"
CMD=$(nslookup -querytype=mx "$DOMAIN")
echo "$CMD"
echo ""

echo "***Check caching. Query time: 0 msec?"
CMD=$(for i in $(seq 1 5); do dig +noall +answer +stats A "$DOMAIN" | sed -n '1,2p'; done)
echo "$CMD"
echo ""

echo "***Check Unbound cache"
CMD=$(unbound-control stats_noreset |grep cache)
echo "$CMD"
echo ""
echo "DONE."

Post Reply