digでdnsの仕組みを学ぶ


`www.jprs.co.jp`のIPアドレスは？


# ルートDNS
http://www.internic.net/domain/named.root

```
$ curl -i http://www.internic.net/domain/named.root
HTTP/1.1 200 OK
Date: Fri, 14 Mar 2025 00:51:06 GMT
Server: Apache
Last-Modified: Thu, 13 Mar 2025 20:32:00 GMT
Content-Length: 3311
ETag: "cef-6303f36c1b000"
Accept-Ranges: bytes
Cache-Control: max-age=420
Expires: Fri, 14 Mar 2025 00:56:12 GMT
X-Frame-Options: SAMEORIGIN
Referrer-Policy: origin-when-cross-origin
Content-Security-Policy: upgrade-insecure-requests
Age: 114
Content-Type: text/plain; charset=UTF-8
Content-Language: en

;       This file holds the information on root name servers needed to
;       initialize cache of Internet domain name servers
;       (e.g. reference this file in the "cache  .  <file>"
;       configuration file of BIND domain name servers).
;
;       This file is made available by InterNIC
;       under anonymous FTP as
;           file                /domain/named.cache
;           on server           FTP.INTERNIC.NET
;       -OR-                    RS.INTERNIC.NET
;
;       last update:     March 13, 2025
;       related version of root zone:     2025031301
;
; FORMERLY NS.INTERNIC.NET
;
.                        3600000      NS    A.ROOT-SERVERS.NET.
A.ROOT-SERVERS.NET.      3600000      A     198.41.0.4
A.ROOT-SERVERS.NET.      3600000      AAAA  2001:503:ba3e::2:30
;
; FORMERLY NS1.ISI.EDU
;
.                        3600000      NS    B.ROOT-SERVERS.NET.
B.ROOT-SERVERS.NET.      3600000      A     170.247.170.2
B.ROOT-SERVERS.NET.      3600000      AAAA  2801:1b8:10::b
;
; FORMERLY C.PSI.NET
;
.                        3600000      NS    C.ROOT-SERVERS.NET.
C.ROOT-SERVERS.NET.      3600000      A     192.33.4.12
C.ROOT-SERVERS.NET.      3600000      AAAA  2001:500:2::c
;
; FORMERLY TERP.UMD.EDU
;
.                        3600000      NS    D.ROOT-SERVERS.NET.
D.ROOT-SERVERS.NET.      3600000      A     199.7.91.13
D.ROOT-SERVERS.NET.      3600000      AAAA  2001:500:2d::d
;
; FORMERLY NS.NASA.GOV
;
.                        3600000      NS    E.ROOT-SERVERS.NET.
E.ROOT-SERVERS.NET.      3600000      A     192.203.230.10
E.ROOT-SERVERS.NET.      3600000      AAAA  2001:500:a8::e
;
; FORMERLY NS.ISC.ORG
;
.                        3600000      NS    F.ROOT-SERVERS.NET.
F.ROOT-SERVERS.NET.      3600000      A     192.5.5.241
F.ROOT-SERVERS.NET.      3600000      AAAA  2001:500:2f::f
;
; FORMERLY NS.NIC.DDN.MIL
;
.                        3600000      NS    G.ROOT-SERVERS.NET.
G.ROOT-SERVERS.NET.      3600000      A     192.112.36.4
G.ROOT-SERVERS.NET.      3600000      AAAA  2001:500:12::d0d
;
; FORMERLY AOS.ARL.ARMY.MIL
;
.                        3600000      NS    H.ROOT-SERVERS.NET.
H.ROOT-SERVERS.NET.      3600000      A     198.97.190.53
H.ROOT-SERVERS.NET.      3600000      AAAA  2001:500:1::53
;
; FORMERLY NIC.NORDU.NET
;
.                        3600000      NS    I.ROOT-SERVERS.NET.
I.ROOT-SERVERS.NET.      3600000      A     192.36.148.17
I.ROOT-SERVERS.NET.      3600000      AAAA  2001:7fe::53
;
; OPERATED BY VERISIGN, INC.
;
.                        3600000      NS    J.ROOT-SERVERS.NET.
J.ROOT-SERVERS.NET.      3600000      A     192.58.128.30
J.ROOT-SERVERS.NET.      3600000      AAAA  2001:503:c27::2:30
;
; OPERATED BY RIPE NCC
;
.                        3600000      NS    K.ROOT-SERVERS.NET.
K.ROOT-SERVERS.NET.      3600000      A     193.0.14.129
K.ROOT-SERVERS.NET.      3600000      AAAA  2001:7fd::1
;
; OPERATED BY ICANN
;
.                        3600000      NS    L.ROOT-SERVERS.NET.
L.ROOT-SERVERS.NET.      3600000      A     199.7.83.42
L.ROOT-SERVERS.NET.      3600000      AAAA  2001:500:9f::42
;
; OPERATED BY WIDE
;
.                        3600000      NS    M.ROOT-SERVERS.NET.
M.ROOT-SERVERS.NET.      3600000      A     202.12.27.33
M.ROOT-SERVERS.NET.      3600000      AAAA  2001:dc3::35
; End of file
```

