Линукс dig командата за диагностика на мрежа 

29.09.2020 159 0

Линукс диг командата (dig command) е софтуер с команден интерфейс като Хост командата (host command), който сигурно вече имате. Тук ще ви покажем как да го използвате на своя компютър с Линукс. Версии на Диг командата има също за Windows и macOS.

Какво е командата диг?

DIG (Domain Information Groper) е широко използвана за DNS диагностика. Може да проверявате за проблеми по пътя на DNS заявките. Ние ще ползваме командата на Линукс компютър (Ubuntu-based Linux Mint 19.1), но вие може да я намерите и на macOS или Windows с малки разлики във функциите.

Линукс диг команда – инсталация

Ако използвате популярна версия на Линукс, сигурно вече я имате инсталирана. Отворете Терминала (Terminal) и напишете dig -v. Ако е инсталирана, ще видите съобщение, подобно на това:

DiG 9.11.3-1ubuntu1.7-Ubuntu.

Ако командата не е инсталирана, ще видите:

dig command not found

За Ubuntu-based Линукс дистрибуции (Ubuntu, Mint, и др.) може да я инсталирате със следния код в Терминала:

sudo apt install dnsutils

За CentOS или Fedora:

sudo yum install bind-utils

За Arch Linux компютри:

sudo pacman -S bind-tools

Диг команда, обяснение

За нашите примери ще използваме Yahoo.com. Вие може да използвате вашия домейн или друг. Просто трябва да подмените yahoo.com от примерите.

linux@linux:~$ dig yahoo.com

; <<>> DiG 9.11.3-1ubuntu1.13-Ubuntu <<>> yahoo.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7223
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;yahoo.com.			IN	A

;; ANSWER SECTION:
yahoo.com.		338	IN	A	98.137.11.164
yahoo.com.		338	IN	A	74.6.143.25
yahoo.com.		338	IN	A	74.6.143.26
yahoo.com.		338	IN	A	74.6.231.20
yahoo.com.		338	IN	A	74.6.231.21
yahoo.com.		338	IN	A	98.137.11.163

;; Query time: 37 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Tue Sep 29 09:39:24 EEST 2020
;; MSG SIZE  rcvd: 134

Първо излиза версията на командата и глобалните опции.
DNS сървърът има хедър, където се изписва “NOERROR”, ако заявката е успешна.

Следва отговорът на EDNS.
По подразбиране ще покаже A запис. А записът показва IP адреса за домейна, който проверявате.

Примери на Диг командата

linux@linux:~$ dig yahoo.com +short
98.137.11.163
74.6.231.21
74.6.231.20
74.6.143.26
74.6.143.25
98.137.11.164

Само IP адреса без допълнителен текст.

linux@linux:~$ dig yahoo.com MX

; <<>> DiG 9.11.3-1ubuntu1.13-Ubuntu <<>> yahoo.com MX
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 255
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;yahoo.com.			IN	MX

;; ANSWER SECTION:
yahoo.com.		838	IN	MX	1 mta6.am0.yahoodns.net.
yahoo.com.		838	IN	MX	1 mta7.am0.yahoodns.net.
yahoo.com.		838	IN	MX	1 mta5.am0.yahoodns.net.

;; Query time: 2 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Tue Sep 29 09:41:56 EEST 2020
;; MSG SIZE  rcvd: 117

Запитване за MX запис ще ви даде информация за incoming mail сървърите на хоста.

linux@linux:~$ dig yahoo.com SOA

; <<>> DiG 9.11.3-1ubuntu1.13-Ubuntu <<>> yahoo.com SOA
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33033
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;yahoo.com.			IN	SOA

;; ANSWER SECTION:
yahoo.com.		1800	IN	SOA	ns1.yahoo.com. hostmaster.yahoo-inc.com. 2020092905 3600 300 1814400 600

;; Query time: 4 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Tue Sep 29 09:42:32 EEST 2020
;; MSG SIZE  rcvd: 99

Виж SOA запис – начало на авторитета.

linux@linux:~$ dig yahoo.com TTL

; <<>> DiG 9.11.3-1ubuntu1.13-Ubuntu <<>> yahoo.com TTL
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63155
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;yahoo.com.			IN	A

;; ANSWER SECTION:
yahoo.com.		127	IN	A	98.137.11.163
yahoo.com.		127	IN	A	74.6.231.21
yahoo.com.		127	IN	A	74.6.231.20
yahoo.com.		127	IN	A	74.6.143.26
yahoo.com.		127	IN	A	74.6.143.25
yahoo.com.		127	IN	A	98.137.11.164

;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Tue Sep 29 09:42:54 EEST 2020
;; MSG SIZE  rcvd: 134

;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 15728
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;TTL.				IN	A

;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Tue Sep 29 09:42:54 EEST 2020
;; MSG SIZE  rcvd: 32

TTL – time to live. Показва времето, което информацията трябва да бъде пазена.

linux@linux:~$ dig yahoo.com +nocomments +noquestion +noauthority +noadditional +nostats

