Computer Networking › Section B · The application layer › Topic B.4
DNS: the internet's directory service
People remember names such as www.example.org, but packets are delivered to IP addresses. The Domain Name System translates one into the other billions of times a day, using a distributed database that no single organisation holds and that works because almost every answer is cached.
What DNS provides
The Domain Name System (DNS), designed by Paul Mockapetris in 1983 and specified today in RFCs 1034 and 1035, is both a distributed database of name servers and an application-layer protocol for querying it. Its main service is translating host names to IP addresses. It also supports aliasing, so a short, memorable name can point to a long canonical name; mail routing, by naming each domain's mail servers; and load distribution, by returning several addresses for a busy site and rotating their order. Queries usually travel over UDP on port 53, with TCP used for large answers. Almost every web visit or email starts with a DNS lookup.
Why not one central server?
One server holding every name would be a single point of failure, face an impossible query load, sit far from most users and need every change on the internet made in one place. DNS instead spreads the work over a hierarchy of servers, each responsible for one part of the name space, called a zone. Delegation lets each organisation run its own part, and caching lets most queries be answered close to the user. The Computer Science topic "The internet: architecture and addressing" introduced this hierarchy.
The hierarchy of servers
Names are read from right to left. At the top are the root servers: 13 named identities, a.root-servers.net to m.root-servers.net, run by 12 organisations and copied at well over a thousand sites worldwide using anycast, so a query reaches a nearby copy. Root servers know the servers for each top-level domain (TLD), such as .com, .org or country codes like .jp. TLD servers know the authoritative servers for each domain registered under them. A domain's authoritative servers hold its actual records, and an organisation may run them itself or pay a provider.
Resolvers: recursive and iterative queries
A host does not search the hierarchy itself. It sends one query to its local recursive resolver, run by its ISP, its organisation or a public service. That is a recursive query: the host expects a final answer. If the answer is not cached, the resolver works down the hierarchy with iterative queries. The root replies with a referral to the TLD servers, the TLD server refers it to the domain's authoritative servers, and they return the answer. The resolver passes it to the host and keeps a copy. Referrals keep root and TLD servers' work light.
Worked example: timing a lookup
A laptop needs the address of www.example.org. Round-trip times are 5 ms to its resolver, 20 ms from the resolver to a root server, 30 ms to a .org server and 40 ms to example.org's authoritative server. 1. Nothing cached: the resolver asks all three in turn, so \(5 + 20 + 30 + 40 = 95\) ms. 2. The resolver already knows the .org servers, as it usually does: it skips the root and TLD, so \(5 + 40 = 45\) ms. 3. Someone asked for the same name minutes ago: the resolver answers from cache in 5 ms. Check: the full lookup sent 4 queries and got 4 replies, while the cached case used only 1 of each.
Caching and time to live
Every DNS answer carries a time to live (TTL) in seconds, set by the domain's owner. Resolvers, and often the host's own operating system, cache the answer for that long and then discard it. Popular names and TLD server lists stay cached almost all the time, so the root servers see a tiny share of lookups. TTL is a trade-off. A long TTL, such as 86,400 seconds or one day, cuts load and speeds lookups but means changes spread slowly. A short TTL, such as 300 seconds, lets an operator move a service quickly but sends more queries to the authoritative servers.
Resource records
DNS stores resource records, each with a name, a value, a type and a TTL. Type A maps a host name to an IPv4 address and AAAA to an IPv6 address. NS names an authoritative server for a domain. CNAME makes a name an alias of a canonical name. MX names a domain's mail servers, with a preference number so the lowest is tried first. TXT holds text, used for email authentication and proving ownership of a domain. SOA, start of authority, holds administrative details of a zone, such as its serial number. Queries and replies share one message format, with a 16-bit identifier that matches each reply to its query.
Worked example: moving a website
A shop's site, www.shop.example, has an A record with a TTL of 86,400 seconds, and it must move to a new server with a different address on Friday. 1. A resolver that cached the old record just before the change could keep using it for up to 86,400 s, which is 24 hours. 2. So on Wednesday, at least one full old TTL before the move, the operator lowers the TTL to 300 s. 3. By Thursday every cache holds the record with the short TTL. 4. On Friday the operator changes the address; within 300 s, which is 5 minutes, every resolver following the rules has the new one. 5. Afterwards, the TTL can be raised again.
Registering a domain
To create shop.example, its owner pays a registrar, a company accredited for that TLD, which passes the details to the registry that runs the TLD. The owner supplies the names and addresses of the domain's authoritative servers. The registry adds NS records for shop.example to the TLD servers, plus glue records, A or AAAA records giving those name servers' addresses when they sit inside the domain itself, such as ns1.shop.example. Without glue, a resolver would need the domain's own servers to find the domain's own servers. The owner then puts A, MX and other records on the authoritative servers.
Security and privacy
Classic DNS has no built-in protection. In cache poisoning, an attacker tries to get forged replies accepted by a resolver, sending users to the wrong address. DNSSEC adds digital signatures to records so resolvers can check that answers are genuine, although many domains still do not sign their zones. Ordinary queries are also unencrypted, revealing which sites a user visits; DNS over TLS (DoT) and DNS over HTTPS (DoH) encrypt the path between a device and its resolver. DNS servers are also frequent targets of denial-of-service attacks, which anycast and caching help absorb.
Common mistakes to avoid
First, thinking root servers store every name; they only refer resolvers to TLD servers. Second, saying there are only 13 root machines; there are 13 identities copied at many sites. Third, mixing up recursive and iterative queries: the host asks recursively, and the resolver usually asks iteratively. Fourth, expecting a changed record to take effect at once, when caches keep the old one until its TTL expires. Fifth, believing DNSSEC encrypts queries; it signs answers, while DoT and DoH provide encryption. Sixth, forgetting glue records when name servers sit inside their own domain.
Key takeaways
DNS is a distributed, hierarchical database and a protocol, usually over UDP port 53, that maps names to addresses and supports aliases, mail routing and load distribution. Root servers, 13 identities copied worldwide by anycast, refer resolvers to TLD servers, which refer them to authoritative servers. Hosts send recursive queries to a resolver, which follows iterative referrals and caches each answer for its TTL. Record types include A, AAAA, NS, CNAME, MX, TXT and SOA. Registrars place NS and glue records in the TLD. DNSSEC authenticates answers; DoT and DoH encrypt queries.
Flashcards
Flashcard
Domain Name System: distributed database and protocol for names
Test your understanding
Question 1 of 5
A host's RTT to its resolver is 3 ms; from the resolver, the root is 12 ms, the TLD server 25 ms and the authoritative server 40 ms. The resolver already knows the TLD's servers but not the answer. How long does the lookup take?
Question 2 of 5
What does a root server send back when a resolver asks it for the address of www.example.org?
Question 3 of 5
A company changed its A record an hour ago, but some users still reach the old server. What is the most likely reason?
Question 4 of 5
Which record tells a sending mail server where to deliver mail for a domain?
Question 5 of 5
What does DNS over HTTPS (DoH) protect against that DNSSEC does not?
