SkillPilotAI

dig and delv

dig prints the full DNS message (header, flags, sections, TTL, query time) and is the standard tool for DNS troubleshooting and scripting. delv fetches the same answer but validates the DNSSEC chain of trust itself before trusting it.

85.1 Why is it used?

  • See exactly what a server answered: status, flags (aa, ad, cd, ra), every section and TTL.
  • Follow the delegation chain from the root with +trace to catch a wrong NS or glue record.
  • Test transports: UDP, TCP, DoT, DoH; test EDNS, zone transfers, TSIG.
  • delv proves whether an answer is DNSSEC-valid and shows why validation fails.
OSHow to get it
Linuxbind9-dnsutils / bind-utils (dig + delv)
macOSdig built in but old; brew install bind for newer options
WindowsNot built in: ISC BIND tools or WSL
Labpc 192.168.105.10 (dig/delv 9.18.25), ns1 192.168.105.53 (BIND 9.18.49, signed zone shop.lab)

85.2 How it works

dig +trace: delegation chain from the root
  1. 1.dig gets the root NS list (here from the lab server)

  2. 2.Asks l.root-servers.net -> referral to the com servers

  3. 3.Asks c.gtld-servers.net -> referral to elliott.ns.cloudflare.com

  4. 4.Asks the authoritative server -> final A records for example.com

dig itself walks the chain; no resolver cache involved

delv: checking the chain of trust
  1. 1.Fetch A, DNSKEY, DS records + RRSIGs (here via 8.8.8.8)

  2. 2.Start at the root trust anchor

  3. 3.Verify DS and DNSKEY of com

  4. 4.Verify DS and DNSKEY of example.com

  5. 5.Verify the RRSIG of the A record -> "fully validated"

85.3 dig basic usage

Terminal
dig www.shop.labdig @8.8.8.8 example.com MXdig version.bind TXT CHdig +noall +answer . NS | head -3dig +qr www.shop.lab A -x 192.168.105.80 \  shop.lab ns +noqr
Output
$ dig www.shop.lab;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44592;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1;; ANSWER SECTION:www.shop.lab.  300  IN  A  192.168.105.80;; Query time: 15 msec;; SERVER: 192.168.105.53#53(192.168.105.53) (UDP)$ dig @8.8.8.8 example.com MX;; flags: qr rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1example.com.  206  IN  MX  0 .;; SERVER: 8.8.8.8#53(8.8.8.8) (UDP)$ dig version.bind TXT CHversion.bind.  0  CH  TXT  "n085 lab DNS"$ dig +noall +answer . NS | head -3.  259182  IN  NS  l.root-servers.net..  259182  IN  NS  m.root-servers.net..  259182  IN  NS  k.root-servers.net.$ dig +qr www.shop.lab A -x 192.168.105.80 shop.lab ns +noqr;; Sending:;; flags: rd ad; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1www.shop.lab.  300  IN  A  192.168.105.8080.105.168.192.in-addr.arpa. 300 IN  PTR  www.shop.lab.shop.lab.  300  IN  NS  ns1.shop.lab.
  • No server given -> uses resolv.conf; @server sends directly to it. Type and class are positional after the name.
  • aa = authoritative (ns1 owns shop.lab); ad = validated by the resolver (8.8.8.8).
  • No arguments -> NS of the root zone. One line can run several queries.

85.4 dig command-line options

Terminal
dig -x 192.168.105.80 +shortdig -t AXFR shop.lab +onesoadig -k /root/xfr.key -t AXFR shop.lab \  +onesoa +nocryptodig -c CH -t TXT version.bind +shortdig -p 5353 www.shop.lab +shortdig -u www.shop.lab | grep "Query time"
Output
$ dig -x 192.168.105.80 +shortwww.shop.lab.$ dig -t AXFR shop.lab +onesoa; <<>> DiG 9.18.25 <<>> -t AXFR shop.lab +onesoa;; global options: +cmd; Transfer failed.$ dig -k /root/xfr.key -t AXFR shop.lab +onesoa +nocryptoshop.lab.  300  IN  SOA  ns1.shop.lab. admin.shop.lab. 2026110904 3600 600 86400 300shop.lab.  3600  IN  DNSKEY  257 3 13 [key id = 44243]shop.lab.  300  IN  MX  10 mail.shop.lab.mail.shop.lab.  300  IN  A  192.168.105.25www.shop.lab.  300  IN  A  192.168.105.80;; SERVER: 192.168.105.53#53(192.168.105.53) (TCP);; XFR size: 31 records (messages 1, bytes 2214)$ dig -c CH -t TXT version.bind +short"n085 lab DNS"$ dig -p 5353 www.shop.lab +short192.168.105.80$ dig -u www.shop.lab | grep "Query time";; Query time: 546 usec
OptionMeaning
-x addrReverse lookup (PTR)
-t TYPE / -t TYPE65 / -t IXFR=serialRecord type, by number, incremental transfer
-c CH / -c HSClass (default IN)
-k file / -y h:name:keyTSIG key from file / inline (inline shows in shell history, prefer -k)
-p port, -b IP#portServer port, source address
-f fileBatch: one query per line
-4 / -6, -u, -r, -q nameIP version, microseconds, skip ~/.digrc, explicit query name

