dig — утилита для обращения к системе DNS, позволяющая задавать разные типы запросов и запрашивать произвольные сервера.
Простой вывод команды показывает информацию по А-записи для домена, который мы указали:
nick@name:~$ dig bing.com ; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> bing.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1512 ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 65494 ;; QUESTION SECTION: ;bing.com. IN A ;; ANSWER SECTION: bing.com. 1979 IN A 13.107.21.200 bing.com. 1979 IN A 204.79.197.200 ;; Query time: 0 msec ;; SERVER: 127.0.0.53#53(127.0.0.53) ;; WHEN: Wed Aug 29 10:15:56 EEST 2018 ;; MSG SIZE rcvd: 69
В разделе ANSWER SECTION можно увидеть А-записи домена bing.com
Обычно требуется узнать только IP-адрес домена. Для этого существуют ключи:
+nocomments — отключает линию комментариев
+noauthority — отключает секцию «AUTHORITY SECTION»
+noadditional – отключает секцию «ADDITIONAL SECTION»
+nostats – отключает секцию статистики
+noanswer – выключает секцию ответа (ANSWER SECTION)
Пример:
nick@name:~$ dig bing.com +nocomments +noauthority +noadditional +nostats ; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> bing.com +nocomments +noauthority +noadditional +nostats ;; global options: +cmd ;bing.com. IN A bing.com. 795 IN A 13.107.21.200 bing.com. 795 IN A 204.79.197.200
Так же существует ключ +noall, который выключает все секции. Используем этот ключ с ключом +answer чтобы уменьшить длину команды:
nick@name:~$ dig bing.com +noall +answer ; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> bing.com +noall +answer ;; global options: +cmd bing.com. 569 IN A 13.107.21.200 bing.com. 569 IN A 204.79.197.200
Чтобы получить запись MX,выполним команду:
nick@name:~$ dig bing.com MX +noall +answer ; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> bing.com MX +noall +answer ;; global options: +cmd bing.com. 3600 IN MX 10 bing-com.mail.protection.outlook.com.
nick@name:~$ dig bing.com NS +noall +answer ; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> bing.com NS +noall +answer ;; global options: +cmd bing.com. 92150 IN NS ns4.msedge.net. bing.com. 92150 IN NS ns1.msedge.net. bing.com. 92150 IN NS ns2.msedge.net. bing.com. 92150 IN NS ns3.msedge.net.
nick@name:~$ dig -t NS bing.com +noall +answer ; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> -t NS bing.com +noall +answer ;; global options: +cmd bing.com. 6119 IN NS ns3.msedge.net. bing.com. 6119 IN NS ns2.msedge.net. bing.com. 6119 IN NS ns1.msedge.net. bing.com. 6119 IN NS ns4.msedge.net.
nick@name:~$ dig bing.com ANY +noall +answer ; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> bing.com ANY +noall +answer ;; global options: +cmd bing.com. 5 IN MX 10 bing-com.mail.protection.outlook.com. bing.com. 5 IN A 204.79.197.200 bing.com. 5 IN A 13.107.21.200 bing.com. 5 IN NS ns2.msedge.net. bing.com. 5 IN NS ns3.msedge.net. bing.com. 5 IN NS ns1.msedge.net. bing.com. 5 IN NS ns4.msedge.net.
nick@name:~$ dig bing.com ANY +short 10 bing-com.mail.protection.outlook.com. 204.79.197.200 13.107.21.200 ns4.msedge.net. ns1.msedge.net. ns2.msedge.net. ns3.msedge.net.
nick@name:~$ dig -x 204.79.197.200 +short a-0001.a-msedge.net.
nick@name:~$ nano domains.txt
bing.com
google.com
github.com
nick@name:~$ dig -f domains.txt +noall +answer bing.com. 1798 IN A 204.79.197.200 bing.com. 1798 IN A 13.107.21.200 google.com. 240 IN A 216.58.209.78 github.com. 10 IN A 192.30.253.113 github.com. 10 IN A 192.30.253.112
nick@name:~$ dig -f domains.txt MX +noall +answer bing.com. 1389 IN MX 10 bing-com.mail.protection.outlook.com. google.com. 483 IN MX 20 alt1.aspmx.l.google.com. google.com. 483 IN MX 30 alt2.aspmx.l.google.com. google.com. 483 IN MX 40 alt3.aspmx.l.google.com. google.com. 483 IN MX 50 alt4.aspmx.l.google.com. google.com. 483 IN MX 10 aspmx.l.google.com. github.com. 3600 IN MX 10 ALT3.ASPMX.L.GOOGLE.com. github.com. 3600 IN MX 10 ALT4.ASPMX.L.GOOGLE.com. github.com. 3600 IN MX 1 ASPMX.L.GOOGLE.com. github.com. 3600 IN MX 5 ALT1.ASPMX.L.GOOGLE.com. github.com. 3600 IN MX 5 ALT2.ASPMX.L.GOOGLE.com.
nick@name:~$ dig google.com MX +noall +answer bing.com NS +noall +answer github.com NS +noall +answer ; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> google.com MX +noall +answer bing.com NS +noall +answer github.com NS +noall +answer ;; global options: +cmd google.com. 352 IN MX 10 aspmx.l.google.com. google.com. 352 IN MX 50 alt4.aspmx.l.google.com. google.com. 352 IN MX 40 alt3.aspmx.l.google.com. google.com. 352 IN MX 30 alt2.aspmx.l.google.com. google.com. 352 IN MX 20 alt1.aspmx.l.google.com. bing.com. 89815 IN NS ns3.msedge.net. bing.com. 89815 IN NS ns2.msedge.net. bing.com. 89815 IN NS ns4.msedge.net. bing.com. 89815 IN NS ns1.msedge.net. github.com. 438 IN NS ns-1707.awsdns-21.co.uk. github.com. 438 IN NS ns4.p16.dynect.net. github.com. 438 IN NS ns-421.awsdns-52.com. github.com. 438 IN NS ns2.p16.dynect.net. github.com. 438 IN NS ns-1283.awsdns-32.org. github.com. 438 IN NS ns-520.awsdns-01.net. github.com. 438 IN NS ns1.p16.dynect.net. github.com. 438 IN NS ns3.p16.dynect.net.
Можно использовать команду и в bash скрипте, чтобы выводить например NS, A и MX записи:
#!/bin/bash IFS=$'\n' [ $# -eq 1 ] || { echo "usage: adig example.com" exit 1 } cname="www.$1" echo for i in $(dig ns $1 +short | sed -e 's/\.$//'); do echo "$i" for j in $(dig "$1" @"$i" +short); do echo "@ A $j" done www=$(dig "$cname" @"$i" +short | head -1) echo "www $www" for k in $(dig "$1" @"$i" MX +short); do echo "@ MX $k" done echo done
Вывод будет таким:
nick@worked:~$ ./dig.sh bing.com ns1.msedge.net @ A 204.79.197.200 @ A 13.107.21.200 www www-bing-com.a-0001.a-msedge.net. @ MX 10 bing-com.mail.protection.outlook.com. ns4.msedge.net @ A 204.79.197.200 @ A 13.107.21.200 www www-bing-com.a-0001.a-msedge.net. @ MX 10 bing-com.mail.protection.outlook.com. ns2.msedge.net @ A 204.79.197.200 @ A 13.107.21.200 www www-bing-com.a-0001.a-msedge.net. @ MX 10 bing-com.mail.protection.outlook.com. ns3.msedge.net @ A 204.79.197.200 @ A 13.107.21.200 www www-bing-com.a-0001.a-msedge.net. @ MX 10 bing-com.mail.protection.outlook.com.