dig
Query DNS servers and display detailed DNS records
By CMD Script Team · 4 min read · Last updated
dig [@SERVER] [OPTIONS] NAME [TYPE]Options
| Flag | Description |
|---|---|
-x | Perform a reverse DNS lookup for an IP address, e.g. dig -x 8.8.8.8 |
+short | Print only the terse answer (just the resolved value), suppressing headers and metadata |
TYPE | Specify the DNS record type to query, e.g. dig example.com MX, dig example.com TXT |
@SERVER | Query a specific DNS server directly instead of the system default, e.g. dig @8.8.8.8 example.com |
+trace | Trace the full delegation path from the root servers down to the authoritative answer |
+noall +answer | Suppress all output sections except the answer section, for cleaner output |
-4 / -6 | Force queries over IPv4 or IPv6 only |
Distribution compatibility
- Ubuntu
- Debian
- Fedora
- Arch
- macOS
What it does
dig (Domain Information Groper) sends DNS queries to a resolver or a specific
nameserver and displays the full response — the question asked, the answer section with
resolved records and TTLs, and (optionally) authority and additional sections showing
which servers are authoritative. It's the standard, most detailed command-line DNS
diagnostic tool, part of the BIND DNS utilities, and is preferred over nslookup and
host for anything beyond a quick lookup because of how much protocol detail it exposes.
Beginner examples
dig example.com— look up the A record(s) for a domain, full detailed outputdig example.com +short— same lookup, terse output (just the IP)dig example.com MX— look up mail exchanger recordsdig -x 8.8.8.8— reverse lookup: find the hostname for an IP address
dig example.com +short
Advanced examples
- Query a specific public resolver directly to compare against your local DNS (useful
when suspecting DNS cache poisoning or a stale local cache):
dig @1.1.1.1 example.com - Trace the full delegation chain from root servers to authoritative nameserver to
debug a broken DNS setup:
dig example.com +trace - Check TXT records for SPF/DKIM/domain verification entries:
dig example.com TXT +short - Get clean, script-friendly output with just the answer section:
dig example.com A +noall +answer
dig +trace example.com
Common mistakes
- Forgetting that
digby default queries your system's configured resolver, which may have cached an old/incorrect record — use@serverto bypass the cache and check an authoritative or public resolver directly. - Misreading
dig's default verbose output when only the IP is needed — reach for+shortinstead of grepping through the full response. - Assuming a missing record type means the domain is misconfigured, without checking whether that record type was ever expected to exist (e.g., expecting an AAAA record for a domain that's IPv4-only).
- Not specifying a record type and being confused why
dig example.com MXinfo doesn't show up in a plaindig example.com(which defaults to the A record only).
Tips
- Use
+shortconstantly for quick lookups and scripting — it strips away the header, question, and metadata noise. dig +traceis invaluable when a domain "doesn't resolve" and you need to find exactly which level of the delegation chain (root → TLD → authoritative) is broken.- Combine
digwith@serverto directly compare answers from different resolvers when debugging DNS propagation delays after a record change.
Best practices
- After changing DNS records, verify propagation by querying multiple resolvers
directly (
dig @8.8.8.8,dig @1.1.1.1) rather than relying solely on your local (possibly cached) resolver. - In scripts and monitoring checks, always use
+shortand pin down a specific record type to keep output parseable and predictable. - When documenting DNS troubleshooting steps, prefer
digovernslookup—nslookupis officially deprecated by ISC in favor ofdig/host, even though it's still present on many systems.
Try it yourself
A simulated shell with a sample home directory — experiment freely, nothing leaves your browser. Type help to list supported commands.
Real-world use cases
- Verifying a DNS record change (A, CNAME, MX, TXT) has propagated correctly after updating a zone file or DNS provider's dashboard.
- Diagnosing "why won't this domain resolve" issues by tracing the delegation path with
+traceto find the broken link in the chain. - Checking SPF/DKIM/DMARC TXT records when troubleshooting email deliverability issues.
Common interview questions
- What's the difference between dig and nslookup? dig provides more detailed, protocol-accurate output and is the modern standard; nslookup is older, has quirky default behavior, and is considered deprecated by its own maintainers (ISC) in favor of dig/host.
- How would you find the mail servers for a domain?
dig example.com MX +short. - How does
dig +tracework, and when would you use it? It walks the DNS delegation chain manually, starting from the root servers, through the TLD servers, down to the domain's authoritative nameservers — useful for pinpointing exactly where a delegation is broken.
Frequently Asked Questions
What's the difference between dig and host?
dig gives a much more detailed, protocol-level view (query/answer/authority/additional sections, TTLs, flags) and is the standard tool for serious DNS troubleshooting. host provides a quick, human-readable one-liner answer — faster to read for a simple lookup but less detailed.
How do I get just the IP address without all the extra dig output?
Use `+short`: `dig example.com +short` prints just the resolved value(s), one per line, with no headers or metadata.
How do I check what mail servers handle a domain's email?
`dig example.com MX +short` lists the domain's mail exchanger records along with their priority values.
How do I do a reverse DNS lookup with dig?
`dig -x 8.8.8.8` looks up the PTR record for that IP address, showing the hostname it reverse-resolves to (if one is configured).
Cheat sheet
Download a quick-reference cheat sheet for dig.