85.5 Query header flags

Terminal
dig example.com +norecursedig www.shop.lab +norecursedig @8.8.8.8 dnssec-failed.orgdig @8.8.8.8 dnssec-failed.org +cddig +qid=1234 www.shop.lab
Output
$ dig example.com +norecurse;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20200;; flags: qr ra; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 1$ dig www.shop.lab +norecurse;; flags: qr aa ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2$ dig @8.8.8.8 dnssec-failed.org;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 64622$ dig @8.8.8.8 dnssec-failed.org +cd;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8677;; flags: qr rd ra cd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1$ dig +qid=1234 www.shop.lab;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1234
Flag optionEffect
+[no]recurse / +[no]rdflagRD bit; +norecurse -> only cache/referral (13 root NS in AUTHORITY)
+cd / +[no]cdflagChecking disabled: resolver skips DNSSEC validation
+[no]adflagAD bit in the query (default on)
+[no]aaonly / +aaflagAsk for an authoritative-only answer
+opcode=NOTIFY, +qid=NOpcode, fixed query ID
+header-onlySend only the header (QUERY: 0)
+[no]coflagBIND 9.20 option: invalid in dig 9.18

85.6 Transport, retries and timing

Terminal
dig +tcp www.shop.labdig @192.168.105.99 www.shop.lab \  +timeout=1 +tries=1
Output
$ dig +tcp www.shop.lab;; SERVER: 192.168.105.53#53(192.168.105.53) (TCP)$ dig @192.168.105.99 www.shop.lab +timeout=1 +tries=1;; communications error to 192.168.105.99#53: timed out;; no servers could be reached[exit 9]
  • +timeout=1 +tries=1 is the fail-fast combo for scripts; exit code 9 = no reply.
  • Defaults: timeout 5 s, tries 3, retry 2. +fail tries the next server after SERVFAIL, +ignore keeps a truncated UDP answer instead of retrying over TCP, +keepopen reuses one TCP socket.

85.7 Encrypted and HTTP transports (DoT / DoH)

Terminal
dig +tls @1.1.1.1 example.comdig +https @1.1.1.1 example.comdig +tls-ca +tls-hostname=one.one.one.one \  @1.1.1.1 example.com +shortdig +tls-ca +tls-hostname=wrong.example \  @1.1.1.1 example.com +shortdig +http-plain @192.168.105.53 www.shop.lab
Output
$ dig +tls @1.1.1.1 example.com;; SERVER: 1.1.1.1#853(1.1.1.1) (TLS)$ dig +https @1.1.1.1 example.com;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 45165;; SERVER: 1.1.1.1#443(1.1.1.1) (HTTPS)$ dig +tls-ca +tls-hostname=one.one.one.one @1.1.1.1 example.com +short104.20.23.154172.66.147.243$ dig +tls-ca +tls-hostname=wrong.example @1.1.1.1 example.com +short;; TLS peer certificate verification for 1.1.1.1#853 failed: hostname mismatch$ dig +http-plain @192.168.105.53 www.shop.lab;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47587;; SERVER: 192.168.105.53#80(192.168.105.53) (HTTP)
  • +tls = DoT on 853, +https = DoH (POST to /dns-query) on 443; +https-get uses GET.
  • +tls-ca verifies the certificate, +tls-hostname sets the name to check; +tls-certfile / +tls-keyfile for client certificates.
  • +http-plain = DNS over plain HTTP on port 80 (no encryption, lab only).

85.8 EDNS options

