Networking – How to do full A-Record resolution from root DNS servers

dnsnetworking

I have a hypothetical situation that I've been unable to find any real answer to. Imagine we have a computer that has never been on the internet. The computer is also on a network where no DNS service is provided. Lets also pretend that things like google public DNS don't exist.

Now let's assume that the only thing this computer has is the root DNS servers' names and resolved addresses, like so.

Now this computer wants to know the IP address of say, superuser.com. How, with only having the IP addresses of root servers, does the computer work through queries to a root server in order to wind up with the resolved A-record of superuser.com?

I've made attempts but I always wind up in a place where I need to use an existing DNS server that I know of to resolve an A-Record. For example if I open command prompt and start trying to resolve google.ca (against a root server), I wind up with:

Served By:

ns1.google.com

google.ca

ns2.google.com

google.ca

… and so and and so forth. So basically at this point, I have to resolve nsX.google.com in order to query it to get the A-record for google.ca, however, given the scenario, I don't have a server I can to query for the address of nsX.google.com. If I attempt to resolve ns1.google.com back from the root server, I wind up in the same place.

Short version: How the hell do I resolve the A-Record for a domain without using any other information except what is provided to me by a root server? Thanks in advance. 🙂

Best Answer

Your situation is not unusual the slightest bit; every time a full-featured recursive resolver is started – such as BIND9 or Unbound, even the copy I've running on my laptop – it starts with just a list of root zone 'hints', and descends from there all by itself.

(You said "Imagine a world where Google Public DNS doesn't exist". Ever wonder how Google Public DNS itself resolves all domain names?)

But replies to DNS queries can have more than just a straight answer. Specifically, if a domain's authoritative name servers are in the same domain, then a copy of their addresses – aka, glue records – will be held by the parent domain as well.

So when you query the com. name servers for www.google.com, they don't just say that it's hosted by ns1.google.com, but also give you the IP addresses of ns1.google.com in the same reply message!

In fact, you should have already hit this earlier, with the com. top-level domain. When you query the root name servers – they will tell you that all of com. is hosted by m.gtld-servers.net. and they will give you its IP address. You can see for yourself that the root zone file holds this information.

For example:

$ dig @198.41.0.4 www.google.com. A
;; opcode: QUERY, status: NOERROR, id: 61096
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 16

;; QUESTION SECTION:
;www.google.com.            IN  A

;; AUTHORITY SECTION:
com.            172800  IN  NS  m.gtld-servers.net.
com.            172800  IN  NS  l.gtld-servers.net.
com.            172800  IN  NS  k.gtld-servers.net.
...

;; ADDITIONAL SECTION:
m.gtld-servers.net. 172800  IN  A   192.55.83.30
l.gtld-servers.net. 172800  IN  A   192.41.162.30
k.gtld-servers.net. 172800  IN  A   192.52.178.30
...

Continuing with one of the com. name servers:

$ dig @192.55.83.30 www.google.com. A
;; opcode: QUERY, status: NOERROR, id: 46406
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 4, ADDITIONAL: 5

;; QUESTION SECTION:
;www.google.com.            IN  A

;; AUTHORITY SECTION:
google.com.     172800  IN  NS  ns2.google.com.
google.com.     172800  IN  NS  ns1.google.com.
google.com.     172800  IN  NS  ns3.google.com.
google.com.     172800  IN  NS  ns4.google.com.

;; ADDITIONAL SECTION:
ns2.google.com.     172800  IN  A   216.239.34.10
ns1.google.com.     172800  IN  A   216.239.32.10
ns3.google.com.     172800  IN  A   216.239.36.10
ns4.google.com.     172800  IN  A   216.239.38.10

Continuing with one of the google.com. name servers:

$ dig @216.239.34.10 www.google.com. A
;; opcode: QUERY, status: NOERROR, id: 7744
;; flags: qr aa rd; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.google.com.            IN  A

;; ANSWER SECTION:
www.google.com.     300 IN  A   173.194.32.50
www.google.com.     300 IN  A   173.194.32.49
www.google.com.     300 IN  A   173.194.32.52
www.google.com.     300 IN  A   173.194.32.48
www.google.com.     300 IN  A   173.194.32.51

We finally received an authoritative answer (aa) for the same name we asked for.

Related Question