Linux dig Command — Querying and Troubleshooting DNS¶
dig(Domain Information Groper) is the most powerful command-line utility for querying the Domain Name System (DNS). It is used to retrieve DNS records, verify name resolution, troubleshoot DNS issues, inspect authoritative name servers, perform reverse lookups, and validate DNS configurations. Unlikenslookup,digprovides detailed information about DNS queries and responses, making it the preferred DNS troubleshooting tool for Linux administrators, DevOps engineers, Cloud Architects, Platform Engineers, Site Reliability Engineers (SRE), Network Engineers, and Security Engineers.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand the
digcommand - Query DNS records
- Troubleshoot DNS resolution
- Perform reverse DNS lookups
- Query specific DNS servers
- Understand authoritative responses
- Diagnose production DNS issues
Prerequisites¶
Complete:
- Linux
ipCommand - Linux
ssCommand - Linux
netstatCommand - Linux
tcpdumpCommand - Linux
tracerouteCommand
Basic understanding of:
- DNS
- IP Addressing
- DNS Records
Why Learn dig?¶
Suppose users report:
- Website Not Opening
- API Not Reachable
- Email Delivery Failure
- Kubernetes Service Resolution Problems
- DNS Timeout
Network connectivity works.
But:
The first tool most Linux engineers use is:
What is dig?¶
dig stands for:
It queries DNS servers and displays:
- DNS Records
- Query Status
- Name Servers
- Response Time
- Time To Live (TTL)
- Authority Information
DNS Resolution Process¶
dig helps inspect every stage of this process.
Basic Syntax¶
Example:
Install dig¶
Ubuntu/Debian
RHEL/CentOS
Basic DNS Query¶
Returns:
- IP Address
- TTL
- Query Time
- DNS Server
- Response Status
Understanding Output¶
Important sections:
The requested record.
The returned DNS record.
Authoritative name servers.
Additional useful records.
Query A Record¶
Returns:
Query AAAA Record¶
Returns:
Query MX Record¶
Returns:
Query NS Record¶
Returns:
Query CNAME Record¶
Returns:
Query TXT Record¶
Commonly used for:
- Sender Policy Framework (SPF)
- DomainKeys Identified Mail (DKIM)
- Domain Verification
- Security Policies
Reverse DNS Lookup¶
Returns:
Maps:
Query Specific DNS Server¶
Example:
Queries Google's DNS server directly.
Query Cloudflare DNS¶
Query Any Record¶
Note: Many public DNS servers restrict or minimise responses to
ANYqueries for security and performance reasons. Do not rely onANYto retrieve all record types.
Short Output¶
Returns only:
Useful for scripts.
Display Trace¶
Shows the complete DNS resolution path:
Display TTL¶
Example output:
Meaning:
The DNS record can be cached for five minutes.
Check DNSSEC¶
Displays Domain Name System Security Extensions (DNSSEC)-related information when available.
DNS Troubleshooting Workflow¶
Use dig to identify where failures occur.
Enterprise Example¶
Users cannot access:
Run:
Questions answered:
- Does DNS resolve?
- Correct IP?
- TTL?
- Authoritative Server?
- NXDOMAIN?
Cloud Perspective¶
Cloud engineers use dig to verify:
- Load Balancer DNS
- Kubernetes Ingress
- Private DNS Zones
- Cloud DNS
- Internal Service Discovery
Kubernetes Perspective¶
DNS is essential for Kubernetes.
Example:
Useful for troubleshooting:
- CoreDNS
- Service Discovery
- Internal Name Resolution
Linux Perspective¶
Basic query.
Short output.
Reverse lookup.
Specific DNS server.
Common DNS Record Types¶
| Record | Purpose |
|---|---|
| A | IPv4 Address |
| AAAA | IPv6 Address |
| MX | Mail Server |
| NS | Name Server |
| CNAME | Alias |
| TXT | Text Record |
| PTR | Reverse Lookup |
| SOA | Start of Authority |
Common dig Commands¶
| Command | Purpose |
|---|---|
dig domain | Basic DNS query |
dig domain A | IPv4 lookup |
dig domain AAAA | IPv6 lookup |
dig domain MX | Mail servers |
dig domain NS | Name servers |
dig -x IP | Reverse lookup |
dig @DNS_SERVER domain | Query specific DNS server |
dig +short domain | Short output |
dig +trace domain | Full DNS resolution path |
Hands-on Lab¶
Task 1¶
Query Google.
Task 2¶
Query IPv4 address.
Task 3¶
Query IPv6 address.
Task 4¶
Query mail servers.
Task 5¶
Query authoritative name servers.
Task 6¶
Perform reverse lookup.
Task 7¶
Query Google's public DNS server.
Compare the result with your organisation's default DNS resolver.
Task 8¶
Trace DNS resolution.
Observe the path from the root servers to the authoritative name servers.
Production Troubleshooting¶
Problem:
Step 1
↓
Resolved?
↓
No
↓
Check:
↓
Works?
↓
Yes
↓
Problem:
↓
No
↓
Investigate:
- Authoritative DNS
- DNS Records
- Firewall
- Network Connectivity
dig vs nslookup¶
| dig | nslookup |
|---|---|
| Modern DNS Tool | Legacy DNS Tool |
| Detailed Output | Simpler Output |
| Preferred for Linux | Available on Many Platforms |
| Better for Troubleshooting | Better for Basic Queries |
Common Mistakes¶
❌ Querying the wrong DNS server.
✅ Specify the server using @server when needed.
❌ Assuming cached results are authoritative.
✅ Query authoritative servers or use +trace.
❌ Ignoring TTL values.
✅ Consider DNS caching when troubleshooting changes.
❌ Relying on ANY queries.
✅ Query specific record types instead.
❌ Forgetting reverse lookups.
✅ Use -x to troubleshoot IP-to-hostname mappings.
Best Practices¶
- Query specific record types whenever possible.
- Use
+shortin scripts. - Use
+tracefor delegation troubleshooting. - Compare responses from multiple DNS servers.
- Verify TTL before changing DNS records.
- Test both public and private DNS zones.
- Document production DNS configurations.
Interview Questions¶
Beginner¶
- What is
dig? - How do you query an A record?
- What is a reverse DNS lookup?
- What does
dig +shortdo?
Intermediate¶
- Explain the different sections of
digoutput. - How do you query a specific DNS server?
- What is TTL?
- Explain
dig +trace.
Architect Level¶
- Design a DNS troubleshooting workflow using
dig. - Explain how you would troubleshoot intermittent DNS failures in Kubernetes.
- How would you validate DNS propagation after migrating to a new DNS provider?
Summary¶
In this lesson, you learned:
- The
digcommand - DNS Queries
- DNS Record Types
- Reverse DNS Lookups
- Authoritative Name Servers
- DNS Tracing
- TTL Analysis
- Enterprise DNS Troubleshooting
dig is the most powerful DNS diagnostic tool available on Linux. It enables engineers to query DNS records, inspect authoritative responses, validate DNS configurations, troubleshoot name resolution problems, and analyse DNS behaviour in enterprise, cloud, and Kubernetes environments. Mastering dig is essential for production network and infrastructure operations.
Key Takeaways¶
digis the preferred DNS troubleshooting tool on Linux.- Query specific record types such as A, AAAA, MX, NS, and TXT.
- Use
dig -xfor reverse DNS lookups. - Use
@serverto query a specific DNS resolver. - Use
+shortfor concise output and+traceto follow the complete DNS resolution path. digis indispensable for troubleshooting DNS issues in enterprise, cloud, and Kubernetes environments.
What's Next?¶
In the next lesson, you'll learn about nslookup.
You'll explore:
- What
nslookupis - Basic DNS Queries
- Querying Specific Record Types
- Interactive Mode
- Reverse DNS Lookups
- DNS Troubleshooting
- Comparing
nslookupwithdig
By the end of the lesson, you'll understand how to use nslookup for quick DNS lookups, troubleshoot common DNS issues, and know when to choose nslookup versus dig.