dig Command: Tutorial & Examples

Querying DNS Servers

The dig command, short for Domain Information Groper, is a versatile tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server that was queried. The dig command is useful for network troubleshooting and for educational purposes.

It's an essential tool for any system administrator, especially if you're dealing with issues related to DNS resolution.

How dig Works

The dig command sends a DNS query to the server specified (or to the default system DNS server if unspecified), and then displays the server's response. It can be used to retrieve all types of DNS records, including A (Address), MX ( Mail Exchange), and TXT (Text) records.

One of the strengths of the dig command is its ability to give verbose and detailed output, which is helpful when debugging DNS issues or understanding the DNS process.

Why the dig Command is Important

Understanding DNS queries and responses is crucial for troubleshooting network or website problems. The dig command is a powerful tool in this regard, as it provides rich and detailed information about DNS operations.

Additionally, dig can be used to verify the health and functionality of your DNS server(s). If you're experiencing a network failure, dig can help identify if the issue is DNS-related.

Common Problems Solved by the dig Command

Problems related to DNS resolution are common in networked systems. dig can help diagnose these issues. For example, if a website is not loading, you can use dig to determine if the issue lies in DNS resolution.

In case of a misconfigured DNS server or incorrect DNS records, dig can provide insights into what's wrong by displaying the raw DNS response from the server.

dig Command Examples

Let's look at some examples of how to use the dig command.

dig www.example.com

This command retrieves the DNS records for the domain www.example.com. The output will show the A record (IP address) for this domain.

dig MX www.example.com

This command retrieves the MX (Mail Exchange) records for the domain www.example.com. The output will list the mail servers and their priorities.

dig +short www.example.com

This command provides a concise version of the DNS query response, showing only the most essential information (usually the A record).

Expected Output

A typical output of a dig command looks like this:

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

; EDNS: version: 0, flags:; udp: 65494
;www.example.com.       IN  A

www.example.com.    14399   IN  A

;; Query time: 28 msec
;; WHEN: Fri Mar 22 14:18:55 UTC 2019
;; MSG SIZE  rcvd: 59

In this example, you can see that www.example.com resolves to the IP address

The text above is licensed under CC BY-SA 4.0 CC BY SA