10 Linux Dig (Domain Information Groper) commands for querying DNS

s2 0

In our previous article, we discussed examples and uses of nslookup commands, a network command line tool used to query and obtain Domain Name System (DNS) information.

Here in this article we are developing another command line tool called shewhich is very similar to Linux nslookup Tool. We’ll take a closer look at how to use the dig command through its examples and usage.

[ You might also like: How to Install and Use dig and nslookup Commands in Linux ]

she stands for (Domain information Groper) is a network administration command line query tool Domain name system (DNS) Nameserver.

It’s useful for reviewing and troubleshooting DNS Problems and also to do DNS searches and displays the answers returned by the queried name server.

Digging is part of it TIE Domain Name Server software suite. The dig command replaces older tools like nslookup and the host. dig tool is available in the most important Linux distributions.

1. Query domain “A” data set

# dig yahoo.com

; <<>> DiG 9.16.1-Ubuntu <<>> yahoo.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20076
;; 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.		387	IN	A	98.137.11.163
yahoo.com.		387	IN	A	74.6.143.26
yahoo.com.		387	IN	A	74.6.143.25
yahoo.com.		387	IN	A	74.6.231.20
yahoo.com.		387	IN	A	74.6.231.21
yahoo.com.		387	IN	A	98.137.11.164

;; Query time: 4 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Fri Dec 10 12:58:13 IST 2021
;; MSG SIZE  rcvd: 134

The above command will cause dig to look for "A" Entry for the domain name yahoo.com. Dig command reads the /etc/resolv.conf File and query of the DNS server listed there. The answer from the DNS server is what dig indicates.

Let’s understand the output of the commands:

  • Lines beginning with ; are comments that are not part of the information.
  • The first line tells us the version of the dig (9.16.1) Command.
  • Next, dig displays the header of the response it received from the DNS Server.
  • Next up is the question section which simply tells us the query, which in this case is a query for the "A" Recording of yahoo.com. the IN means that it is an internet search (in internet class).
  • The answer section tells us that yahoo.com has the IP address 98.137.11.163.
  • Finally, there are some statistics on the query. You can disable these statistics with the +nostats Opportunity.

2. Domain “A” record with + short. Interrogate

By default, she is quite detailed. One way to reduce the output is to use the +short Opportunity. which drastically reduces the output as shown below.

# dig yahoo.com +short

98.137.11.164
74.6.231.21
74.6.231.20
74.6.143.25
74.6.143.26
98.137.11.163

Note: By default, dig searches for the "A" Record of the specified domain, but you can also specify other records. the MX or Email exchanges record tells the mail servers how to route email for the domain. Likewise TTL, SOA, Etc.

3. Query the MX record for the domain

Querying different types of DNS resource records only.

# dig yahoo.com MX

; <<>> DiG 9.16.1-Ubuntu <<>> yahoo.com MX
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60630
;; 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.		51	IN	MX	1 mta6.am0.yahoodns.net.
yahoo.com.		51	IN	MX	1 mta5.am0.yahoodns.net.
yahoo.com.		51	IN	MX	1 mta7.am0.yahoodns.net.

;; Query time: 4 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Fri Dec 10 13:03:32 IST 2021
;; MSG SIZE  rcvd: 117

4. Query the SOA record for the domain

# dig yahoo.com SOA

; <<>> DiG 9.16.1-Ubuntu <<>> yahoo.com SOA
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25140
;; 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. 
2021121001 3600 300 1814400 600

;; Query time: 128 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Fri Dec 10 13:04:08 IST 2021
;; MSG SIZE  rcvd: 99

5. Query of the TTL entry for the domain

# dig yahoo.com TTL

; <<>> DiG 9.16.1-Ubuntu <<>> yahoo.com TTL
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64017
;; 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.		1606	IN	A	74.6.143.25
yahoo.com.		1606	IN	A	74.6.231.21
yahoo.com.		1606	IN	A	74.6.143.26
yahoo.com.		1606	IN	A	98.137.11.164
yahoo.com.		1606	IN	A	98.137.11.163
yahoo.com.		1606	IN	A	74.6.231.20

;; Query time: 4 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Fri Dec 10 13:04:58 IST 2021
;; MSG SIZE  rcvd: 134

;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 27889
;; 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: Fri Dec 10 13:04:58 IST 2021
;; MSG SIZE  rcvd: 32

6. “Queries only” section

# dig yahoo.com +nocomments +noquestion +noauthority +noadditional +nostats

; <<>> DiG 9.16.1-Ubuntu <<>> yahoo.com +nocomments +noquestion +noauthority +noadditional +nostats
;; global options: +cmd
yahoo.com.		1556	IN	A	74.6.231.20
yahoo.com.		1556	IN	A	98.137.11.163
yahoo.com.		1556	IN	A	98.137.11.164
yahoo.com.		1556	IN	A	74.6.143.26
yahoo.com.		1556	IN	A	74.6.231.21
yahoo.com.		1556	IN	A	74.6.143.25

7. Query ALL types of DNS records

# dig yahoo.com ANY +noall +answer

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6 <<>> yahoo.com ANY +noall +answer
;; global options: +cmd
yahoo.com.              3509    IN      A       72.30.38.140
yahoo.com.              3509    IN      A       98.138.253.109
yahoo.com.              3509    IN      A       98.139.183.24
yahoo.com.              1709    IN      MX      1 mta5.am0.yahoodns.net.
yahoo.com.              1709    IN      MX      1 mta6.am0.yahoodns.net.
yahoo.com.              1709    IN      MX      1 mta7.am0.yahoodns.net.
yahoo.com.              43109   IN      NS      ns2.yahoo.com.
yahoo.com.              43109   IN      NS      ns8.yahoo.com.
yahoo.com.              43109   IN      NS      ns3.yahoo.com.
yahoo.com.              43109   IN      NS      ns1.yahoo.com.
yahoo.com.              43109   IN      NS      ns4.yahoo.com.
yahoo.com.              43109   IN      NS      ns5.yahoo.com.
yahoo.com.              43109   IN      NS      ns6.yahoo.com.

8. DNS reverse lookup

Interrogate DNS Reverse search. Show answer area only when used + short.

# dig -x 72.30.38.140 +short

ir1.fp.vip.sp2.yahoo.com.

9. Querying multiple DNS records

Query the DNS specific query of multiple websites. MX, NS, etc. records.

# dig yahoo.com mx +noall +answer redhat.com ns +noall +answer

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6 <<>> yahoo.com mx +noall +answer redhat.com ns +noall +answer
;; global options: +cmd
yahoo.com.              1740    IN      MX      1 mta6.am0.yahoodns.net.
yahoo.com.              1740    IN      MX      1 mta7.am0.yahoodns.net.
yahoo.com.              1740    IN      MX      1 mta5.am0.yahoodns.net.
redhat.com.             132     IN      NS      ns1.redhat.com.
redhat.com.             132     IN      NS      ns4.redhat.com.
redhat.com.             132     IN      NS      ns3.redhat.com.
redhat.com.             132     IN      NS      ns2.redhat.com.

10. Create a .digrc file

Create .digrc File under $ HOME / .digrc to save standard dig options.

# dig yahoo.com
yahoo.com.              3427    IN      A       72.30.38.140
yahoo.com.              3427    IN      A       98.138.253.109
yahoo.com.              3427    IN      A       98.139.183.24

We have stores + no everything + Answer Options permanently in .digrc File in the user’s home directory. If the dig command is executed now, only the response section of the dig output will be displayed. No need to like options every time. to enter + no everything + Answer.

In this article, we’ve tried to figure out the dig command, which can help you find (DNS) Domain Name Service-related information. Share your thoughts using the comments box.