DNS: finding the server
A name is not an address
Section titled “A name is not an address”A client does not send packets to www.example.com. It sends them to an address, a number such as 192.0.2.10. The Domain Name System, DNS, is what turns the first into the second, and it runs before nearly every request a client makes to a server it has not talked to recently.
DNS is a hierarchy, and it is distributed. The names form a tree, and the tree is cut into zones. Each zone has at least one authoritative server, the one that holds the answer for the names in that zone. A zone passes responsibility for a part of its tree to another zone by a delegation: a record that says which servers to ask next. RFC 1034 describes the structure: the root of the tree delegates to the servers of .com, which delegate to the servers of example.com, which know the address of www.example.com.
Mental model. A name lookup is a series of referrals. Each server either knows the answer or says who is closer to it. The device does not do the legwork: it asks a recursive resolver, which does, and which remembers what it learns.
What a lookup costs
Section titled “What a lookup costs”Your device asks its recursive resolver, often run by an internet provider or by a public service. If the resolver has the answer in its cache, it replies at once. If not, it follows the delegations, as RFC 1034’s algorithm says: it looks for the closest name servers it already knows, starting from the name and working back toward the root, and asks them. Each answer either holds the address or points to servers closer to it.
The lab below shows the messages for the same lookup under four conditions, at two round-trip times: the one between your device and its resolver, which is short, and the one between the resolver and each DNS server on the internet, which is longer. Step through the first variant to see the delegations followed.
Looking up a name
The resolver has nothing cached for this name, so it follows the delegations from the root down: root, then .com, then the domain's own server.
- Your device asks its resolver5 msYour device to Recursive resolver: www.example.com ?. Arrives at 5 ms.www.example.com ?
- The resolver asks a root server25 msRecursive resolver to Root server: Who serves .com?. Arrives at 25 ms.Who serves .com?
- 45 msRoot server to Recursive resolver: Ask the .com servers. Arrives at 45 ms.Ask the .com servers
- The resolver asks a .com server65 msRecursive resolver to .com server: Who serves example.com?. Arrives at 65 ms.Who serves example.com?
- 85 ms.com server to Recursive resolver: Ask ns1.example.com. Arrives at 85 ms.Ask ns1.example.com
- The resolver asks the authoritative server105 msRecursive resolver to Authoritative server: www.example.com ?. Arrives at 105 ms.www.example.com ?
- 125 msAuthoritative server to Recursive resolver: 192.0.2.10. Arrives at 125 ms.192.0.2.10
- Your device asks its resolver130 msRecursive resolver to Your device: 192.0.2.10. Arrives at 130 ms.192.0.2.10
Time until your device has the address: 130 ms
Model notes
Assumptions
- Each message takes half the round-trip time of the link it crosses. Messages are never lost, never queue and never overlap, and each leaves when the one before it has arrived, once its receiver has finished any processing.
Simplifications
- Real resolvers keep each answer in a cache for as long as its time to live allows, so most lookups are one of the shorter variants. The longest chain is drawn for a name that none of the caches holds.
- Real lookups also ask for IPv6 addresses, can be answered over TCP when a response is too long for one datagram, and may try several servers of the same zone. Only the sequence of referrals is drawn.
Parameter values are illustrative. They are not benchmarks of any real product.
With the defaults, a lookup where nothing is cached takes 130 ms: 10 ms between your device and the resolver, and three round trips of 40 ms to the root server, the .com server and the authoritative server. If the resolver already knows the .com servers, which is the usual case, the root is skipped and the lookup takes 90 ms. If it also knows which server is authoritative for the domain, it takes 50 ms. If it has the answer cached, only your device’s own round trip is left: 10 ms.
Raise Round trip to each DNS server to 100 ms, and the first of these becomes 310 ms while the last stays at 10 ms. A cache does not make the network faster. It removes round trips. This is the same pattern as every cache in the course, and the reason the hit rate is the number to watch.
The time to live
Section titled “The time to live”How long may the resolver keep an answer? Each record carries a time to live, a TTL. RFC 1035 defines it as the time interval that the record may be cached before the source of the information should again be consulted, and says that a zero means the record is to be used only for the transaction in progress and not cached.
The owner of the zone chooses it, and it is a trade-off.
- A long TTL means fewer lookups. A resolver that is asked for the name all day asks the authoritative server at most once per TTL: 86,400 ÷ 300 = 288 times a day for a TTL of five minutes, and once a day for a TTL of a day. Most users also get the fast, cached answer.
- A short TTL means changes take effect sooner, but each cache holds the answer for less time, so more lookups go the long way. At a TTL of 60 seconds, the same resolver asks 1,440 times a day.
What happens if you change the address of a service?
Section titled “What happens if you change the address of a service?”A team moves a service to a new data centre, so its address changes. Resolvers that looked the name up just before the change hold the old address, and they keep handing it out until its TTL runs out. With a TTL of one day, some clients can keep reaching the old address for up to 24 hours after the change. With a TTL of five minutes, the longest is 5 minutes.
This assumes that every cache respects the TTL, which is the most that the TTL can promise. It also means that lowering the TTL does not help at once. A record cached a minute ago, with a TTL of a day, will not be looked at again for a day, and so the new, shorter TTL only takes effect after the old one has run out. A team that plans a change lowers the TTL at least one old TTL ahead of it, makes the change, and raises the TTL again afterwards.
DNS is a dependency of every request
Section titled “DNS is a dependency of every request”A client that cannot resolve a name cannot find the server, however healthy the server is. If the resolver is unreachable and the answer is not cached, the request fails before it has left the device. That makes DNS a hard dependency, in the terms of the dependencies lesson, of every request that goes by name, and the reason that the answers’ TTLs, the number of authoritative servers and their placement are availability decisions as well as performance ones. The long TTL has a second benefit here: a name whose answer is still cached keeps working while its authoritative servers are down, until the TTL runs out.
- DNS turns a name into an address. It is a tree of zones, each with authoritative servers, joined by delegations that say whom to ask next.
- A recursive resolver does the legwork for your device: from the root to
.comto the domain’s own server, and it caches what it learns. - With 10 ms to the resolver and 40 ms to each DNS server, a lookup takes 130 ms with nothing cached, 90 ms with the
.comservers known, 50 ms with the domain’s server known, and 10 ms with the answer cached. A cache removes round trips. - A time to live is how long an answer may be cached. A long one means fewer lookups and slower changes: 288 lookups a day per resolver at five minutes, one at a day.
- After a change, the old address can still be used for up to one TTL, so lower the TTL before a planned change.
- DNS is a hard dependency of every request made by name.
Next: TCP and UDP, and the round trip that a connection costs before any data moves.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.