; <<>> DiG 9.11.3-1ubuntu1.13-Ubuntu <<>> yahoo.com +nocomments +noquestion +noauthority +noadditional +nostats
;; global options: +cmd
yahoo.com.		1587	IN	A	74.6.231.20
yahoo.com.		1587	IN	A	74.6.231.21
yahoo.com.		1587	IN	A	98.137.11.163
yahoo.com.		1587	IN	A	98.137.11.164
yahoo.com.		1587	IN	A	74.6.143.25
yahoo.com.		1587	IN	A	74.6.143.26

Само да отговори заявката. Без допълнителна информация.

linux@linux:~$ dig yahoo.com ANY +noall +answer

; <<>> DiG 9.11.3-1ubuntu1.13-Ubuntu <<>> yahoo.com ANY +noall +answer
;; global options: +cmd
yahoo.com.		1408	IN	SOA	ns1.yahoo.com. hostmaster.yahoo-inc.com. 2020092905 3600 300 1814400 600
yahoo.com.		411	IN	MX	1 mta5.am0.yahoodns.net.
yahoo.com.		411	IN	MX	1 mta6.am0.yahoodns.net.
yahoo.com.		411	IN	MX	1 mta7.am0.yahoodns.net.
yahoo.com.		1559	IN	A	98.137.11.164
yahoo.com.		1559	IN	A	74.6.143.25
yahoo.com.		1559	IN	A	74.6.143.26
yahoo.com.		1559	IN	A	74.6.231.20
yahoo.com.		1559	IN	A	74.6.231.21
yahoo.com.		1559	IN	A	98.137.11.163
yahoo.com.		134719	IN	NS	ns4.yahoo.com.
yahoo.com.		134719	IN	NS	ns5.yahoo.com.
yahoo.com.		134719	IN	NS	ns1.yahoo.com.
yahoo.com.		134719	IN	NS	ns2.yahoo.com.
yahoo.com.		134719	IN	NS	ns3.yahoo.com.

Тази команда ще покаже всички DNS записи.

linux@linux:~$ dig -x 98.137.246.7

; <<>> DiG 9.11.3-1ubuntu1.13-Ubuntu <<>> -x 98.137.246.7
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 65179
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;7.246.137.98.in-addr.arpa.	IN	PTR

;; ANSWER SECTION:
7.246.137.98.in-addr.arpa. 1800	IN	PTR	media-router-fp71.prod.media.vip.gq1.yahoo.com.

;; Query time: 4 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Tue Sep 29 09:49:28 EEST 2020
;; MSG SIZE  rcvd: 114

Обратна заявка. Сложете IP адреса и отговорът ще бъде домейна. Ще видите PTR запис.

linux@linux:~$ dig @8.8.8.8 +trace www.yahoo.com

; <<>> DiG 9.11.3-1ubuntu1.13-Ubuntu <<>> @8.8.8.8 +trace www.yahoo.com
; (1 server found)
;; global options: +cmd
.			86774	IN	NS	a.root-servers.net.
.			86774	IN	NS	b.root-servers.net.
.			86774	IN	NS	c.root-servers.net.
.			86774	IN	NS	d.root-servers.net.
.			86774	IN	NS	e.root-servers.net.
.			86774	IN	NS	f.root-servers.net.
.			86774	IN	NS	g.root-servers.net.
.			86774	IN	NS	h.root-servers.net.
.			86774	IN	NS	i.root-servers.net.
.			86774	IN	NS	j.root-servers.net.
.			86774	IN	NS	k.root-servers.net.
.			86774	IN	NS	l.root-servers.net.
.			86774	IN	NS	m.root-servers.net.
.			86774	IN	RRSIG	NS 8 0 518400 20201011050000 20200928040000 46594 . YkK2UhiFUBjIOJvnaSJfCg479QYmSLsVw8RQYyObr+OLRllPi2abjBBp MRF0yimscdyWj6ghcwzXWK9VOM2l+pj+faiJLQQCUt0wxRpiCO3ngzKU t9f2NM1qkftlRzDKTJ1zZfZOLg03W10NogUtIdtBa6yWorlcwXBdfZ13 QAcGg19KfrOIARvPGuMtT7T8jfS1/jokOhhQQFUJaEoqTXvo459Ifptj vQL14B/XUCn9BKdOqxt1DHGDfmOrxDpZf7T3ixyGaXDkMv5k9S0Mag4J notAAu4nDNS4zQBZ146sdurFN4QQaYH1WXuZFOPZKNxc1v8XrpZQXxDm 19Fr/w==
;; Received 525 bytes from 8.8.8.8#53(8.8.8.8) in 2 ms

