dig — Query DNS Records from the Command Line

Practical guide to dig — DNS lookups, record types, reverse lookup, DNSSEC and tracing on the command line, with examples for the most common diagnostic scenarios.

dig is the go-to tool for DNS diagnostics on the command line: a single command lets you look up individual records, verify mail server configuration, trace the full delegation chain to the authoritative nameserver, or validate DNSSEC signatures. It ships as part of the BIND package and is pre-installed on virtually every Unix system. This guide covers the options you reach for most – from a quick A-record lookup to a full zone transfer.

Basic Queries

dig DOMAIN — Query the A record (IPv4 address) of a domain using default DNS server.

dig example.com

dig DOMAIN TYPE — Query a specific record type (A, AAAA, MX, NS, TXT, CNAME, SOA, SRV, CAA, PTR, etc.).

dig example.com MX

dig @SERVER DOMAIN — Query a specific DNS server.

dig @8.8.8.8 example.com

dig @SERVER DOMAIN TYPE — Query a specific record type from a specific server.

dig @1.1.1.1 example.com AAAA

dig DOMAIN ANY — Query all available record types. Note: many servers restrict ANY queries.

dig example.com ANY

Common Record Types

dig DOMAIN A — IPv4 address record.

dig example.com A

dig DOMAIN AAAA — IPv6 address record.

dig example.com AAAA

dig DOMAIN MX — Mail exchange records. Shows mail servers and priorities.

dig example.com MX

dig DOMAIN NS — Nameserver records. Shows authoritative DNS servers.

dig example.com NS

dig DOMAIN TXT — Text records. Often contains SPF, DKIM, DMARC, and verification records.

dig example.com TXT

dig DOMAIN SOA — Start of Authority. Shows primary nameserver, admin email, serial, and timers.

dig example.com SOA

dig DOMAIN CNAME — Canonical name (alias) record.

dig www.example.com CNAME

dig DOMAIN SRV — Service record. Used for service discovery (e.g., SIP, XMPP, LDAP).

dig _sip._tcp.example.com SRV

dig DOMAIN CAA — Certificate Authority Authorization. Shows which CAs can issue certificates.

dig example.com CAA

Output Control

dig +short DOMAIN — Short output — only the answer, no headers or metadata.

dig +short example.com

dig +short DOMAIN TYPE — Short output for a specific record type.

dig +short example.com MX

dig +noall +answer DOMAIN — Show only the answer section. Clean but with field details.

dig +noall +answer example.com

dig +noall +answer +authority DOMAIN — Show answer and authority sections.

dig +noall +answer +authority example.com NS

dig +nocomments +noquestion +noauthority +noadditional +nostats DOMAIN — Suppress all sections except the answer.

dig +nocomments +noquestion +noauthority +noadditional +nostats example.com

dig +multiline DOMAIN SOA — Multi-line output with comments. Useful for SOA and DNSSEC records.

dig +multiline example.com SOA

dig +yaml DOMAIN — Output in YAML format (dig 9.18+).

dig +yaml example.com

dig +json DOMAIN — Output in JSON format (dig 9.18+).

dig +json example.com

Reverse DNS Lookup

dig -x IP — Reverse DNS lookup — find the hostname for an IP address.

dig -x 8.8.8.8

dig -x IP +short — Short reverse lookup — hostname only.

dig -x 8.8.8.8 +short

dig -x IPV6 — Reverse lookup for an IPv6 address.

dig -x 2001:4860:4860::8888

Tracing & Debugging

dig +trace DOMAIN — Trace the full delegation path from root servers to the authoritative server.

dig +trace example.com

dig +trace +nodnssec DOMAIN — Trace without DNSSEC records for cleaner output.

dig +trace +nodnssec example.com

dig +stats DOMAIN — Show query statistics (time, server, message size).

dig +stats example.com

dig +qr DOMAIN — Show the outgoing query alongside the response.

dig +qr example.com

dig +identify DOMAIN — Show the responding server for +short queries.

dig +short +identify example.com

DNSSEC

dig +dnssec DOMAIN — Request DNSSEC records (RRSIG, DNSKEY, DS, NSEC).

dig +dnssec example.com

dig DOMAIN DNSKEY — Query DNSSEC public keys for a domain.

dig example.com DNSKEY

dig DOMAIN DS — Query Delegation Signer records (links child to parent zone).

dig example.com DS

dig +dnssec +multiline DOMAIN DNSKEY — Show DNSSEC keys with multi-line formatting and key IDs.

dig +dnssec +multiline example.com DNSKEY

dig +cd DOMAIN — Disable DNSSEC checking (CD flag). Get answer even if validation fails.

dig +cd example.com

dig +sigchase DOMAIN — Chase DNSSEC signature chain (if supported by your dig version).

dig +sigchase example.com

Network Options

dig +tcp DOMAIN — Use TCP instead of UDP for the query.

dig +tcp example.com

dig +notcp DOMAIN — Force UDP (default).

dig +notcp example.com

dig -4 DOMAIN — Force IPv4 transport only.

dig -4 example.com

dig -6 DOMAIN — Force IPv6 transport only.

dig -6 example.com

dig -p PORT @SERVER DOMAIN — Use a non-standard DNS port.

dig -p 5353 @127.0.0.1 example.com

dig +time=SECONDS DOMAIN — Set the query timeout in seconds (default: 5).

dig +time=10 example.com

dig +retry=N DOMAIN — Set the number of retries (default: 2).

dig +retry=5 example.com

dig +bufsize=N DOMAIN — Set the EDNS UDP buffer size (for large responses).

dig +bufsize=4096 example.com

Batch & Multi-Query

dig DOMAIN1 DOMAIN2 DOMAIN3 — Query multiple domains in a single invocation.

dig google.com github.com example.com

dig -f FILE — Read domains from a file (one per line) and query each.

dig -f domains.txt

dig +short DOMAIN A DOMAIN AAAA DOMAIN MX — Query multiple record types for a domain.

dig +short example.com A example.com AAAA example.com MX

Zone Transfer

dig @NS DOMAIN AXFR — Request a full zone transfer (requires authorization).

dig @ns1.example.com example.com AXFR

dig @NS DOMAIN IXFR=SERIAL — Request an incremental zone transfer from a given serial number.

dig @ns1.example.com example.com IXFR=2024010101

Common Patterns

dig +short DOMAIN NS | while read ns; do echo "$ns:"; dig +short @$ns DOMAIN; done — Check if all nameservers return the same answer.

dig +short example.com NS | while read ns; do echo "$ns:"; dig +short @$ns example.com; done

dig +short DOMAIN TXT | grep 'v=spf' — Check SPF record for a domain.

dig +short example.com TXT | grep 'v=spf'

dig +short _dmarc.DOMAIN TXT — Check DMARC policy for a domain.

dig +short _dmarc.example.com TXT

dig +short SELECTOR._domainkey.DOMAIN TXT — Check a DKIM record.

dig +short google._domainkey.example.com TXT

dig +noall +answer +ttlid DOMAIN — Check the remaining TTL of a cached record.

dig +noall +answer example.com

dig @ns1.DOMAIN DOMAIN SOA +short — Get the zone serial number directly from the authoritative server.

dig @ns1.example.com example.com SOA +short

Conclusion

dig is indispensable for anyone who needs to diagnose DNS issues quickly or verify configurations. Combined with +short for scripts and +trace for the full delegation chain, it covers virtually every DNS diagnostic scenario – no GUI, no unnecessary dependencies.

Further Reading

  • nslookup – simple DNS queries, interactive or one-shot
  • host – compact DNS lookup tool for quick answers
  • ping – check reachability once DNS has resolved