1. Basic DNS Lookup (A Record)
$ dig google.com
Performs a basic DNS lookup for google.com, returning the A record (IPv4 address). This is the most common usage of dig.
Output includes: Query time, server used, answer section with IP address, authority section, and additional information.
2. Query Specific DNS Server
$ dig @8.8.8.8 example.com
Queries Google's public DNS server (8.8.8.8) specifically for example.com instead of using your system's default DNS server.
Why this matters: Different DNS servers may return different results due to caching, propagation delays, or filtering. This lets you test against specific nameservers.
3. Short Answer Format
$ dig +short google.com
Returns only the IP address without all the additional information. Perfect for scripting and when you just need the answer.
Output: Just the IP address(es), one per line.
IP=$(dig +short example.com)
4. Query MX Records (Mail Servers)
$ dig example.com MX
Retrieves the Mail Exchange (MX) records for a domain, showing which mail servers handle email for that domain.
Output shows: Priority numbers (lower = higher priority) and mail server hostnames.
5. Query NS Records (Name Servers)
$ dig example.com NS
Shows the authoritative name servers for a domain. These are the servers that hold the official DNS records for the domain.
Critical for: Understanding the DNS hierarchy and knowing where to make DNS changes.
6. Reverse DNS Lookup (PTR Record)
$ dig -x 8.8.8.8
Performs a reverse DNS lookup to find the hostname associated with an IP address. The -x flag automatically handles the reverse lookup format.
Technical note: This queries PTR records in the in-addr.arpa domain.
7. Query TXT Records
$ dig example.com TXT
Retrieves TXT records, which contain arbitrary text data. These are used for various purposes including SPF (email authentication), domain verification, and DMARC policies.
Common uses: SPF records, DKIM keys, domain verification tokens, site verification.
8. Query ALL Record Types
$ dig example.com ANY
Attempts to retrieve all available DNS records for a domain in a single query.
Returns: A, AAAA, MX, NS, TXT, SOA, and other record types if they exist.
9. Trace DNS Resolution Path
$ dig +trace example.com
Shows the complete DNS resolution path from root servers down to the authoritative nameservers. This is incredibly useful for understanding how DNS actually works.
You'll see: Root servers → TLD servers (.com, .org, etc.) → Authoritative nameservers → Final answer
10. Query with Multiple Options Combined
$ dig @1.1.1.1 +short +timeout=2 example.com A
Combines multiple options: uses Cloudflare DNS (1.1.1.1), returns short format output, sets a 2-second timeout, and specifically requests A records.
Options breakdown:
- @1.1.1.1 - Use specific DNS server
- +short - Minimal output
- +timeout=2 - Wait max 2 seconds
- A - Request only A records
Quick Reference: Common dig Options
| Option | Description |
|---|---|
+short |
Display only the answer, no additional information |
+trace |
Show the complete DNS resolution path from root servers |
+noall +answer |
Show only the answer section |
+nocmd |
Don't display the command line echoed back |
+noquestion |
Don't display the question section |
+nocomments |
Don't display comment lines in output |
+nostats |
Don't display query statistics |
-x [IP] |
Perform reverse DNS lookup |
@[server] |
Query specific DNS server |
+timeout=[sec] |
Set query timeout in seconds |
alias myip='dig +short myip.opendns.com @resolver1.opendns.com'This gives you your public IP instantly!