Every DNS question you will ever troubleshoot comes down to which server said what, and when. dig answers that directly: it sends one query to one server you choose and prints the full response, including the status code, flags, TTLs, and the address of the server that replied. That precision makes it the fastest way to separate a real DNS fault from a stale cache.

To run a DNS lookup with the dig command, type dig name type @server (for example, dig example.com MX @1.1.1.1), then read the status field, the ANSWER section, and the SERVER line to confirm what came back and who answered. Add +short when you only want values, and switch to +trace or +norecurse against an authoritative server when you need the published truth.
At PacketTools, the same habits drive production work: verifying VPN resolution, checking mail records before a cutover, and proving whether a change has propagated. Once you can read a dig response line by line, you can troubleshoot DNS issues with evidence instead of guesswork.
How Do You Run Your First DNS Query?
Your first query needs only a domain name; dig defaults to an A record and your system resolver. Installation takes one package command on Linux and macOS, and the syntax stays the same on every platform once dig is present.
What Does dig Do?
dig stands for Domain Information Groper. It is a command-line tool that builds a DNS query, sends it to a name server, and prints the reply in nearly raw protocol form. It is a network administration tool that also runs in batch mode, reading requests from a file.
Compared with nslookup, dig exposes the header flags and section counts you need for diagnosis. If you already use the nslookup command for quick checks, think of dig as the tool you reach for when you need to prove where an answer originated.
How Do You Install dig on Linux, macOS, and Windows?
dig ships with BIND 9, the DNS suite maintained by the Internet Systems Consortium. Check first with dig -v; a version string like DiG 9.18.x means you are ready.
| Platform | Install command |
|---|---|
| Debian / Ubuntu | sudo apt install dnsutils (newer releases use bind9-dnsutils) |
| Fedora / RHEL | sudo dnf install bind-utils |
| Arch / Manjaro | sudo pacman -S bind |
| Alpine | apk add bind-tools |
| macOS | Preinstalled; brew install bind for a current build |
| Windows | BIND 9 Windows tools, WSL, or Cygwin |
On Windows, WSL is the least painful path: you get the same Linux package and identical output, which keeps your notes portable.
Basic Syntax: Name, Record Type, Server, and Options
The general form is:
dig [@server] [name] [type] [+options]
@server: the resolver or authoritative server to ask. Omit it and dig uses your system resolver.name: the domain you are querying.type: A, AAAA, MX, TXT, NS, SOA, and so on. Default is A.+options: output and query modifiers such as+short,+trace, or+tcp.
dig parses arguments by shape, so dig MX example.com @8.8.8.8 and dig @8.8.8.8 example.com MX produce the same query.
Get Concise Results with +short and +noall +answer
+short strips everything except values, ideal for scripts and quick checks:
dig example.com +short
For readable output that keeps TTL and record type, use dig +noall +answer:
dig +noall +answer example.com MX
One caution from experience: +short prints nothing for NXDOMAIN, and dig still exits with status zero. In scripts, test the status field or check for empty output explicitly.
How Do You Read DNS Answers and Status Fields?

