Networking & DNS

The dig command: DNS lookups explained with examples

Use dig to query A, MX, TXT, NS and other records, ask a specific nameserver, trace delegation from the root and check propagation, SPF, DKIM and DNSSEC.

IntermediateAny domain3 min read

When a domain points to the wrong server or email will not arrive, the dig command shows exactly what DNS returns and which server said it. It is more precise than nslookup or online checkers, and these dig examples cover nearly every DNS problem you will meet in hosting.

Before you start

  • Linux/macOS have dig (install dnsutils or bind-utils if missing). On Windows, use WSL or install BIND tools; Resolve-DnsName in PowerShell is a close alternative.
  • The domain you want to test.

Basic lookup

dig example.com

The important part is the ANSWER SECTION:

;; ANSWER SECTION:
example.com.   3600  IN  A  203.0.113.10

That is name, TTL in seconds (how long resolvers may cache it), class, record type and value. The footer shows which resolver answered (SERVER:) and the query time.

For just the value, add +short:

dig +short example.com

Query specific record types

CommandShows
dig example.com AIPv4 address
dig example.com AAAAIPv6 address
dig example.com MX +shortMail servers and priority
dig example.com TXT +shortSPF, verification and other text records
dig example.com NS +shortNameservers
dig www.example.com CNAME +shortAlias target
dig example.com CAA +shortWhich CAs may issue SSL certificates
dig -x 203.0.113.10 +shortReverse DNS (PTR) for an IP

Ask a specific DNS server

Your local resolver may have an old answer cached. Ask a public resolver or, better, the domain's authoritative nameserver directly:

dig @1.1.1.1 example.com +short
dig @ns1.example-dns.com example.com +short

If the authoritative server shows the new IP but public resolvers show the old one, the change is correct and you are waiting for caches to expire (the old TTL).

Trace delegation from the root

dig +trace example.com

dig walks from the root servers to the TLD servers to your nameservers, ignoring caches. Use it when you changed nameservers at the registrar: the TLD step shows which nameservers the registry actually has.

Check email DNS records

  • SPF: dig example.com TXT +short | grep spf (there must be only one SPF record).
  • DKIM: dig default._domainkey.example.com TXT +short (replace default with your selector).
  • DMARC: dig _dmarc.example.com TXT +short

Check DNSSEC

dig example.com +dnssec

The ad flag in the header (when using a validating resolver like 1.1.1.1) means the answer was DNSSEC-validated. A SERVFAIL from validating resolvers but a normal answer with +cd (checking disabled) points to broken DNSSEC, often a stale DS record after changing DNS providers.

Read status codes

  • NOERROR with answers: record exists.
  • NOERROR without answers: the name exists but has no record of that type.
  • NXDOMAIN: the name does not exist.
  • SERVFAIL: the resolver could not get a valid answer (nameserver down, DNSSEC failure, lame delegation).
  • REFUSED: the server will not answer for that zone; often a nameserver that does not host the domain.

Troubleshooting with dig

  • Site shows the old server: compare dig @authoritative with dig @8.8.8.8; wait out the TTL or flush local DNS.
  • Nameserver change not working: dig +trace shows whether the registry has the new nameservers.
  • Email bouncing: verify MX targets resolve to A records (MX must not point to a CNAME or IP).

dig FAQ

dig vs nslookup?

Both query DNS. dig gives fuller, script-friendly output and is the standard for troubleshooting; nslookup is available by default on Windows.

How do I check DNS propagation?

Query several public resolvers (1.1.1.1, 8.8.8.8, 9.9.9.9) with +short and compare them to the authoritative answer.

Why does dig show a different IP than my browser?

Your browser or OS may cache DNS, or use DNS-over-HTTPS with a different resolver.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.