Master DNS Lookups with dig: A Complete Linux Guide
This guide explains how to use the Linux dig command to query various DNS records, retrieve name‑server details, perform reverse lookups, and specify custom DNS servers, providing clear examples and step‑by‑step commands for effective network troubleshooting.
The dig (Domain Information Groper) utility is a powerful Linux tool for querying DNS information such as domain resolution, DNS records, and name‑server details.
Querying Domain Records
Use dig to retrieve specific DNS record types for a domain.
1. A record (IPv4 address)
dig A example.comThis returns the IPv4 address associated with example.com.
2. AAAA record (IPv6 address)
dig AAAA example.comThis returns the IPv6 address for example.com.
3. MX record (mail exchange)
dig MX example.comThe output lists the mail servers handling email for example.com, including priority values.
Querying DNS Server Information
1. Name‑server IP address
Replace ns1.example.com with the target name‑server: dig +short ns1.example.com The command returns the IP address of the specified name‑server.
2. Detailed name‑server data (SOA, NS)
To fetch the Start of Authority (SOA) record for a domain: dig +short -t SOA example.com The result includes the domain’s authoritative information such as refresh and retry intervals.
Other Useful Queries
1. Reverse DNS lookup
Convert an IP address to its domain name: dig -x 192.168.1.1 The output shows the domain name associated with 192.168.1.1.
2. Query a specific DNS server
Specify a DNS server (e.g., Google’s 8.8.8.8) for the lookup:
dig @8.8.8.8 example.comExample Scenarios
1. Retrieve MX records for a domain
dig MX example.comThis returns the mail server information for example.com, including priorities.
2. Get the SOA record of a name‑server
dig +short -t SOA example.comThe command provides the SOA details for example.com, useful for understanding domain authority settings.
Conclusion
The dig command is an essential tool for Linux users to investigate DNS configurations, troubleshoot network issues, and manage domain information effectively.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