# ルート権威サーバーにwww.jprs.co.jp を聞いてみる
+norecで再帰検索しないようにする

```
$ dig +norec @198.41.0.4 www.jprs.co.jp A

; <<>> DiG 9.20.2-1-Debian <<>> +norec @198.41.0.4 www.jprs.co.jp A
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51759
;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 8, ADDITIONAL: 16

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.jprs.co.jp.                        IN      A

;; AUTHORITY SECTION:
jp.                     172800  IN      NS      e.dns.jp.
jp.                     172800  IN      NS      g.dns.jp.
jp.                     172800  IN      NS      c.dns.jp.
jp.                     172800  IN      NS      a.dns.jp.
jp.                     172800  IN      NS      h.dns.jp.
jp.                     172800  IN      NS      d.dns.jp.
jp.                     172800  IN      NS      f.dns.jp.
jp.                     172800  IN      NS      b.dns.jp.

;; ADDITIONAL SECTION:
e.dns.jp.               172800  IN      A       192.50.43.53
e.dns.jp.               172800  IN      AAAA    2001:200:c000::35
g.dns.jp.               172800  IN      A       203.119.40.1
c.dns.jp.               172800  IN      A       156.154.100.5
c.dns.jp.               172800  IN      AAAA    2001:502:ad09::5
a.dns.jp.               172800  IN      A       203.119.1.1
a.dns.jp.               172800  IN      AAAA    2001:dc4::1
h.dns.jp.               172800  IN      A       161.232.72.25
h.dns.jp.               172800  IN      AAAA    2a01:8840:1bc::25
d.dns.jp.               172800  IN      A       210.138.175.244
d.dns.jp.               172800  IN      AAAA    2001:240::53
f.dns.jp.               172800  IN      A       150.100.6.8
f.dns.jp.               172800  IN      AAAA    2001:2f8:0:100::153
b.dns.jp.               172800  IN      A       202.12.30.131
b.dns.jp.               172800  IN      AAAA    2001:dc2::1

;; Query time: 119 msec
;; SERVER: 198.41.0.4#53(198.41.0.4) (UDP)
;; WHEN: Fri Mar 14 09:54:51 JST 2025
;; MSG SIZE  rcvd: 499
```

jpの権威サーバのIPの一つが　192.50.43.53　とわかった。

# jpの権威サーバーにwww.jprs.co.jp を聞いてみる

