The dig command, which stands for Domain Information Groper, is a powerful and versatile command-line utility for querying Domain Name System (DNS) servers.
For network administrators and developers, it is an indispensable tool for diagnosing DNS problems, verifying configurations, and gaining a deeper understanding of how domain names are resolved into IP addresses.
This article will provide a thorough exploration of the dig command, from its basic usage to the intricacies of its output.
Table of Contents
Understanding the Role of dig
At its core, dig is used to retrieve detailed information about various DNS records, such as A (address), MX (mail exchange), NS (name server), and more.
It allows users to send DNS queries to specific name servers and inspect the responses, making it invaluable for troubleshooting network-related issues.
By default, dig directs its queries to the DNS server listed in the /etc/resolv.conf file, but it also provides the flexibility to query any other name server directly.
Getting Started with dig
On most Linux distributions, the dig command is part of the dnsutils or bind-utils package.
If it’s not already installed on your system, you can typically install it using your distribution’s package manager. For example, on Debian-based systems like Ubuntu, you would use:
sudo apt-get install dnsutils
For Red Hat-based systems like CentOS, the command would be:
sudo yum install bind-utils
Once installed, you can verify its availability by checking its version: dig -v.
See also: Mastering the Linux Command Line — Your Complete Free Training Guide
Common dig Commands at a Glance
Here’s a quick overview of some of the most frequently used dig commands:
| Command | Description | Example |
|---|---|---|
dig [hostname] | Retrieves the A record (IP address) for the specified hostname. | dig www.example.com |
dig [hostname] [record type] | Fetches records of a specific type for the hostname. | dig example.com MX |
dig [hostname] +short | Provides a concise answer, often just the IP address. | dig www.example.com +short |
dig @[nameserver] [hostname] | Queries a specific DNS server instead of the default. | dig @8.8.8.8 www.example.com |
dig [hostname] +trace | Traces the DNS resolution path from the root servers. | dig www.example.com +trace |
dig -x [IP address] | Performs a reverse DNS lookup to find the hostname associated with an IP address. | dig -x 8.8.8.8 |
dig [hostname] ANY | Requests all available DNS record types for a hostname. | dig example.com ANY |
dig -f [filename] | Executes batch queries for a list of domains in a file. | dig -f domains.txt |
Deconstructing the dig Command Output
A standard dig query returns a wealth of information, which can be broken down into several key sections.
Let’s examine the output of a simple query, dig google.com:
; <<>> DiG 9.18.1-1ubuntu1.1-Ubuntu <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12345
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;google.com. IN A
;; ANSWER SECTION:
google.com. 202 IN A 142.250.191.46
;; Query time: 47 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Tue Oct 22 10:00:00 UTC 2025
;; MSG SIZE rcvd: 55
Here’s a breakdown of each part of the output:
- Header: This initial section provides metadata about the query and response. It includes the
digversion, the global options used, and the DNS response header. The header contains important details like the query status (NOERRORindicates a successful query) and flags. - Flags: These provide more specific information about the response. Common flags include:
qr: Indicates that this is a query response.rd: Stands for “Recursion Desired,” meaning the client requested that the DNS server perform a recursive query.ra: Means “Recursion Available,” confirming that the server supports recursion.aa: Denotes an “Authoritative Answer,” meaning the response came directly from a nameserver that is an authority for the domain.
- OPT PSEUDOSECTION: This section relates to the Extension Mechanisms for DNS (EDNS), which allows for more advanced DNS features.
- QUESTION SECTION: This part restates the query that was sent. In this case, it shows a request for an A (address) record for
google.com. - ANSWER SECTION: This is the core of the response, providing the answer to the query. It includes the domain name, the Time to Live (TTL) in seconds, the class (IN for Internet), the record type (A), and the IP address.
- AUTHORITY SECTION: This section lists the authoritative name servers for the domain, which are the primary sources of DNS information for that domain.
- ADDITIONAL SECTION: This provides extra information that might be useful, such as the IP addresses of the name servers listed in the AUTHORITY SECTION.
- Statistics: The final part of the output provides meta-information about the query itself, including the query time, the server that provided the answer, when the query was made, and the size of the response message.
Practical Applications of dig
The dig command is not just for retrieving A records. Here are some practical scenarios where it proves to be a powerful diagnostic tool:
- Querying Specific Record Types: You can specify different record types to get more targeted information. For instance, to find the mail servers for a domain, you would query for
MXrecords:dig example.com MX. To find the name servers, you’d useNS:dig example.com NS. - Tracing DNS Resolution: The
+traceoption is incredibly useful for understanding the entire DNS resolution process. It follows the query from the root name servers down to the authoritative name servers for the domain, showing each step of the lookup. This can help pinpoint where a DNS issue might be occurring. - Reverse DNS Lookups: Using the
xflag followed by an IP address,digcan perform a reverse DNS lookup to find the domain name associated with that IP. - Querying Specific DNS Servers: To check if a DNS change has propagated to a specific name server, you can direct your query to it using the
@symbol, for example,dig @8.8.8.8 example.com. This is useful for comparing responses from different DNS servers. - Concise Output: For scripting or quick checks, the
+shortoption provides just the essential information. For a slightly more detailed but still clean output,+noall +answerwill display only the answer section.
In conclusion, the dig command is a fundamental tool for anyone working with networks and the internet.
Its ability to perform detailed DNS queries and present the results in a structured format makes it an essential utility for troubleshooting, verification, and a deeper understanding of the intricate workings of the Domain Name System.




[…] To handle multiple domains and interact with DNS effectively, I rely on “dig”. This simple yet powerful tool allows me to quickly run DNS queries and retrieve valuable information about domain names. Learn more about how to use dig command […]