The dig command in Linux

dig (domain information groper) sends DNS queries and prints the full answer, including which server replied and how long it took. When "the site is down" is actually "the name doesn't resolve", dig is the instrument that proves it — and during DNS migrations it is how you watch the new records propagate.

How dig works

dig builds a DNS query packet and sends it — UDP port 53 by default, retrying over TCP when the answer is too large and arrives truncated. The reply's sections mirror the protocol: ANSWER holds the records you asked for, AUTHORITY names the servers responsible, ADDITIONAL carries helper records. The status (NOERROR, NXDOMAIN, SERVFAIL) and the "Query time" line make dig a protocol instrument, not just a lookup tool.

The resolution world has two kinds of servers, and dig lets you interrogate both. Recursive resolvers (your ISP's, 8.8.8.8) chase answers on your behalf and cache them subject to each record's TTL — the reason changes propagate gradually. Authoritative servers hold the zone's truth. dig @resolver shows what the world currently believes; dig @authoritative shows what it should believe; +trace walks the whole delegation from the root, exposing exactly which link in the chain is broken.

Syntax

dig [@SERVER] NAME [TYPE]

Common options

OptionWhat it does
A / AAAAIPv4 / IPv6 address records (A is the default type).
MXMail exchangers for the domain.
TXTText records: SPF, verification tokens, DKIM.
NSThe authoritative name servers.
@8.8.8.8Ask a specific server instead of the system resolver.
+shortJust the answer values, nothing else.
+traceWalk the delegation from the root — see the whole resolution path.

How to use dig: examples

$ dig example.com +short

The IP(s) behind a name, and nothing more.

$ dig example.com MX +short

Where this domain's mail goes.

$ dig @8.8.8.8 example.com

Bypass your local resolver: is the record wrong everywhere, or only in your cache?

$ dig example.com +trace

Follow resolution from the root servers down — the tool for "which delegation is broken?".

$ dig -x 93.184.216.34 +short

Reverse lookup: the name registered for an IP.

Real-world use cases for dig

Watching a migration propagate

After changing an A record: dig @authoritative-ns example.com confirms the zone is right, then dig @8.8.8.8 and dig @1.1.1.1 show which public resolvers have picked it up as TTLs expire. No more "clear your cache and pray".

Verifying mail configuration

Deliverability audit in three queries: dig domain MX (where mail goes), dig domain TXT (SPF policy), dig selector._domainkey.domain TXT (DKIM key). Most "our emails go to spam" tickets are solved staring at exactly these three answers.

Pro tips and common mistakes

Frequently asked questions about dig

My DNS change is not visible — why?

Caches. Every record carries a TTL, and resolvers serve the old value until it expires. Query the authoritative server directly (dig @ns1.provider.com name) to confirm the change itself is live.

What is the difference between dig and nslookup?

Same job; dig gives more complete, script-friendly output and is the standard on Linux. nslookup survives mainly on Windows.

What does SERVFAIL / NXDOMAIN mean?

NXDOMAIN: the name does not exist. SERVFAIL: the resolver failed to get an answer (often broken delegation or DNSSEC). They point to different culprits.

Related commands

curl

Download files, test APIs, send POST requests with JSON, and inspect headers.

ping

Check whether a host is reachable and measure round-trip latency.

ip

The modern tool for addresses, links and routes — replacing ifconfig and route.

Want to build real fluency? The interactive course takes you through dig and every other essential command with guided, checked exercises.