Skip to content

/cheatsheets/dig/dig-cheat-sheet

dig cheat sheet: DNS lookups from the command line

The commands on this page have not been executed by our verification runner yet.updated
tool
dig / nslookup
versions
BIND 9
os
linux, macos, windows

dig NAME asks the system's DNS resolver for the A record of NAME and prints the full response; dig +short NAME prints only the answer. Add a record type (dig NAME MX), a server (dig @1.1.1.1 NAME) or +trace to follow the delegation from the root servers. dig is part of BIND 9 (package dnsutils or bind-utils on Linux).

Basic lookups

CommandWhat it does
dig example.comA record, full output (question, answer, authority, statistics)
dig +short example.comOnly the answer values
dig example.com AAAAIPv6 address
dig example.com MXMail servers
dig example.com TXTTXT records (SPF, domain verification)
dig example.com NSName servers of the zone
dig example.com SOAStart of authority: primary server, serial, timers
dig www.example.com CNAMEAlias target
dig _sip._tcp.example.com SRVService records
dig -x 192.0.2.10Reverse lookup (PTR) for an IP address

Choose the server and transport

CommandWhat it does
dig @1.1.1.1 example.comAsk a specific resolver instead of the system one
dig @ns1.example.com example.comAsk the authoritative server directly (bypasses caches)
dig +tcp example.comUse TCP instead of UDP
dig -p 5353 @127.0.0.1 example.comNon-standard port
dig -4 example.com / dig -6 example.comForce IPv4 or IPv6 transport
dig +https @1.1.1.1 example.comDNS over HTTPS (BIND 9.18 and later)

Control the output

OptionEffect
+shortAnswer values only
+noall +answerAnswer section only, in zone-file format with TTLs
+traceFollow the delegation from the root servers to the authoritative answer
+dnssecRequest DNSSEC records (RRSIG) with the answer
+norecurseDo not ask for recursion (see what a server knows itself)
+nocmd +nostatsDrop the header line and the statistics
-f names.txtBatch mode: one query per line from a file

Read the status

The header line ;; ->>HEADER<<- opcode: QUERY, status: NOERROR tells you how the server answered:

StatusMeaning
NOERRORThe name exists. An empty answer section means it has no record of the requested type
NXDOMAINThe name does not exist
SERVFAILThe resolver could not get an answer (broken delegation, DNSSEC validation failure, unreachable servers)
REFUSEDThe server refuses to answer this client (for example a resolver that only serves its own network)

Troubleshooting recipes

bash
# does the change appear at the authoritative server? (compare the SOA serial)
dig +short example.com SOA @ns1.example.com
# is a resolver still caching the old value? (the TTL counts down)
dig +noall +answer example.com @8.8.8.8
# where does resolution break?
dig +trace example.com

On Windows, dig is included in the BIND 9 tools; nslookup and PowerShell's Resolve-DnsName are the built-in alternatives.

Sources