ENDS Options in dig

以下のバージョンを使ってます。

$ dig -v
DiG 9.11.0rc1

ちょっと違うけど以下も参考になる。

Release Notes for BIND Version 9.11.0b3 http://ftp.swin.edu.au/isc/bind9/9.11.0b3/RELEASE-NOTES-bind-9.11.0b3.html

$HOME/.digrc には +nocookie だけ書いてる。 (COOKIE が入っているものは、 .digrc を書き換えていなかったときのもの)

+bufsize=###

EDNS による UDP ペイロードサイズの拡張。 TCP フォールバックせずに大きいサイズの応答を受け取れる。

+[no]edns[=###]

(EDNS バージョンを指定して) EDNS クエリを投げる。

edns=1 を指定

$ dig yokohei.com +qr +edns=1

; <<>> DiG 9.11.0rc1 <<>> yokohei.com +qr +edns=1
;; global options: +cmd
;; Sending:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 45859
;; flags: rd ad; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 1, flags:; udp: 4096
;; QUESTION SECTION:
;yokohei.com.			IN	A

;; QUERY SIZE: 40
...

バージョン未指定

$ dig yokohei.com +qr +edns

; <<>> DiG 9.11.0rc1 <<>> yokohei.com +qr +edns
;; global options: +cmd
;; Sending:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18815
;; flags: rd ad; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;yokohei.com.			IN	A

;; QUERY SIZE: 40

version 0 が使われる。

+ednsflags=###

EDNS Flag bit を指定。

6.1.4. Flags https://tools.ietf.org/html/rfc6891#section-6.1.4

DO DNSSEC OK bit as defined by [RFC3225].

Z Set to zero by senders and ignored by receivers, unless modified in a subsequent specification.

この Z に値を入れるみたい。 DO を指定するためのオプションではない。

$ dig yokohei.com +qr +ednsflags=0x0101

; <<>> DiG 9.11.0rc1 <<>> yokohei.com +qr +ednsflags=0x0101
;; global options: +cmd
;; Sending:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7715
;; flags: rd ad; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; MBZ: 0x0101, udp: 4096
; COOKIE: 37e446938df9187b
;; QUESTION SECTION:
;yokohei.com.			IN	A

;; QUERY SIZE: 52

pcap 結果はこんな感じ

Additional records
    <Root>: type OPT
        Name: <Root>
        Type: OPT (41)
        UDP payload size: 4096
        Higher bits in extended RCODE: 0x00
        EDNS0 version: 0
        Z: 0x0101
            0... .... .... .... = DO bit: Cannot handle DNSSEC security RRs
            .000 0001 0000 0001 = Reserved: 0x0101
        Data length: 12
        Option: COOKIE

+[no]ednsnegotiation

EDNS バージョンネゴシエーションを有効化するか否か。

+ednsneg のとき、 EDNS0 でリトライする。

$ dig yokohei.com +qr +edns=1 +ednsneg

; <<>> DiG 9.11.0rc1 <<>> yokohei.com +qr +edns=1 +ednsneg
;; global options: +cmd
;; Sending:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53483
;; flags: rd ad; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 1, flags:; udp: 4096
; COOKIE: 13777430a309d815
;; QUESTION SECTION:
;yokohei.com.			IN	A

;; QUERY SIZE: 52

;; BADVERS, retrying with EDNS version 0.
;; Sending:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34168
;; flags: rd ad; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 13777430a309d815
;; QUESTION SECTION:
;yokohei.com.			IN	A

;; QUERY SIZE: 52

+noednsneg のとき、 EDNS0 でリトライしない。

$ dig yokohei.com +qr +edns=1 +noednsneg

; <<>> DiG 9.11.0rc1 <<>> yokohei.com +qr +edns=1 +noednsneg
;; global options: +cmd
;; Sending:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13716
;; flags: rd ad; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 1, flags:; udp: 4096
; COOKIE: c1ed880201197d08
;; QUESTION SECTION:
;yokohei.com.			IN	A

;; QUERY SIZE: 52

リトライの挙動を理解するため dig の実装を読む。

https://github.com/isc-projects/bind9/blob/755efa9b187696d0de6f341e1dbfbb7e2a437d53/bin/dig/dighost.c#L3747

	if (msg->rcode == dns_rcode_badvers && msg->opt != NULL &&
	    (newedns = ednsvers(msg->opt)) < l->edns && l->ednsneg) {
		/*
		 * Add minimum EDNS version required checks here if needed.
		 */
		if (l->comments)
			printf(";; BADVERS, retrying with EDNS version %u.\n",
			       (unsigned int)newedns);
		l->edns = newedns;
		n = requeue_lookup(l, true);
		if (l->trace && l->trace_root)
			n->rdtype = l->qrdtype;
		dns_message_destroy(&msg);
		isc_event_free(&event);
		clear_query(query);
		cancel_lookup(l);
		check_next_lookup(l);
		UNLOCK_LOOKUP;
		return;

newedns を使ってリクエリ。 newedns とは何か、というと BADVERS を返すときに使われた EDNS バージョン。 なるほど。

+ednsopt=###[:value]

EDNS Option Code の指定。

DNS EDNS0 Option Codes (OPT) https://www.iana.org/assignments/dns-parameters/dns-parameters.xml#dns-parameters-11

例えば opt code 3 の nsid を指定すると、以下のようになる。

$ dig yokohei.com +qr +ednsopt=3 +norec @ns1.yokohei.com

; <<>> DiG 9.11.0rc1 <<>> yokohei.com +qr +ednsopt=3 +norec @ns1.yokohei.com
;; global options: +cmd
;; Sending:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 24960
;; flags: ad; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 246c29690e40f4f1
; NSID
;; QUESTION SECTION:
;yokohei.com.			IN	A

;; QUERY SIZE: 44

;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 24960
;; flags: qr aa; QUERY: 1, ANSWER: 4, AUTHORITY: 4, ADDITIONAL: 5

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; NSID: 61 30 30 65 32 30 39 65 33 61 62 36 65 33 65 39 61 35 63 33 30 38 65 35 37 31 35 64 31 38 36 34 20 20 2d ("a00e209e3ab6e3e9a5c308e5715d1864  -")
;; QUESTION SECTION:
;yokohei.com.			IN	A
...

pcap 結果

Additional records
    <Root>: type OPT
        Name: <Root>
        Type: OPT (41)
        UDP payload size: 4096
        Higher bits in extended RCODE: 0x00
        EDNS0 version: 0
        Z: 0x0000
        Data length: 16
        Option: COOKIE
        Option: NSID - Name Server Identifier

Last updated