The status code and the ANSWER count in the header tell you most of the story before you read a single record. The remaining sections, flags, and statistics confirm who answered and how fresh the data is.
Read the Question, Answer, Authority, and Additional Sections
A full response has predictable blocks:
- QUESTION: echoes what you asked (
example.com. IN A). Check it first; a typo here explains many “wrong” answers. - ANSWER: the records matching your question.
- AUTHORITY: NS records in a referral, or an SOA record in a negative answer. Recursive replies frequently leave it empty.
- ADDITIONAL: helper records, such as glue addresses for name servers. The OPT pseudo-record also counts here, which is why you often see
ADDITIONAL: 1with nothing listed.
Interpret Record Values, TTL, Query Time, and the Responding Server
Each answer line reads name TTL class type value. The TTL is the remaining cache lifetime in seconds. Run the same query twice against a caching resolver and you will watch it count down; a TTL that matches the zone’s configured value suggests a fresh fetch.
The statistics block closes the output:
;; Query time: 14 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
A query time near 0 ms means a local cache hit. The SERVER line confirms which resolver replied. If it shows 127.0.0.53, you are talking to systemd-resolved, which forwards upstream on your behalf.
Understand Response Flags and the EDNS OPT Pseudosection
The flags line is where diagnosis happens:
qr: this is a response.rd: recursion desired (you asked for it).ra: recursion available (the server offers it).aa: authoritative answer, straight from a server hosting the zone.ad: authenticated data, meaning the resolver validated DNSSEC.
The OPT pseudosection shows EDNS details such as udp: 1232, the largest UDP payload the server accepts. Very small values or missing EDNS on modern servers point to middleboxes mangling DNS traffic.
Distinguish NOERROR, Empty Answers, NXDOMAIN, SERVFAIL, and REFUSED
| Status | What it means | Where to look next |
|---|---|---|
| NOERROR with answers | Success | Verify values and TTL |
| NOERROR, ANSWER: 0 | Name exists, no records of that type | Query other types; check SOA in AUTHORITY |
| NXDOMAIN | Name does not exist | Spelling, zone contents, delegation |
| SERVFAIL | Resolver could not complete the lookup | DNSSEC failures, unreachable authoritative servers |
| REFUSED | Server declined to answer you | ACLs, querying an authoritative server for a zone it does not host |
NXDOMAIN is the code behind a browser’s DNS_PROBE_FINISHED_NXDOMAIN error, and SERVFAIL frequently surfaces to users as a generic DNS lookup failed message. Testing the same name against a second resolver tells you whether the failure is global or local.
Which DNS Record Types Should You Query?
Query the specific type tied to your symptom: A and AAAA for reachability, MX and TXT for mail, NS and SOA for zone health, PTR for reverse lookups. For the full catalog of DNS record types, the essentials below cover nearly every ticket.
Check IPv4, IPv6, and Aliases with A, AAAA, and CNAME
dig +short example.com A
dig +short example.com AAAA
dig +noall +answer www.example.com CNAME
A records return IPv4 addresses; AAAA returns IPv6. When a site works for some users and fails for others, check AAAA first: a stale or unreachable IPv6 address breaks dual-stack clients while IPv4-only clients connect fine.
A CNAME query against a name with its own A records returns an empty answer, which is normal. When you query A on an alias, dig shows the CNAME followed by the target’s addresses, so +short output can mix a hostname with IPs.
Inspect MX and TXT Records for Email Troubleshooting
dig +noall +answer example.com MX
dig +short example.com TXT
dig +short selector1._domainkey.example.com TXT
dig +short _dmarc.example.com TXT
In MX output, the lower preference number wins. dig prints records in whatever order the resolver returned them, so sort by the number yourself.
For TXT, look for exactly one record starting with v=spf1. Two SPF records cause a permerror at receivers, a mistake that shows up constantly after migrations to Microsoft 365.
Find Authoritative Name Servers and Zone Details with NS and SOA
dig +noall +answer example.com NS
dig example.com SOA +multiline
The NS list tells you which servers to question directly later. The SOA record holds the primary server, the admin contact, and the serial number. +multiline labels each SOA timer, so you can read refresh, retry, expire, and negative-cache TTL without counting fields.
Run Reverse DNS Lookups with dig -x and PTR Records
dig -x 8.8.8.8 +short
-x builds a PTR query for the reversed address under in-addr.arpa (or ip6.arpa for IPv6). Reverse records matter most for outbound mail servers, where receivers expect the PTR to match a forward A record. The owner of the IP block controls the PTR, so fixes often go through your hosting provider or ISP.
Why ANY Does Not Return Every DNS Record
ANY was once a shortcut for listing everything at a name. Because it was abused for amplification attacks, RFC 8482 lets servers return a minimal response, and some public resolvers reject it with NOTIMP. Query each type individually when you need a complete picture.
How Do You Compare Resolvers and Trace Authoritative Answers?

