FreeBSD

Проверка DNS: ip-hostname-ip

С помощью данного скрипта можно проверить работу dns сервера, а именно правильно ли резолвится ip адрес в имя и обратно. Скрипт будет полезен при настройке dns сервера небольшой корпоративной сети.

Конфигурация скрипта:

Блок который будем проверять задаётся переменной “NETS“. Для примера 2 сети 192.168.20 и 192.168.21.
Переменная “IPS” отвечает за OS в которой будет работать скрипт (Linux|xBSD)
Сам скрипт dns_check.sh

#### dns_check.sh
#
NETS="192.168.20 192.168.21"
#IPS=$(seq 1 10)  ## for Linux
#
 IPS=$(jot 254 1)  ## for OpenBSD or FreeBSD
# 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 "okt$A -> $HOST -> $ADDR"
      elif test -n "$ADDR"; then
        echo -e "failt$A -> $HOST -> $ADDR"
      else
        echo -e "failt$A -> $HOST -> [unassigned]"
      fi
    fi
  done
done

echo ""
echo "DONE."

Запускаем скрипт

# ./dns_check.sh
          ip        ->     hostname      -> ip
  --------------------------------------------------------
  ok      192.168.20.1 -> host1.domain.lan. -> 192.168.20.1
  ok      192.168.20.2 -> host2.domain.lan. -> 192.168.20.2
  ok      192.168.20.3 -> host3.domain.lan. -> 192.168.20.3
  ok      192.168.20.4 -> host4.domain.lan. -> 192.168.20.4
  ok      192.168.20.5 -> dhca5.domain.lan. -> 192.168.20.5
  ok      192.168.20.6 -> dhca6.domain.lan. -> 192.168.20.6
  ok      192.168.20.7 -> dhca7.domain.lan. -> 192.168.20.7
  ok      192.168.20.8 -> dhca8.domain.lan. -> 192.168.20.8
  ok      192.168.20.9 -> dhca9.domain.lan. -> 192.168.20.9
  ok      192.168.20.10 -> dhca10.domain.lan. -> 192.168.20.10
  ok      192.168.21.1 -> host5.domain.lan. -> 192.168.21.1
  ok      192.168.21.2 -> host6.domain.lan. -> 192.168.21.2
  ok      192.168.21.3 -> host7.domain.lan. -> 192.168.21.3
  ok      192.168.21.4 -> host8.domain.lan. -> 192.168.21.4
  ok      192.168.21.5 -> dhcb5.domain.lan. -> 192.168.21.5
  ok      192.168.21.6 -> dhcb6.domain.lan. -> 192.168.21.6
  ok      192.168.21.7 -> dhcb7.domain.lan. -> 192.168.21.7
  ok      192.168.21.8 -> dhcb8.domain.lan. -> 192.168.21.8
  ok      192.168.21.9 -> dhcb9.domain.lan. -> 192.168.21.9
  ok      192.168.21.10 -> dhcb10.domain.lan. -> 192.168.21.10

  DONE.

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Subscribe
Notify of
guest
2 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments