Lesson 85: dig Command
In this lesson, you'll learn how to use the dig command to query DNS records and troubleshoot DNS-related issues in Linux.
dig stands for Domain Information Groper which is a network administration command-line tool for querying Domain Name System (DNS) name servers.
It is useful for verifying and troubleshooting DNS problems and also for performing DNS lookups and displaying the answers that are returned from the name server that was queried.
dig is part of the BIND domain name server software suite. It has replaced older tools such as nslookup and host.
It is available in major Linux distributions.
dig Command Syntax
# dig [OPTIONS] [DOMAIN] [RECORD_TYPE]
dig Command Options
| Option | Description |
|---|---|
+short |
Display a short, concise output |
+nocomments |
Suppress comment lines in output |
+noquestion |
Suppress the question section |
+noauthority |
Suppress the authority section |
+noadditional |
Suppress the additional section |
+nostats |
Suppress the statistics section |
+noall +answer |
Show only the answer section |
-x IP |
Perform a reverse DNS lookup |
1. Query Domain "A" Record
Let's look up the "A" record for the domain name yahoo.com by executing the command stated below:
# dig yahoo.com
; <<>> DiG 9.18.12-0ubuntu0.22.04.2-Ubuntu <<>> yahoo.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51852
;; flags: qr rd ra; QUERY: 1, ANSWER: 8, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;yahoo.com. IN A
;; ANSWER SECTION:
yahoo.com. 5 IN A 98.137.11.163
yahoo.com. 5 IN A 34.225.127.72
yahoo.com. 5 IN A 74.6.231.21
yahoo.com. 5 IN A 74.6.143.25
yahoo.com. 5 IN A 74.6.231.20
yahoo.com. 5 IN A 98.137.11.164
yahoo.com. 5 IN A 74.6.143.26
yahoo.com. 5 IN A 54.161.105.65
;; Query time: 12 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Mon Sep 18 19:16:48 EDT 2023
;; MSG SIZE rcvd: 166
The above command causes dig to look up the "A" record for the domain name yahoo.com.
It reads the /etc/resolv.conf file and queries the DNS servers listed there. The response from the DNS server is what dig displays.
Let us understand the output of the command:
- Lines beginning with
;are comments and not part of the information. - The first line tells us the version of the
dig(9.18.12) command. - Next,
digshows the header of the response it received from the DNS server. - Next comes the question section, which simply tells us the query β in this case a query for the "A" record of
yahoo.com. The "IN" means this is an Internet lookup (in the Internet class). - The answer section tells us that
yahoo.comhas the IP address98.137.11.163. - Lastly, there are some stats about the query. You can turn off these stats using the
+nostatsoption.