DNS Verify -- IP to hostname to IP


The dns verify shell script will check hostnames to ips. This script is intended for a private network like a home LAN or internal corporate network.

The reason for this script was made is to make sure that you have the correct IP to hostname to IP resolution. If you have worked with BIND enough you may have made a mistake once or twice. You should have put the hostname in with one IP and you put another or you put an IP in one file but forgot to put it in the other. This script will show you those errors and you can quickly fix them.

Configure the script

There are two decisions you need to make before using this script.

What ranges of IP's are we monitoring? The variable "NETS" is a space separated list of all of the networks you want to monitor. In our example we are looking the 192.168.10 and 172.168.20 networks.

What sequence of IP's in $NETS are we checking? The variable "IPS" is either going to be a list of ips you want to check or if you have the binary "seq" install you can use the "$(seq 1 254)" function. The binary "seq" is short for sequence and it will count from the first number to the last in one step digits. This is nice if you want to go from 1 to 254 for example.

Here is the dns_verify.sh shell script.

#### dns_verify.sh
NETS="192.168.10 172.168.20"
IPS="1 2 3 4 5 6 7 8 9 10"
#Have seq? Replace $IPS with $(seq 1 254)
echo -e "\tip        ->     hostname      -> ip"
echo '--------------------------------------------------------'  
for NET in $NETS; do
  for n in $IPS; do
    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"
        echo -e "fail\t$A -> $HOST -> [unassigned]"

echo ""
echo "DONE."

HELPFUL HINT: If you need assistance with Bind then check out our Bind Authoritative Caching DNS Server (named.conf) Guide. You can setup a fast and secure caching DNS server for your network.

What does the output look like?

If we have 10 ips on the 192.168.10 network and 10 ips on the 172.168.20 network the output of the script will look like the following. Notice all of the lines say "ok"? If you see "ok" then everything is good. If you see "fail" then take a look at the output line and fix the BIND entry.

  user@machine: ./dns_verify.sh 

          ip        ->     hostname      -> ip
  ok -> host1.domain.lan. ->
  ok -> host2.domain.lan. ->
  ok -> host3.domain.lan. ->
  ok -> host4.domain.lan. ->
  ok -> dhca5.domain.lan. ->
  ok -> dhca6.domain.lan. ->
  ok -> dhca7.domain.lan. ->
  ok -> dhca8.domain.lan. ->
  ok -> dhca9.domain.lan. ->
  ok -> dhca10.domain.lan. ->
  ok -> host5.domain.lan. ->
  ok -> host6.domain.lan. ->
  ok -> host7.domain.lan. ->
  ok -> host8.domain.lan. ->
  ok -> dhcb5.domain.lan. ->
  ok -> dhcb6.domain.lan. ->
  ok -> dhcb7.domain.lan. ->
  ok -> dhcb8.domain.lan. ->
  ok -> dhcb9.domain.lan. ->
  ok -> dhcb10.domain.lan. ->



You mentioned this is used for internal use only. Why can't I use it on hosts on the Internet?

You can. The problem is this script does not limit the amount of dns calls it requests per second. If you run this on a host that is not your own it might look like an attack.

My ISP has given me a few ips, but they are not in order!

No problem. Edit the $IPS variable and enter just the ips you want to check. For example, what if we had the ips,, and We could setup the $NETS variable as NETS="10.0.0" and the ips as IPS="1 5 10".

Questions, comments, or suggestions? Contact Calomel.org