Skip to content

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. Unlike nslookup, dig provides 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

Networking Mastery → Module 9: Linux Networking → Lesson 6

Difficulty: Beginner

Reading Time: 140 Minutes

Course Progress

Course: Networking Mastery

Module: Linux Networking

Lesson: 6 of 10


What You'll Learn

After completing this lesson, you'll be able to:

  • Understand the dig command
  • Query DNS records
  • Troubleshoot DNS resolution
  • Perform reverse DNS lookups
  • Query specific DNS servers
  • Understand authoritative responses
  • Diagnose production DNS issues

Prerequisites

Complete:

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.

Ping

Works

But:

google.com

Cannot Resolve

The first tool most Linux engineers use is:

dig

What is dig?

dig stands for:

Domain Information Groper

It queries DNS servers and displays:

  • DNS Records
  • Query Status
  • Name Servers
  • Response Time
  • Time To Live (TTL)
  • Authority Information

DNS Resolution Process

Application


Resolver


DNS Server


Authoritative Server


Response

dig helps inspect every stage of this process.


Basic Syntax

dig domain

Example:

dig google.com

Install dig

Ubuntu/Debian

sudo apt install dnsutils

RHEL/CentOS

sudo dnf install bind-utils

Basic DNS Query

dig google.com

Returns:

  • IP Address
  • TTL
  • Query Time
  • DNS Server
  • Response Status

Understanding Output

Important sections:

QUESTION SECTION

The requested record.

ANSWER SECTION

The returned DNS record.

AUTHORITY SECTION

Authoritative name servers.

ADDITIONAL SECTION

Additional useful records.


Query A Record

dig google.com A

Returns:

IPv4 Address

Query AAAA Record

dig google.com AAAA

Returns:

IPv6 Address

Query MX Record

dig gmail.com MX

Returns:

Mail Servers

Query NS Record

dig google.com NS

Returns:

Authoritative Name Servers

Query CNAME Record

dig www.github.com CNAME

Returns:

Canonical Name

Query TXT Record

dig google.com TXT

Commonly used for:

  • Sender Policy Framework (SPF)
  • DomainKeys Identified Mail (DKIM)
  • Domain Verification
  • Security Policies

Reverse DNS Lookup

dig -x 8.8.8.8

Returns:

PTR Record

Maps:

IP Address


Hostname

Query Specific DNS Server

Example:

dig @8.8.8.8 google.com

Queries Google's DNS server directly.


Query Cloudflare DNS

dig @1.1.1.1 google.com

Query Any Record

dig google.com ANY

Note: Many public DNS servers restrict or minimise responses to ANY queries for security and performance reasons. Do not rely on ANY to retrieve all record types.


Short Output

dig +short google.com

Returns only:

IP Address

Useful for scripts.


Display Trace

dig +trace google.com

Shows the complete DNS resolution path:

Root


Top-Level Domain (TLD)


Authoritative Server

Display TTL

Example output:

300

Meaning:

5 Minutes

The DNS record can be cached for five minutes.


Check DNSSEC

dig +dnssec google.com

Displays Domain Name System Security Extensions (DNSSEC)-related information when available.


DNS Troubleshooting Workflow

Application


Resolver


DNS Server


Authoritative Server

Use dig to identify where failures occur.


Enterprise Example

Users cannot access:

portal.company.com

Run:

dig portal.company.com

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:

dig kubernetes.default.svc.cluster.local

Useful for troubleshooting:

  • CoreDNS
  • Service Discovery
  • Internal Name Resolution

Linux Perspective

Basic query.

dig google.com

Short output.

dig +short google.com

Reverse lookup.

dig -x 8.8.8.8

Specific DNS server.

dig @8.8.8.8 google.com

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.

dig google.com

Task 2

Query IPv4 address.

dig google.com A

Task 3

Query IPv6 address.

dig google.com AAAA

Task 4

Query mail servers.

dig gmail.com MX

Task 5

Query authoritative name servers.

dig google.com NS

Task 6

Perform reverse lookup.

dig -x 8.8.8.8

Task 7

Query Google's public DNS server.

dig @8.8.8.8 google.com

Compare the result with your organisation's default DNS resolver.


Task 8

Trace DNS resolution.

dig +trace google.com

Observe the path from the root servers to the authoritative name servers.


Production Troubleshooting

Problem:

Website

Not Resolving

Step 1

dig website.com

Resolved?

No

Check:

dig @8.8.8.8 website.com

Works?

Yes

Problem:

Local DNS

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 +short in scripts.
  • Use +trace for 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

  1. What is dig?
  2. How do you query an A record?
  3. What is a reverse DNS lookup?
  4. What does dig +short do?

Intermediate

  1. Explain the different sections of dig output.
  2. How do you query a specific DNS server?
  3. What is TTL?
  4. Explain dig +trace.

Architect Level

  1. Design a DNS troubleshooting workflow using dig.
  2. Explain how you would troubleshoot intermittent DNS failures in Kubernetes.
  3. How would you validate DNS propagation after migrating to a new DNS provider?

Summary

In this lesson, you learned:

  • The dig command
  • 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

  • dig is the preferred DNS troubleshooting tool on Linux.
  • Query specific record types such as A, AAAA, MX, NS, and TXT.
  • Use dig -x for reverse DNS lookups.
  • Use @server to query a specific DNS resolver.
  • Use +short for concise output and +trace to follow the complete DNS resolution path.
  • dig is indispensable for troubleshooting DNS issues in enterprise, cloud, and Kubernetes environments.

What's Next?

nslookup

In the next lesson, you'll learn about nslookup.

You'll explore:

  • What nslookup is
  • Basic DNS Queries
  • Querying Specific Record Types
  • Interactive Mode
  • Reverse DNS Lookups
  • DNS Troubleshooting
  • Comparing nslookup with dig

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.