com.			172800	IN	NS	a.gtld-servers.net.
com.			172800	IN	NS	b.gtld-servers.net.
com.			172800	IN	NS	c.gtld-servers.net.
com.			172800	IN	NS	d.gtld-servers.net.
com.			172800	IN	NS	e.gtld-servers.net.
com.			172800	IN	NS	f.gtld-servers.net.
com.			172800	IN	NS	g.gtld-servers.net.
com.			172800	IN	NS	h.gtld-servers.net.
com.			172800	IN	NS	i.gtld-servers.net.
com.			172800	IN	NS	j.gtld-servers.net.
com.			172800	IN	NS	k.gtld-servers.net.
com.			172800	IN	NS	l.gtld-servers.net.
com.			172800	IN	NS	m.gtld-servers.net.
com.			86400	IN	DS	30909 8 2 E2D3C916F6DEEAC73294E8268FB5885044A833FC5459588F4A9184CF C41A5766
com.			86400	IN	RRSIG	DS 8 1 86400 20201012050000 20200929040000 46594 . GrgcYv58jJp7sNnXE8BzCdk4pHWXhaxzK5+JpunnHyVouWGT2+r73KWQ +UDwPVkBgKMG4npsgThrKC44K3zaCV6c/ohcsJeKs+lLiX1aOdntVXDf h9eMI4bR9xQzo4FXt9y/uSdn0h6lo+w15dP/Q1B7JUkYPTAC6KWMvKsy q1Jlt5Vn+AvnEyos4np0AODZfIT5hun7n03DGXgN4PqHw6OixMVluC/Z RJuDraguGokxicjbxlwk7/D7mcvZp+nCp5AaXnALHmSaHl09GVWkkuri pad6Eyq2mDa9YBYGo3tg5r3AKuVLbJnoV2a4tfe6NoeZbUKD92Qpogzg GNF62A==
;; Received 1173 bytes from 198.97.190.53#53(h.root-servers.net) in 36 ms

yahoo.com.		172800	IN	NS	ns1.yahoo.com.
yahoo.com.		172800	IN	NS	ns5.yahoo.com.
yahoo.com.		172800	IN	NS	ns2.yahoo.com.
yahoo.com.		172800	IN	NS	ns3.yahoo.com.
yahoo.com.		172800	IN	NS	ns4.yahoo.com.
CK0POJMG874LJREF7EFN8430QVIT8BSM.com. 86400 IN NSEC3 1 1 0 - CK0Q1GIN43N1ARRC9OSM6QPQR81H5M9A  NS SOA RRSIG DNSKEY NSEC3PARAM
CK0POJMG874LJREF7EFN8430QVIT8BSM.com. 86400 IN RRSIG NSEC3 8 2 86400 20201004044123 20200927033123 24966 com. mfMj0mWhB7y6rOePA3ZB43jj8Qi/8U8+mHOaQtTMs/Dko4vx3RgNQpc1 qLCNOdgVS2iz/M+OXWwUPxl2pZIDjWM0V+12tVFHJRNvlZEihsTD6J+m IwRaFqx7t98vQHls5R02Rl+7zq2RenAEdFiFno249WDp6LBb51i+tC50 dymKNGwudjNZ8k/o/1c7nnVBjMMY9MbIxO48LI57CpmJuw==
GPIOQL0L7VJL2SB4CTA1LU5TC263MU96.com. 86400 IN NSEC3 1 1 0 - GPIOVE5CC3CA0D1H14G1GI4J0835GEKB  NS DS RRSIG
GPIOQL0L7VJL2SB4CTA1LU5TC263MU96.com. 86400 IN RRSIG NSEC3 8 2 86400 20201004055025 20200927044025 24966 com. m/f6CQuCcAcNW3vvoIzdTs3NQ5rd6bDeQmEooKpZEp9nB/JirpzvS+dp 1dfHbFfB4IAME9eaRBAUKsITih1gsZ1DD6DyNUczOsAJDm+iek+ZIu1S WmBt+uo3b6Mv7HIIi1ClRVA/Akcu3+Bkyog3DwKD4sej7Z8yeNpYHksf 1gIfR88gdQ84m85tCLjwoGt8mEc4uuTRGSRDvD+5+Ph/1A==
;; Received 873 bytes from 192.54.112.30#53(h.gtld-servers.net) in 32 ms

www.yahoo.com.		60	IN	CNAME	new-fp-shed.wg1.b.yahoo.com.
wg1.b.yahoo.com.	172800	IN	NS	yf4.a1.b.yahoo.net.
wg1.b.yahoo.com.	172800	IN	NS	yf3.a1.b.yahoo.net.
wg1.b.yahoo.com.	172800	IN	NS	yf2.yahoo.com.
wg1.b.yahoo.com.	172800	IN	NS	yf1.yahoo.com.
;; Received 220 bytes from 202.165.97.53#53(ns5.yahoo.com) in 296 ms

Проследете пътя на DNS заявките. Ще видите всеки скок от сървър на сървър и можете да откриете проблеми по пътя.

linux@linux:~$ dig -p 5300 yahoo.com

; <<>> DiG 9.11.3-1ubuntu1.13-Ubuntu <<>> -p 5300 yahoo.com
;; global options: +cmd
;; connection timed out; no servers could be reached

Избери порт за заявката.

Заключение

Диг командата има добър набор от опции за основни DNS заявки. Трябва ли да я използвате вместо Хост командата или Пинг командата? Вие решете.

Източник:
Linuxize.com
Tecmint.com

Вашият коментар

Вашият имейл адрес няма да бъде публикуван.