Operations 5 min read

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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master DNS Lookups with dig: A Complete Linux Guide

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.com

This returns the IPv4 address associated with example.com.

2. AAAA record (IPv6 address)

dig AAAA example.com

This returns the IPv6 address for example.com.

3. MX record (mail exchange)

dig MX example.com

The 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.com

Example Scenarios

1. Retrieve MX records for a domain

dig MX example.com

This returns the mail server information for example.com, including priorities.

2. Get the SOA record of a name‑server

dig +short -t SOA example.com

The 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxcommand-lineDNSnetwork-toolsdig
Liangxu Linux
Written by

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.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.