Pointing dig at different servers isolates whether a problem lives in a cache, a resolver, or the authoritative zone itself. Your local resolver, public resolvers, and the zone’s own name servers each answer from a different vantage point.
How Default Resolver Selection Uses /etc/resolv.conf
With no @server, dig reads the nameserver lines in /etc/resolv.conf. On modern Ubuntu that file points to 127.0.0.53, so the real upstream lives elsewhere; run resolvectl status to see it. On macOS, scutil --dns shows the effective resolvers, including per-domain VPN entries that resolv.conf does not reflect.
Compare Google Public DNS, Cloudflare DNS, and Your Local Resolver
dig +noall +answer example.com
dig @8.8.8.8 +noall +answer example.com
dig @1.1.1.1 +noall +answer example.com
Matching answers with different TTLs mean each resolver cached the record at different times. Different values usually mean split-horizon DNS (internal versus external views) or a resolver still holding old data. Some corporate and guest networks silently redirect port 53, so if every resolver returns identical odd results, test from another network.
Query an Authoritative Name Server Directly with +norecurse
dig @ns1.example-dns.net example.com A +norecurse
An authoritative reply carries the aa flag and the zone’s configured TTL. That is the published record with no cache in between. Point +norecurse at a recursive resolver instead and you see only what it already has cached, a handy way to inspect whether an old value is still sitting there.
How Recursive Queries Differ from +trace
A normal query asks your resolver to do the work and hand back a final answer. That is DNS recursion: you see the result, never the steps.
+trace makes dig itself act as the resolver. It starts at the root servers, follows the referral to the TLD servers, then to the zone’s authoritative servers, printing each hop and the server that replied. Where the staircase stops is where resolution breaks. Modern BIND builds enable +dnssec during traces, so expect RRSIG lines in the output.
Diagnose Stale Caches, Delegation Problems, and Propagation Differences
Use this sequence:
- Query the authoritative servers. If they show the old value, the zone was never updated.
- If authoritative is correct but a resolver is wrong, wait out the cached TTL.
- If
+tracefails at the TLD step, the NS records at the registrar do not match your hosting; review your DNS delegation. - Query every NS for the zone and compare SOA serials; a lagging secondary serves old data to a fraction of users.
To see many resolvers worldwide at once, the PacketTools DNS propagation checker complements these spot checks.
A Practical dig Cheatsheet for Repeatable Checks
A short set of saved commands turns ad hoc lookups into consistent checks you can compare across days. Transport options, DNSSEC flags, and batch files cover the cases basic queries miss.
Reusable Commands for Common Diagnostic Tasks
| Task | Command |
|---|---|
| Quick address | dig +short example.com |
| Readable answer | dig +noall +answer example.com |
| Specific resolver | dig @1.1.1.1 example.com |
| Mail records | dig +noall +answer example.com MX |
| Zone servers | dig +short example.com NS |
| SOA serial | dig +short example.com SOA |
| Reverse lookup | dig -x 203.0.113.10 +short |
| Delegation path | dig +trace example.com |
Put favorite defaults like +noall +answer in ~/.digrc, and use dig -r in scripts to ignore that file.
Check TCP, Transport Address Families, Timeouts, and Retries
dig +tcp example.com
dig -4 example.com
dig -6 example.com
dig +time=2 +tries=1 example.com
If UDP works but +tcp times out, a firewall is blocking TCP 53, which breaks large responses and DNSSEC. The DNS TCP or UDP behavior matters more than most teams expect. -4 and -6 force the transport, isolating broken IPv6 paths to the resolver. Short timeouts keep scripts from hanging on dead servers.
Request DNSSEC Data Without Assuming Local Validation
dig +dnssec example.com requests RRSIG records, but dig does not validate them. Trust comes from the ad flag, set by a validating resolver. If a domain returns SERVFAIL, rerun with +cd (checking disabled): an answer with +cd and SERVFAIL without it points to a broken signature or DS record.
Run Batch Queries and Use TSIG Key Files Safely
dig -f queries.txt runs one query per line, handy for auditing dozens of hostnames after a migration. For zone transfers or signed queries, pass a key with -k keyfile. Avoid -y on shared systems because the secret appears in shell history and process lists; keep key files at chmod 600.
Cross-Check Results with PacketTools DNS and Email Tools
dig shows your view from one machine. The PacketTools SuperTool runs DNS, MX, SPF, DKIM, DMARC, blacklist, and SSL checks in one pass from an outside vantage point, with no IPs, queries, or test data logged or stored. Comparing both views quickly reveals split-horizon or local-cache issues.
Verify the Answer, the Resolver, and the Authoritative Source
A reliable DNS lookup confirms three things: the record value, the resolver that delivered it, and what the authoritative servers publish. Read the status field and ANSWER count first, then check the SERVER line so you know whose cache you are seeing.
When resolution looks wrong, move outward step by step. Compare your local resolver against @8.8.8.8 and @1.1.1.1, query an authoritative name server with +norecurse, and run +trace to find where delegation stops. Matching authoritative data with a mismatched resolver means waiting out the TTL; mismatched authoritative servers mean fixing the zone or registrar.
Keep +short for scripts, +noall +answer for reading, and the full output for diagnosis. When DNS propagation is in question, compare SOA serials across every listed name server before declaring the change live.

Leave a Reply