Terminal
dig +nsid www.shop.labdig +subnet=203.0.113.0/24 @8.8.8.8 \  example.comdig +dnssec www.shop.lab +noall +answerdig +edns=1 www.shop.lab +noednsnegotiation
Output
$ dig +nsid www.shop.lab; EDNS: version: 0, flags:; udp: 1232; NSID: 6e 30 38 35 2d 6e 73 ("n085-ns")$ dig +subnet=203.0.113.0/24 @8.8.8.8 example.com; CLIENT-SUBNET: 203.0.113.0/24/0$ dig +dnssec www.shop.lab +noall +answer +nocryptowww.shop.lab.  300  IN  A  192.168.105.80www.shop.lab.  300  IN  RRSIG  A 13 3 300 20261122121609 20261108212522 44243 shop.lab. [omitted]$ dig +edns=1 www.shop.lab +noednsnegotiation;; ->>HEADER<<- opcode: QUERY, status: BADVERS, id: 58237; EDNS: version: 0, flags:; udp: 1232
  • EDNS adds an OPT record carrying newer options. +nsid = server ID, +subnet = EDNS Client Subnet, +dnssec / +do = DO bit (get RRSIGs).
  • BADVERS: the server only speaks EDNS version 0.
  • Others: +bufsize=512 (UDP size), +noedns (no OPT), +padding=128 (hide query size with TLS), +cookie, +keepalive, +expire.

85.9 Lookup behaviour

Terminal
dig +trace example.com +nodnssecdig +search www +shortdig +nosearch wwwdig +nssearch example.com
Output
$ dig +trace example.com +nodnssec;; Received 279 bytes from 192.168.105.53#53(192.168.105.53) in 4 ms;; Received 836 bytes from 199.7.83.42#53(l.root-servers.net) in 128 ms;; Received 359 bytes from 192.26.92.30#53(c.gtld-servers.net) in 140 msexample.com.  300  IN  A  172.66.147.243example.com.  300  IN  A  104.20.23.154;; Received 72 bytes from 108.162.195.228#53(elliott.ns.cloudflare.com) in 44 ms$ dig +search www +short192.168.105.80$ dig +nosearch www;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 6354$ dig +nssearch example.comSOA elliott.ns.cloudflare.com. dns.cloudflare.com. 2418004112 10000 2400 604800 1800 from server 173.245.58.162 in 27 ms.SOA elliott.ns.cloudflare.com. dns.cloudflare.com. 2418004112 10000 2400 604800 1800 from server 108.162.195.228 in 35 ms.SOA elliott.ns.cloudflare.com. dns.cloudflare.com. 2418004112 10000 2400 604800 1800 from server 108.162.192.162 in 31 ms.
  • +nssearch: SOA serial from every authoritative server; different serials = servers out of sync.
  • +ndots=D sets how many dots make a name absolute; +showsearch prints each search try.
  • +sigchase, +topdown, +trusted-key were removed: use delv.

85.10 Output control

Terminal
dig +short +identify api.shop.labdig +noall +answer shop.lab MXdig +multiline +noall +answer shop.lab SOAdig +ttlunits +noall +answer @8.8.8.8 \  example.com NSdig +yaml www.shop.lab | head -12
Output
$ dig +short +identify api.shop.labwww.shop.lab. from server 192.168.105.53 in 0 ms.192.168.105.80 from server 192.168.105.53 in 0 ms.$ dig +noall +answer shop.lab MXshop.lab.  300  IN  MX  10 mail.shop.lab.$ dig +multiline +noall +answer shop.lab SOAshop.lab.  300 IN SOA ns1.shop.lab. admin.shop.lab. (  2026110904 ; serial  3600       ; refresh (1 hour)  600        ; retry (10 minutes)  86400      ; expire (1 day)  300        ; minimum (5 minutes)  )$ dig +ttlunits +noall +answer @8.8.8.8 example.com NSexample.com.  6h  IN  NS  hera.ns.cloudflare.com.example.com.  6h  IN  NS  elliott.ns.cloudflare.com.$ dig +yaml www.shop.lab | head -12-  type: MESSAGE  message:    type: RECURSIVE_RESPONSE    message_size: 85b    socket_protocol: UDP    response_address: "192.168.105.53"    response_port: 53
  • +short for scripts, +noall +answer for clean answers, +yaml for machine-readable output.
  • Section switches: +[no]answer, +[no]authority, +[no]additional, +[no]question, +[no]comments, +[no]cmd, +[no]stats.
  • +nocrypto hides long signatures, +onesoa prints one SOA in AXFR, +noclass / +nottlid drop columns.

85.11 delv: command-line and query options

