Bind zone file cache and dns cache

1

In my lab,there are two name servers running bind9:
ServerA has a zone file for "example.com";
ServerB has a zone file for "sub.example.com" which is subzone of "example.com".
In ServerA's zone file,there are two NS records about subzone and two glue records like below:

sub IN NS dns1.sub
    IN NS dns2.sub
dns1.sub IN A 1.1.1.1
dns2.sub IN A 2.2.2.2

In ServerB's zone file,the NS records like below:

@ IN NS dns1
  IN NS dns2
dns1 IN A 1.1.1.1
dns2 IN A 3.3.3.3

The A record of dns2.sub in ServerA's zone file is wrong(I did this on purpose),it should be 3.3.3.3.
After staring the two name servers,ServerA load its zone file into cache(I don't know how to name this cache,here I call it "zone file cache") and so does ServerB.

Step1: I execute "dig @ServerA +norecurse sub.example.com":

; <<>> DiG 9.9.4-RedHat-9.9.4-73.el7_6 <<>> @ServerA +norecurse sub.example.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64332
;; flags: qr ra; QUERY: 1, ANSWER: 0, AUTHORITY: 2, ADDITIONAL: 4

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

;; AUTHORITY SECTION:
sub.exmample.com.     60      IN      NS      dns1.sub.exmample.com.
sub.exmample.com.     60      IN      NS      dns2.sub.exmample.com.

;; ADDITIONAL SECTION:
dns1.sub.exmample.com. 60     IN      A       1.1.1.1
dns2.sub.exmample.com. 60     IN      A       2.2.2.2

;; Query time: 1 msec
;; SERVER: 10.82.12.69#53(10.82.12.69)
;; WHEN: 二 5月 28 14:55:50 CST 2019
;; MSG SIZE  rcvd: 145

obviously the RR is returned according to the zone file cache.

Step2: I execute "dig @ServerA +recurse sub.example.com":

; <<>> DiG 9.9.4-RedHat-9.9.4-73.el7_6 <<>> @ServerA +recurse sub.example.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43819
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

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

;; AUTHORITY SECTION:
sub.exmample.com.     30      IN      SOA     dns1.sub.exmample.com. mail.sub.exmample.com. 2019051501 60 60 60 60

;; Query time: 803 msec
;; SERVER: 10.82.12.69#53(10.82.12.69)
;; WHEN: 二 5月 28 15:00:05 CST 2019
;; MSG SIZE  rcvd: 100

after dumping ServerA's cache,I got these things:

sub.exmample.com.     26      \-A     ;-$NXRRSET
; sub.exmample.com. SOA dns1.sub.exmample.com. mail.sub.exmample.com. 2019051501 60 60 60 60

Step3:I execute "dig @ServerA +recurse c1.sub.example.com": c1.sub.example.com is one of the hosts in sub.example.com with address 4.4.4.4

; <<>> DiG 9.9.4-RedHat-9.9.4-73.el7_6 <<>> @ServerA +recurse c1.sub.example.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15260
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 4

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

;; ANSWER SECTION:
c1.sub.example.com.  30      IN      A       4.4.4.4

;; AUTHORITY SECTION:
sub.example.com.     30      IN      NS      dns1.sub.exmample.com.
sub.example.com.     30      IN      NS      dns2.sub.exmample.com.


;; ADDITIONAL SECTION:
dns1.sub.exmample.com. 30     IN      A       1.1.1.1
dns2.sub.exmample.com. 30     IN      A       3.3.3.3


;; Query time: 13 msec
;; SERVER: 10.82.12.69#53(10.82.12.69)
;; WHEN: 二 5月 28 15:05:59 CST 2019
;; MSG SIZE  rcvd: 171

There are some points really puzzle me:
1、after executing all three steps,there are two resource records in ServerA's cache about sub.example.com zone's name server dns2: first one is "dns2.sub.exmample.com. 3.3.3.3" in zone file cache,another is "dns2.sub.exmample.com. 2.2.2.2" in dns cache which it got from ServerB. As a normal dns client,which one will I get? DNS resource records in "DNS cache" has priority over records in "zone file cache"?or randomly?
2、what the "AUTHORITY SECTION" means? in my opinion the 2.2.2.2 is not the authoriative answer,why dig treat 2.2.2.2 as "AUTHORITY"?
3、A DNS client will cache all the answers it get or only the "authoriative" answers?
4、When will a DNS resolver query the NS records? after Step2 why doesn't have NS records in ServerA's cache?

aaron

Posted 2019-05-28T07:07:13.807

Reputation: 15

If I am not mistaken, regarding the AUTHORITY SECTION, the server holding exmample.com is treated as being authoritative for the subdomain (even if the subdomain is delegated to other DNS servers) because the subdomain is part of exmample.com. That is, how exmample.com structures its DNS is irrelevant from the perspective of asking "Who do I contact for information regarding exmample.com and its subdomains?" – Anaksunaman – 2019-05-28T09:35:07.757

No answers