nsupdate, mdig, kdig, drill (2/2)
kdig is the dig-like client from Knot DNS that also speaks DNS over TLS, HTTPS and QUIC and prints JSON. drill (from the ldns library) is built for DNSSEC debugging: tracing from the root and chasing the chain of signatures. Together they cover what dig is weakest at: encrypted DNS and DNSSEC chain checks.
88.1 Why is it used?
- kdig: test DoT (+tls), DoH (+https) and DoQ (+quic) with certificate checks; JSON output (+json) for scripts.
- drill: -T trace from the root, -T -D validate DNSSEC at every level, -S chase signatures to see where the chain breaks.
- Both do zone transfers with TSIG, EDNS options and header-flag tweaks.
- Linux: knot-dnsutils (kdig), ldnsutils (drill). macOS: brew knot / brew ldns. Windows: WSL or Windows builds.
88.2 How it works
- Step 1
1.Plain: PC 192.168.108.20 -> lab DNS 192.168.108.10, UDP 53, readable by anyone on the path
- Step 2
2.+tls: query encrypted, leaves through the Docker gateway 192.168.108.1
- Step 3
3.Crosses ISP / internet routers as encrypted bytes
- Step 4
4.Reaches 1.1.1.1 on TCP 853 (+https uses 443, +quic uses UDP 853)
- Step 1
1.drill ignores the resolver and asks a.root-servers.net
- Step 2
2.Root -> referral to the com servers
- Step 3
3.a.gtld-servers.net -> referral to hera.ns.cloudflare.com
- Step 4
4.Authoritative -> final A record for example.com
- Step 5
5.With -D the DNSSEC signature is checked at every step
88.3 kdig: query, server, class and type parameters
Lab: n088-ns 192.168.108.10 = BIND 9.18.49 primary for lab.example (TSIG key xfr-key for transfers/updates, ports 53 + 5353); n088-pc 192.168.108.20 = kdig 3.3.9 + drill 1.8.3.
kdig @192.168.108.10 www.lab.examplekdig @192.168.108.10:5353 \ www.lab.example +shortkdig @192.168.108.10 lab.example MX +shortkdig @192.168.108.10 CH TXT version.bind \ +shortkdig +noall +answer | head -4$ kdig @192.168.108.10 www.lab.example;; ->>HEADER<<- opcode: QUERY; status: NOERROR; id: 49732;; Flags: qr aa rd ra; QUERY: 1; ANSWER: 1; AUTHORITY: 0; ADDITIONAL: 0;; ANSWER SECTION:www.lab.example. 3600 IN A 192.168.108.80;; From 192.168.108.10@53(UDP) in 1.1 ms$ kdig @192.168.108.10:5353 \ www.lab.example +short192.168.108.80$ kdig @192.168.108.10 lab.example MX +short10 mail.lab.example.$ kdig @192.168.108.10 CH TXT version.bind \ +short"lab-bind"$ kdig +noall +answer | head -4. 259200 IN NS b.root-servers.net.. 259200 IN NS i.root-servers.net.. 259200 IN NS l.root-servers.net.. 259200 IN NS a.root-servers.net.kdig @192.168.108.10 lab.example AXFRkdig -k xfr.key @192.168.108.10 \ lab.example AXFRkdig -k xfr.key @192.168.108.10 \ lab.example IXFR=1kdig @192.168.108.10 lab.example NOTIFY=2$ kdig @192.168.108.10 lab.example AXFR;; ERROR: server replied with error 'REFUSED';; AXFR for lab.example.;; ERROR: failed to query server 192.168.108.10@53(TCP)$ kdig -k xfr.key @192.168.108.10 \ lab.example AXFR;; AXFR for lab.example.lab.example. 3600 IN SOA ns1.lab.example. admin.lab.example. 1 3600 600 86400 300lab.example. 3600 IN MX 10 mail.lab.example.lab.example. 3600 IN NS ns1.lab.example.mail.lab.example. 3600 IN A 192.168.108.25www.lab.example. 3600 IN A 192.168.108.80xfr-key. 0 ANY TSIG hmac-sha256. 1794177419 300 32 Co7Eemw6eMzfOrIQjKzDUDC+kRF/XF+F/qFZJTtGZvc= 18110 NOERROR 0;; Received 305 B (1 messages, 8 records)$ kdig -k xfr.key @192.168.108.10 \ lab.example IXFR=1;; IXFR for lab.example.lab.example. 3600 IN SOA ns1.lab.example. admin.lab.example. 2 3600 600 86400 300lab.example. 3600 IN SOA ns1.lab.example. admin.lab.example. 1 3600 600 86400 300lab.example. 3600 IN SOA ns1.lab.example. admin.lab.example. 2 3600 600 86400 300api.lab.example. 300 IN A 192.168.108.90;; Received 283 B (1 messages, 5 records)$ kdig @192.168.108.10 lab.example NOTIFY=2;; ->>HEADER<<- opcode: NOTIFY; status: NOERROR; id: 27;; Flags: qr aa; QUERY: 1; ANSWER: 0; AUTHORITY: 0; ADDITIONAL: 0;; lab.example. IN SOA- Port forms: @ip:port, @ip#port, @ip@port, @[IPv6]:port; a server starting with / is a UNIX socket path.
- CLASS3 / TYPE65 = any class or type by number. No arguments = root NS from the resolv.conf server.
- AXFR without the key is REFUSED; with -k the zone arrives signed by a TSIG record. IXFR=1 returns only changes since serial 1.
88.4 kdig: dash options
kdig -c CH -t TXT -q version.bind \ @192.168.108.10 +shortkdig -x 8.8.8.8 @8.8.8.8 +shortkdig -b 192.168.108.99 @8.8.8.8 \ example.com +shortkdig -d @8.8.8.8 example.com +shortkdig -E q.tap @8.8.8.8 example.com +short$ kdig -c CH -t TXT -q version.bind \ @192.168.108.10 +short"lab-bind"$ kdig -x 8.8.8.8 @8.8.8.8 +shortdns.google.$ kdig -b 192.168.108.99 @8.8.8.8 \ example.com +short;; WARNING: can't assign address 192.168.108.99;; WARNING: can't assign address 192.168.108.99;; WARNING: can't assign address 192.168.108.99;; ERROR: failed to query server 8.8.8.8@53(UDP)$ kdig -d @8.8.8.8 example.com +short;; DEBUG: Querying for owner(example.com.), class(1), type(1), server(8.8.8.8), port(53), protocol(UDP)104.20.23.154172.66.147.243$ kdig -E q.tap @8.8.8.8 example.com +short;; ERROR: no dnstap support but -E specified| Option | Meaning |
|---|---|
| -c / -t / -q | Explicit class / type / name |
| -x address | Reverse PTR query |
| -b address, -4 / -6, -p port | Source IP (must exist on the host), IP version, server port |
| -k keyfile / -y alg:name:key | TSIG key (not together; a wrong key gave BADSIG) |
| -d | Debug messages |
| -E / -G tapfile | Export to / print from dnstap (Alpine build has no dnstap) |
| -h / -V | Help / version |
88.5 kdig: output and header-flag +options
kdig @8.8.8.8 example.com +noclass \ +nottl +noall +answerkdig @1.1.1.1 example.com DNSKEY \ +nocrypto +noall +answerkdig @192.168.108.10 www.lab.example \ +generic +noall +answerkdig @192.168.108.10 lab.example MX +json$ kdig @8.8.8.8 example.com +noclass \ +nottl +noall +answerexample.com. A 104.20.23.154example.com. A 172.66.147.243$ kdig @1.1.1.1 example.com DNSKEY \ +nocrypto +noall +answerexample.com. 3593 IN DNSKEY 256 3 13 [id = 36315]example.com. 3593 IN DNSKEY 256 3 13 [id = 9776]example.com. 3593 IN DNSKEY 256 3 13 [id = 34505]example.com. 3593 IN DNSKEY 257 3 13 [id = 2371]$ kdig @192.168.108.10 www.lab.example \ +generic +noall +answerwww.lab.example. 3600 IN TYPE1 \# 4 C0A86C50$ kdig @192.168.108.10 lab.example MX +json{ "QNAME": "lab.example.", "QTYPEname": "MX", "answerRRs": [ "TTL": 3600, "rdataMX": "10 mail.lab.example.", "rdataA": "192.168.108.25",- +short, +noall +answer, +noclass, +nottl trim output; +nocrypto shows key ids instead of long keys.
- +generic prints RFC 3597 hex form; +json gives the whole packet as RFC 8427 JSON; +multiline, +qr, +tsig, +stats, +opt also exist (+no... turns any off).
- Header flags: +[no]recurse / +[no]rdflag, +[no]cdflag, +[no]adflag, +[no]aaflag, +[no]tcflag, +[no]raflag, +[no]zflag; +dnssec sets the DO bit.
kdig @192.168.108.10 github.com +norecursekdig @192.168.108.10 github.com +shortkdig @192.168.108.10 github.com \ +norecurse +noall +answerkdig @1.1.1.1 example.com +cdflag \ +noall +header$ kdig @192.168.108.10 github.com +norecurse;; ->>HEADER<<- opcode: QUERY; status: NOERROR; id: 2420;; Flags: qr ra; QUERY: 1; ANSWER: 0; AUTHORITY: 13; ADDITIONAL: 0;; AUTHORITY SECTION:. 259152 IN NS i.root-servers.net.. 259152 IN NS g.root-servers.net.. 259152 IN NS f.root-servers.net.$ kdig @192.168.108.10 github.com +short20.207.73.82$ kdig @192.168.108.10 github.com \ +norecurse +noall +answergithub.com. 59 IN A 20.207.73.82$ kdig @1.1.1.1 example.com +cdflag \ +noall +header;; ->>HEADER<<- opcode: QUERY; status: NOERROR; id: 48707;; Flags: qr rd ra cd; QUERY: 1; ANSWER: 2; AUTHORITY: 0; ADDITIONAL: 088.6 kdig: transport +options (TCP, TLS, HTTPS, QUIC)
kdig @1.1.1.1 +tls-ca \ +tls-hostname=cloudflare-dns.com \ example.comkdig @1.1.1.1 +tls-ca \ +tls-hostname=wrong.example example.comkdig @1.1.1.1 +https example.comkdig @94.140.14.14 +quic example.com$ kdig @1.1.1.1 +tls-ca \ +tls-hostname=cloudflare-dns.com \ example.com;; TLS session (TLS1.3)-(ECDHE-X25519)-(ECDSA-SECP256R1-SHA256)-(AES-256-GCM);; Flags: qr rd ra ad; QUERY: 1; ANSWER: 2; AUTHORITY: 0; ADDITIONAL: 1example.com. 266 IN A 104.20.23.154example.com. 266 IN A 172.66.147.243;; From 1.1.1.1@853(TLS) in 170.7 ms$ kdig @1.1.1.1 +tls-ca \ +tls-hostname=wrong.example example.com;; WARNING: TLS, handshake failed (Error in the certificate.);; ERROR: failed to query server 1.1.1.1@853(TCP)$ kdig @1.1.1.1 +https example.com;; HTTP session (HTTP/2-POST)-(1.1.1.1/dns-query)-(status: 200)example.com. 286 IN A 104.20.23.154example.com. 286 IN A 172.66.147.243;; From 1.1.1.1@443(HTTPS) in 81.7 ms$ kdig @94.140.14.14 +quic example.com;; QUIC session (QUICv1)-(TLS1.3)-(ECDHE-X25519)-(ECDSA-SECP256R1-SHA256)-(AES-128-GCM)example.com. 300 IN A 104.20.23.154example.com. 300 IN A 172.66.147.243;; From 94.140.14.14@853(QUIC) in 960.6 ms| Option | Meaning |
|---|---|
| +tls | DoT, opportunistic (no certificate check) |
| +tls-ca[=FILE] + +tls-hostname=STR | Validate the certificate and its name (wrong name -> handshake fails, query never sent) |
| +tls-pin=BASE64, +tls-sni, +tls-keyfile/-certfile, +tls-ocsp-stapling | Key pinning, SNI, client cert, OCSP |
| +https[=URL] / +https-get | DoH via HTTP/2 POST / GET on 443 |
| +quic | DNS over QUIC, UDP 853 |
| +tcp, +fastopen, +ignore, +keepopen | TCP (default for AXFR/IXFR), TCP Fast Open, no TCP retry on TC, many queries on one connection |
| +proxy=SRC-DST | PROXYv2 header |
88.7 kdig: EDNS, timing and retries
kdig @192.168.108.10 www.lab.example \ +nsid +noall +header +optkdig @192.168.108.10 www.lab.example \ +edns=1 +noall +header +optkdig @8.8.8.8 example.com \ +subnet=203.0.113.0/24 +noall +header +opttime kdig @192.168.108.99 example.com \ +timeout=1 +retry=2$ kdig @192.168.108.10 www.lab.example \ +nsid +noall +header +opt;; Flags: qr aa rd ra; QUERY: 1; ANSWER: 1; AUTHORITY: 0; ADDITIONAL: 1;;;; Version: 0; flags: ; UDP size: 1232 B; ext-rcode: NOERROR;; NSID: 6E73312E6C6162 "ns1.lab"$ kdig @192.168.108.10 www.lab.example \ +edns=1 +noall +header +opt;; ->>HEADER<<- opcode: QUERY; status: BADVERS; id: 56037;; Flags: qr rd; QUERY: 1; ANSWER: 0; AUTHORITY: 0; ADDITIONAL: 1;;;; Version: 0; flags: ; UDP size: 1232 B; ext-rcode: BADVERS$ kdig @8.8.8.8 example.com \ +subnet=203.0.113.0/24 +noall +header +opt;; ->>HEADER<<- opcode: QUERY; status: REFUSED; id: 28344;; Flags: qr rd ra; QUERY: 1; ANSWER: 0; AUTHORITY: 0; ADDITIONAL: 1;; CLIENT-SUBNET: 203.0.113.0/24/0$ time kdig @192.168.108.99 example.com \ +timeout=1 +retry=2;; WARNING: response timeout for 192.168.108.99@53(UDP);; WARNING: response timeout for 192.168.108.99@53(UDP);; WARNING: response timeout for 192.168.108.99@53(UDP);; ERROR: failed to query server 192.168.108.99@53(UDP)real 0m 3.01s- +timeout=1 +retry=2 = 3 attempts, 3 seconds. Defaults: timeout 5 s, retry 2, bufsize 4096.
- Others: +cookie, +badcookie, +expire (zone expire time), +padding / +nopadding / +alignment (kdig pads by default with TLS), +ednsopt=CODE:HEX, +noednsopt.
88.8 drill: arguments and general options
drill www.lab.example @192.168.108.10drill version.bind @192.168.108.10 TXT CHdrill -Q www.lab.example @192.168.108.10drill -w a.pkt www.lab.example \ @192.168.108.10 >/dev/null; cat a.pktdrill -i a.pkt | grep -A1 ANSWER$ drill www.lab.example @192.168.108.10;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 58547;; flags: qr aa rd ra ; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0www.lab.example. 3600 IN A 192.168.108.80;; SERVER: 192.168.108.10$ drill version.bind @192.168.108.10 TXT CHversion.bind. 0 CH TXT "lab-bind"$ drill -Q www.lab.example @192.168.108.10192.168.108.80$ drill -w a.pkt www.lab.example \ @192.168.108.10 >/dev/null; cat a.pkt; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19;-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 34 92 85 80 00 01 00 01 00 00 00 00 03 77 77 77 03 6c 61 62 ; 1- 20 07 65 78 61 6d 70 6c 65 00 00 01 00 01 c0 0c 00 01 00 01 00 ; 21- 40 00 0e 10 00 04 c0 a8 6c 50$ drill -i a.pkt | grep -A1 ANSWER;; flags: qr aa rd ra ; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0;; QUESTION SECTION:--;; ANSWER SECTION:www.lab.example. 3600 IN A 192.168.108.80- Order: name [@server] [type] [class].
- -Q quiet (answer data only); -w / -q write answer / query to a hex-dump file; -i / -f read them back without the network (useful for bug reports).
- -D DO bit, -T trace, -S chase, -I source address, -V 5 verbose (prints the query too).
88.9 Debugging a real DNSSEC failure: drill -T -D and -S
drill -TD -k /usr/share/dnssec-root/\trusted-key.key example.comkdig @1.1.1.1 +tls-ca \ +tls-hostname=cloudflare-dns.com \ . DNSKEY +noall +header +answer \ +nottl +nocryptodrill -TD -k k1.key -k k2.key example.comdrill -S -k k1.key -k k2.key \ example.com @1.1.1.1$ drill -TD -k /usr/share/dnssec-root/\trusted-key.key example.com;; Number of trusted keys: 1;; Domain: .;; Signature ok but no chain to a trusted key or ds record;; Domain: com.;; Signature ok but no chain to a trusted key or ds record;; Domain: example.com.;; Signature ok but no chain to a trusted key or ds record[S] example.com. 300 IN A 172.66.147.243$ kdig @1.1.1.1 +tls-ca \ +tls-hostname=cloudflare-dns.com \ . DNSKEY +noall +header +answer \ +nottl +nocrypto;; Flags: qr rd ra ad; QUERY: 1; ANSWER: 3; AUTHORITY: 0; ADDITIONAL: 1. IN DNSKEY 256 3 8 [id = 8763]. IN DNSKEY 257 3 8 [id = 20326]. IN DNSKEY 257 3 8 [id = 38696]$ drill -TD -k k1.key -k k2.key example.com;; Number of trusted keys: 2;; Domain: .[T] . 172800 IN DNSKEY 256 3 8 ;{id = 8763 (zsk), size = 2048b}Key is now trusted!;; Domain: com.[T] com. 86400 IN DNSKEY 256 3 13 ;{id = 65344 (zsk), size = 256b};; Domain: example.com.[T] example.com. 300 IN A 104.20.23.154$ drill -S -k k1.key -k k2.key \ example.com @1.1.1.1example.com. (A)|---example.com. (DNSKEY keytag: 34505 alg: 13 flags: 256) |---example.com. (DS keytag: 2371 digest type: 2) |---com. (DNSKEY keytag: 65344 alg: 13 flags: 256) |---com. (DS keytag: 19718 digest type: 2) |---. (DNSKEY keytag: 8763 alg: 8 flags: 256) |---. (DNSKEY keytag: 38696 alg: 8 flags: 257);; Chase successful- Step 1
1.drill -TD with Alpine's anchor (only root KSK 20326): [S] signed but untrusted at every level
- Step 2
2.Fetch the root DNSKEY over validated DoT (ad flag): KSKs 20326 and 38696
- Step 3
3.The root is now signed by the new KSK 38696
- Step 4
4.Save both KSKs as k1.key and k2.key, rerun -TD: every level [T] trusted
- Step 5
5.drill -S shows the full chain A -> DNSKEY -> DS -> com -> root KSK 38696
The zone was fine; the client's trust anchor was outdated
88.10 drill: query options and -o header bits
drill -s dnskey example.com @1.1.1.1drill -x 8.8.8.8 @8.8.8.8drill -y xfr-key:$SECRET:hmac-sha256 \ lab.example AXFR @192.168.108.10drill -o rd example.net @192.168.108.10 \ | head -6drill -o CD example.com @1.1.1.1 | head -3$ drill -s dnskey example.com @1.1.1.1;; flags: qr rd ra ; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0; equivalent DS records for key 2371:; sha1: example.com. 2768 IN DS 2371 13 1 9bacd9689f3c9eceb62e2e533ca7a87669f7e58b; sha256: example.com. 2768 IN DS 2371 13 2 c988ec423e3880eb8dd8a46fe06ca230ee23f35b578d64e78b29c3e1c83d245a$ drill -x 8.8.8.8 @8.8.8.8;; 8.8.8.8.in-addr.arpa. IN PTR8.8.8.8.in-addr.arpa. 13649 IN PTR dns.google.$ drill -y xfr-key:$SECRET:hmac-sha256 \ lab.example AXFR @192.168.108.10lab.example. 3600 IN SOA ns1.lab.example. admin.lab.example. 2 3600 600 86400 300lab.example. 3600 IN MX 10 mail.lab.example.api.lab.example. 300 IN A 192.168.108.90www.lab.example. 3600 IN A 192.168.108.80lab.example. 3600 IN SOA ns1.lab.example. admin.lab.example. 2 3600 600 86400 300$ drill -o rd example.net @192.168.108.10 \ | head -6;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 35589;; flags: qr ra ; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 0;; QUESTION SECTION:;; example.net. IN A;; ANSWER SECTION:$ drill -o CD example.com @1.1.1.1 | head -3;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 23993;; flags: qr rd cd ra ; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0| drill option | Meaning |
|---|---|
| -s | Print the equivalent DS for each DNSKEY (matches the DS published in the parent) |
| -x / -y name:key[:algo] | Reverse PTR / TSIG key (AXFR worked) |
| -k keyfile | Trusted DNSKEY/DS anchor for -T -D and -S |
| -t / -u, -4 / -6, -p port | TCP / UDP (default UDP), IP version, port |
| -a, -b size | On TC retry with EDNS 4096 then TCP; EDNS0 buffer size |
| -c file, -d domain, -r file, -z | Other resolv.conf, start trace at domain, root hints for trace, do not randomise servers |
| -o QR|AA|TC|RD|CD|RA|AD | UPPERCASE sets the bit, lowercase clears it (QR and RD on by default) |
88.11 Common mistakes
- Believing plain +tls verified the server: it is opportunistic. Use +tls-ca with +tls-hostname.
- Blaming the zone when drill's chain fails: here example.com was fine, the client's old anchor lacked root KSK 38696. Update the trust anchor first.
- Using -b with an IP the host does not own: "can't assign address".
- Expecting every build to have every feature: Alpine's kdig has no dnstap (-E/-G).
88.12 Interview tips
- Why kdig after dig: DoT / DoH / DoQ testing with certificate validation, and JSON output for scripts.
- Why drill: -T -D validates every level from the root, -S shows exactly where the chain of trust breaks.
- A failing chain can be the client's trust anchor (root KSK rollover 20326 -> 38696), not the zone.
- Know the header bits: rd, cd, ad, aa and how to toggle them (kdig +[no]flag, drill -o).