Updated 8 hours ago
Most DNS tools show you the answer. Dig shows you the conversation.
When you ask "what's the IP for example.com?", dig doesn't just return an address. It shows you which server answered, how long the query took, how long you can cache the result, and every detail of the exchange. This transparency transforms DNS from a black box into something you can understand and debug.
Basic Usage
The simplest dig command:
This produces detailed output. Let's decode it.
Reading the Output
The header tells you the query status. NOERROR means success. You'll also see NXDOMAIN (domain doesn't exist), SERVFAIL (server error), or REFUSED (server won't answer you).
The flags reveal the response characteristics:
qr: This is a response (not a query)rd: You asked for recursive resolutionra: The server supports recursionaa: Authoritative answer (appears when the response comes directly from the domain's nameserver, not from cache)
The question section echoes what you asked: "What is the A record for example.com?"
The answer section contains the goods:
example.com.— the domain86400— TTL in seconds (24 hours). This is how long the answer can be cached.IN— Internet classA— record type93.184.216.34— the answer
The statistics show query time (12ms), which server answered (192.168.1.1), and when.
Querying Different Record Types
Querying Specific Servers
By default, dig uses your system's DNS resolver. To query a specific server:
To see the authoritative answer (bypassing all caches), first find the nameservers:
Then query one directly:
This shows the official current record, not a cached copy.
Controlling Output
Just the answer:
Returns only:
Perfect for scripts.
Answer section with details:
Returns:
Trace the entire resolution path:
This is genuinely magical. You watch your query travel from root servers (.) through TLD servers (.com.) to the authoritative nameservers. It's like watching a letter get sorted through the postal system in real time.
Reverse Lookups
Given an IP, find its hostname:
This queries PTR records.
Practical Troubleshooting
Have DNS changes propagated?
Compare authoritative and public DNS:
If they differ, changes haven't fully propagated.
When will the cache expire?
The TTL tells you. Query twice with a gap:
Watch the TTL decrease. When it hits zero, the record will be fetched fresh.
Is the response authoritative or cached?
Look for the aa flag. Present means authoritative. Absent means cached.
Debug a CNAME chain:
The answer section shows each hop in the chain.
Verify mail configuration:
Shows mail servers and priorities. Then verify they resolve:
Advanced Options
Force TCP (instead of UDP):
Useful for testing firewalls or large responses.
Set timeout:
Wait only 2 seconds.
Query DNSSEC:
Shows cryptographic signatures if the domain uses DNSSEC.
Multiline TXT records:
Makes long records readable.
Status Codes
When things go wrong, the status tells you why:
- NOERROR: Success (even if the answer section is empty—domain exists but has no records of that type)
- NXDOMAIN: Domain doesn't exist
- SERVFAIL: Server encountered an error (often misconfigured nameservers)
- REFUSED: Server won't answer you (access restrictions)
Script-Friendly Patterns
Frequently Asked Questions About dig
Was this page helpful?