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.Here is the dns_verify.sh shell script.
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.
- To check if "seq" is on your machine do a "which seq" or run the line "seq 1 10" to count from 1 to 10. If you have "seq" then you can comment out the variable IPS and replace the line in the script "for n in $IPS; do" with "for n in $(seq 1 254); do".
- If you do not have "seq" and you dont want to build it then just use the variable $IPS. It is a space separated list of ips. This is what is used in the example below.
#### 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 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 "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 192.168.10.1 -> host1.domain.lan. -> 192.168.10.1 ok 192.168.10.2 -> host2.domain.lan. -> 192.168.10.2 ok 192.168.10.3 -> host3.domain.lan. -> 192.168.10.3 ok 192.168.10.4 -> host4.domain.lan. -> 192.168.10.4 ok 192.168.10.5 -> dhca5.domain.lan. -> 192.168.10.5 ok 192.168.10.6 -> dhca6.domain.lan. -> 192.168.10.6 ok 192.168.10.7 -> dhca7.domain.lan. -> 192.168.10.7 ok 192.168.10.8 -> dhca8.domain.lan. -> 192.168.10.8 ok 192.168.10.9 -> dhca9.domain.lan. -> 192.168.10.9 ok 192.168.10.10 -> dhca10.domain.lan. -> 192.168.10.10 ok 172.168.20.1 -> host5.domain.lan. -> 172.168.20.1 ok 172.168.20.2 -> host6.domain.lan. -> 172.168.20.2 ok 172.168.20.3 -> host7.domain.lan. -> 172.168.20.3 ok 172.168.20.4 -> host8.domain.lan. -> 172.168.20.4 ok 172.168.20.5 -> dhcb5.domain.lan. -> 172.168.20.5 ok 172.168.20.6 -> dhcb6.domain.lan. -> 172.168.20.6 ok 172.168.20.7 -> dhcb7.domain.lan. -> 172.168.20.7 ok 172.168.20.8 -> dhcb8.domain.lan. -> 172.168.20.8 ok 172.168.20.9 -> dhcb9.domain.lan. -> 172.168.20.9 ok 172.168.20.10 -> dhcb10.domain.lan. -> 172.168.20.10 DONE.
No comments:
Post a Comment