The labs on this site need JavaScript to run. The same content is written out below.
Fundamentals › Networking
What does DNS turn a name into?
Computers connect to each other by IP address (a number), but people use names like shop.example. DNS is the service that turns a name into an IP address, and a DNS server is a computer that holds a table listing each name with its IP address. The code box on the screen has two parts. The upper part is what is registered on the DNS server (name → IP address), and the lower part is the address the client tries to reach. A client that connects by name first asks the DNS server for the IP address of that name, before it connects to the server, and then connects to the IP address it got in the answer. In this lab you leave the name unregistered, register it with a different IP address, or write an IP address directly in the address instead of a name, and make the same connection each time, to see how many times the DNS server is asked and which computer is reached. The 8080 on the screen is a port number written as an example.
Checked against real execution · Ran all 6 combinations on Node.js 24.18.0 with a small DNS server (RFC 1035 messages) started inside 127.0.0.x, a dns.Resolver client, and two HTTP servers, and checked against the results
# Registered on the DNS server (name → IP address) shop.example 127.0.0.1 # The address the client tries to reach http://shop.example:8080/
All 6 combinations were checked against real execution, entirely within the 127.0.0.x addresses of the PC used to write this lab. No outside network and no actual DNS settings of this PC were asked. The DNS server is a small server started with dgram in Node.js 24.18.0 on a free UDP port of 127.0.0.1. Its messages were built by hand in the format of RFC 1035 section 4.1 (a 12-byte header, a question, and an answer). It answers an A query for a name in its registration table with that IP address, and it answers a name that is not in the table with RCODE 3 (Name Error, section 4.1.1). The client reads the two parts of the code box as written. If the host of the address is not an IP address according to net.isIP, it asks with resolve4 of a dns.Resolver whose only server is set to the server above with setServers, and it sends an HTTP request to the IP address it received. If the host is an IP address, it sends the request directly without calling the Resolver. The flow shown on the screen, "ask first if it is a name, and do not ask if it is an IP address", was made the same as the flow of this probe. The name resolution order of the operating system, the hosts file, the caches of browsers and operating systems, and recursive resolvers were not covered, and it was not checked whether a real browser works in the same order as this probe. Those details are covered in the in-depth lab "DNS". As servers, two HTTP servers were started on 127.0.0.1 and 127.0.0.2 with the same port number. The 8080 on the screen is an example number and a free port was actually used, and 127.0.0.2 imitates a "different computer" but is actually a different loopback address of the same PC. On the PC used to write this lab (Windows), the server bound to 127.0.0.2 right away. What was checked against is the number and kind of queries the DNS server received, the RCODE of the no-such-name answer, the answer the client received, the destination IP address of the connections the servers received, the status and body of the response, the order in which the query comes before the connection in the combinations with a name, and the fact that neither server received a connection or a request when the answer was no such name. "Times the DNS server was asked" is the number of A queries the DNS server received. This Resolver sent no queries of a kind other than A, and it did not ask again after receiving the no-such-name answer, so the number of queries and the number of A queries were the same. This is what was observed with the default settings of this Node.js version. That Node.js reports the no-such-name answer as an ENOTFOUND error is also observed behavior. The DNS server is not an independent implementation but one made for this lab, and what read its answers is dns.Resolver (c-ares) of Node.js, so it is checked against the outside only in the sense that the DNS messages were read by an independent implementation, and it was not checked against a DNS server that is actually in operation. What was checked against the documentation is RFC 1034 section 5.2.1 (a request to turn a host name into a host address becomes a request for an A record, and a name error is returned if the name does not exist), section 3.6 (resource records), section 4.3.1 (the response saying that the name does not exist), RFC 1035 section 3.4.1 (an A record is a 32-bit internet address), sections 4.1 and 4.1.1 (message format, RCODE 3 Name Error), and RFC 6761 section 6.5 (names ending in .example are reserved for documentation and are not registered). Registering several IP addresses for one name and using AAAA records were not covered, and the server code on the screen is not shown.
Previous lab: URLs · Next lab: HTTP requests
Struck-through text was removed from the first version of the code; highlighted text was added.