Terminal
delv @8.8.8.8 example.comdelv -a /root/anchors.conf @8.8.8.8 \  example.comdelv -a /root/anchors.conf @8.8.8.8 \  -x 8.8.8.8 +shortdelv -i www.shop.lab
Output
$ delv @8.8.8.8 example.com;; validating ./DNSKEY: no valid signature found (DS);; no valid RRSIG resolving './DNSKEY/IN': 8.8.8.8#53;; broken trust chain resolving 'com/DS/IN': 8.8.8.8#53;; resolution failed: broken trust chain$ dig @8.8.8.8 . DNSKEY +multiline +nocrypto  ) ; ZSK; alg = RSASHA256 ; key id = 8763  ) ; KSK; alg = RSASHA256 ; key id = 20326  ) ; KSK; alg = RSASHA256 ; key id = 38696ns1$ dnssec-dsfromkey -2 -f /tmp/root.dnskey .. IN DS 38696 8 2 683D2D0ACB8C9B712A1948B27F741219298D0A450D612C483AF444A4C0FB2B16$ delv -a /root/anchors.conf @8.8.8.8 example.com; fully validatedexample.com.  206  IN  A  104.20.23.154example.com.  206  IN  A  172.66.147.243$ delv -a /root/anchors.conf @8.8.8.8 -x 8.8.8.8 +shortdns.google.$ delv -i www.shop.lab; authoritativewww.shop.lab.  300  IN  A  192.168.105.80
  • Real problem: delv 9.18.25 has only the old root KSK 20326 built in; the root DNSKEY set is now signed by KSK 38696 -> broken trust chain.
  • Fix: build an anchor file from the root DNSKEY after checking its DS digest against the IANA value, pass it with -a -> fully validated.
  • -x = reverse lookup, -i = insecure mode (skip validation).
Terminal
delv -a /root/anchors.conf \  +root=shop.lab www.shop.labdelv -a /root/anchors.conf +root=shop.lab \  +vtrace www.shop.labdelv -a /root/anchors.conf @8.8.8.8 \  +cdflag dnssec-failed.org
Output
$ delv -a /root/anchors.conf +root=shop.lab www.shop.lab; fully validatedwww.shop.lab.  300  IN  A  192.168.105.80www.shop.lab.  300  IN  RRSIG  A 13 3 300 20261122121609 20261108212522 44243 shop.lab. MJHFER4M...$ delv -a /root/anchors.conf +root=shop.lab +vtrace www.shop.lab;; fetch: www.shop.lab/A;; fetch: shop.lab/DNSKEY;; validating shop.lab/DNSKEY: verify rdataset (keyid=44243): success;; validating shop.lab/DNSKEY: marking as secure (DS);; validating www.shop.lab/A: keyset with trust secure;; validating www.shop.lab/A: verify rdataset (keyid=44243): success$ delv -a /root/anchors.conf @8.8.8.8 +cdflag dnssec-failed.org;; validating dnssec-failed.org/DNSKEY: no valid signature found (DS);; no valid RRSIG resolving 'dnssec-failed.org/DNSKEY/IN': 8.8.8.8#53;; broken trust chain resolving 'dnssec-failed.org/A/IN': 8.8.8.8#53;; resolution failed: broken trust chain
delv optionMeaning
-a fileTrust anchor file
+root=zoneZone whose anchor starts the chain (validate a private signed zone)
+vtraceValidator steps (verify success, marking as secure)
+rtrace / +mtraceLog every query sent / dump every response
+cdflagFetch even broken data and validate it locally to see the exact reason
-i, +norootSkip validation
-x, -t, -c, -p, -b, -4/-6, +short, +dnssec, +multilineSame meaning as in dig

85.12 Common mistakes

  • Assuming dig shows what the browser sees: dig asks the DNS server directly and ignores the hosts file, browser cache and browser DoH setting. Compare both.
  • SERVFAIL from a validating resolver but NOERROR with +cd means DNSSEC is broken for that domain; find the reason with delv +vtrace / +cdflag.
  • Trusting an old delv: an outdated built-in trust anchor reports broken trust chains for valid zones.
  • Putting TSIG keys inline with -y: they end up in shell history; use -k.

85.13 Interview tips

  • dig vs nslookup: dig shows the whole message (flags, TTL, query time), stable output, scriptable with +short.
  • Read flags: aa = authoritative, ad = DNSSEC validated, cd = checking disabled, ra = recursion available.
  • +trace for delegation problems, +nssearch for out-of-sync servers, +tcp / +tls / +https for transport tests.
  • delv verifies the chain of trust; keep its trust anchor up to date (root KSK rollover).