```
$ dig +norec @192.50.43.53 www.jprs.co.jp A

; <<>> DiG 9.20.2-1-Debian <<>> +norec @192.50.43.53 www.jprs.co.jp A
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5689
;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 4, ADDITIONAL: 9

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;www.jprs.co.jp.                        IN      A

;; AUTHORITY SECTION:
jprs.co.jp.             86400   IN      NS      ns1.jprs.co.jp.
jprs.co.jp.             86400   IN      NS      ns2.jprs.co.jp.
jprs.co.jp.             86400   IN      NS      ns3.jprs.co.jp.
jprs.co.jp.             86400   IN      NS      ns4.jprs.co.jp.

;; ADDITIONAL SECTION:
ns1.jprs.co.jp.         86400   IN      A       202.11.16.49
ns2.jprs.co.jp.         86400   IN      A       202.11.16.59
ns3.jprs.co.jp.         86400   IN      A       203.105.65.178
ns4.jprs.co.jp.         86400   IN      A       203.105.65.181
ns1.jprs.co.jp.         86400   IN      AAAA    2001:df0:8::a153
ns2.jprs.co.jp.         86400   IN      AAAA    2001:df0:8::a253
ns3.jprs.co.jp.         86400   IN      AAAA    2001:218:3001::a153
ns4.jprs.co.jp.         86400   IN      AAAA    2001:218:3001::a253

;; Query time: 19 msec
;; SERVER: 192.50.43.53#53(192.50.43.53) (UDP)
;; WHEN: Fri Mar 14 10:07:38 JST 2025
;; MSG SIZE  rcvd: 291
```

co.jpは飛び越えて、jprs.co.jpの権威サーバの情報が得られた

# jprs.co.jpの権威サーバにwww.jprs.co.jp を聞いてみる
```
$ dig +norec @202.11.16.49 www.jprs.co.jp A

; <<>> DiG 9.20.2-1-Debian <<>> +norec @202.11.16.49 www.jprs.co.jp A
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33589
;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 9

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;www.jprs.co.jp.                        IN      A

;; ANSWER SECTION:
www.jprs.co.jp.         300     IN      A       117.104.133.165

;; AUTHORITY SECTION:
jprs.co.jp.             86400   IN      NS      ns2.jprs.co.jp.
jprs.co.jp.             86400   IN      NS      ns3.jprs.co.jp.
jprs.co.jp.             86400   IN      NS      ns4.jprs.co.jp.
jprs.co.jp.             86400   IN      NS      ns1.jprs.co.jp.

;; ADDITIONAL SECTION:
ns1.jprs.co.jp.         86400   IN      A       202.11.16.49
ns2.jprs.co.jp.         86400   IN      A       202.11.16.59
ns3.jprs.co.jp.         86400   IN      A       203.105.65.178
ns4.jprs.co.jp.         86400   IN      A       203.105.65.181
ns1.jprs.co.jp.         86400   IN      AAAA    2001:df0:8::a153
ns2.jprs.co.jp.         86400   IN      AAAA    2001:df0:8::a253
ns3.jprs.co.jp.         86400   IN      AAAA    2001:218:3001::a153
ns4.jprs.co.jp.         86400   IN      AAAA    2001:218:3001::a253

;; Query time: 29 msec
;; SERVER: 202.11.16.49#53(202.11.16.49) (UDP)
;; WHEN: Fri Mar 14 10:11:38 JST 2025
;; MSG SIZE  rcvd: 307
```

117.104.133.165とわかった。


# 再帰検索有無の違い

リゾルバに 8.8.8.8 （Google）を指定

```:再帰検索なし
$ dig +norec @8.8.8.8 www.jprs.co.jp A

; <<>> DiG 9.20.2-1-Debian <<>> +norec @8.8.8.8 www.jprs.co.jp A
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 34082
;; flags: qr ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;www.jprs.co.jp.                        IN      A

;; Query time: 19 msec
;; SERVER: 8.8.8.8#53(8.8.8.8) (UDP)
;; WHEN: Fri Mar 14 10:02:21 JST 2025
;; MSG SIZE  rcvd: 43
```

予想通り、結果が得られない。

```:再帰検索あり
$ dig @8.8.8.8 www.jprs.co.jp A

; <<>> DiG 9.20.2-1-Debian <<>> @8.8.8.8 www.jprs.co.jp A
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40279
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;www.jprs.co.jp.                        IN      A

;; ANSWER SECTION:
www.jprs.co.jp.         300     IN      A       117.104.133.165

;; Query time: 30 msec
;; SERVER: 8.8.8.8#53(8.8.8.8) (UDP)
;; WHEN: Fri Mar 14 10:05:40 JST 2025
;; MSG SIZE  rcvd: 59
```