How to Use the ‘dig’ Command for Advanced DNS Troubleshooting in Linux

The Limitations of ping and nslookup

When a website suddenly stops loading, the first instinct of most administrators is to run a quick ping google.com. If that fails, they might try nslookup to see if the DNS server is resolving the domain name. While these tools are adequate for basic checks, they hide the complex, multi-layered reality of the Domain Name System.

If you are migrating a website to a new host, changing MX records for a new email provider, or diagnosing a global DNS propagation issue, you need a tool that exposes the raw DNS data. You need dig (Domain Information Groper).

dig is the industry standard command-line tool for querying DNS name servers. Unlike nslookup, which often relies on the operating system’s internal (and sometimes flawed) resolver cache, dig talks directly to the DNS servers, providing a verbose, highly accurate readout of the exact DNS records.

The Basic dig Command

To perform a standard DNS lookup for a domain’s IP address (the A Record), simply type dig followed by the domain name.

dig digitash.com

Understanding the Output:

The output will be divided into several sections. The most important is the “ANSWER SECTION”. It will look something like this:

;; ANSWER SECTION:
digitash.com.		300	IN	A	142.250.190.46
  • 300: This is the Time To Live (TTL) in seconds. It tells you how long the record will be cached before it must be checked again (5 minutes in this case).
  • IN: Stands for Internet.
  • A: The record type (Address record).
  • 142.250.190.46: The actual IP address.

Advanced Queries

1. Querying Specific Record Types

By default, dig only asks for the ‘A’ record. If you are troubleshooting an email delivery issue, you need to see the Mail Exchange (MX) records. Simply append the record type to the command.

dig digitash.com MX

To check the text records (often used for SPF/DMARC anti-spam verification):

dig digitash.com TXT

To request every single public record available for a domain:

dig digitash.com ANY

2. Bypassing Local DNS (Querying a Specific Server)

If you recently changed your website’s IP address, your computer might still be loading the old site because your ISP’s local DNS server has cached the old record. You can use dig to bypass your ISP and ask Google’s public DNS (8.8.8.8) or Cloudflare’s public DNS (1.1.1.1) directly to see if the changes have propagated globally.

To query a specific server, use the @ symbol followed by the server’s IP address:

dig @8.8.8.8 digitash.com

3. The “+short” Flag for Clean Scripts

The verbose output of dig is excellent for human reading, but terrible if you are writing a bash script and just need the raw IP address to pass into a variable. Add the +short flag to strip away all the headers and formatting.

dig digitash.com +short

The output will simply be: 142.250.190.46.

Tracing the DNS Hierarchy

If a domain is completely failing to resolve anywhere on the internet, you can use the +trace flag. This forces dig to start at the absolute top of the internet (the Root Servers), ask them for the .com servers, then ask the .com servers for your domain’s specific name servers, mapping the entire chain of custody.

dig digitash.com +trace

This will instantly highlight exactly which level of the global DNS infrastructure is failing to route your traffic.

Conclusion

While ping tells you if a server is alive, dig tells you exactly how the internet is finding that server. Mastering dig is an absolute requirement for anyone managing web hosting, email infrastructure, or enterprise networks on Linux.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.