Linux dig command for network diagnostics

29.09.2020 1,907 1

​Linux dig command is another command-line software, like the host command, that you probably already have. Here we will show you how to use it on your Linux computer. You can also check out a version of the dig command for Windows and macOS.

What is dig command

DIG (Domain Information Groper) is a widely used DNS probing utility. Troubleshoot your DNS service and see if there is a problem. We will be using it on Linux (Ubuntu-based Linux Mint 19.1), but you can find it on macOS or Windows too, with little to no difference in functionality.

Linux dig command installation

If you are using a popular Linux distro, you probably already have it installed. Open the Terminal and type in “dig -v“. If it is installed, you will see a message with the version similar to this:

DiG 9.11.3-1ubuntu1.7-Ubuntu.

If you don’t have it, then the message will be:

dig command not found

For Ubuntu-based Linux distributions (Ubuntu, Mint, etc.) you can get dig command with the following:

sudo apt install dnsutils

For CentOS or Fedora:

sudo yum install bind-utils

For Arch Linux computers:

sudo pacman -S bind-tools

Dig command explained

In our examples we will use Yahoo.com. You can use your domain or another one. Just replace the “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

The version of the command and the global options are shown first.
The DNS server provides a header, where it displays “NOERROR” if your query was successful.

Then the answer for the EDNS.
The default is the A record which shows the IP address for the domain you are probing.

Dig command examples

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

Just the IP address without any additional text.

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 record query will give you data about the incoming mail servers of the host.

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

See the SOA record – the start of authority.

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. Showing for how long the data must be kept.

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

Only answer the query. No extra information query.

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.

This dig command will show all DNS records.

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

The Reverse lookup. You put in the IP address and you want to see the domain. You will get a PTR record.

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

Trace the route of the DNS query. You will see each hop and you can see a problematic server on the way.

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

Set the port for the query.

Conclusion

Dig command has a good set of options enough for basic DNS troubleshooting. Should you use it instead of the Host command or Ping command? It is up to you to decide.

Sources:
Linuxize.com
Tecmint.com

One reply on “Linux dig command for network diagnostics”

rifles for sale

… [Trackback]

[…] Here you can find 40447 more Information to that Topic: blog.neterra.cloud/en/linux-dig-command-for-network-diagnostics/ […]

Leave a Reply

Your email address will not be published.