People remember names such as www.example.com, but packets need IP addresses. DNS translates one into the other, for almost every connection made on the internet.

The DNS Hierarchy

DNS is a distributed, hierarchical database. The root (written as a dot) sits at the top, served by 13 named root server systems with many copies worldwide. Below it are top-level domains (TLDs): generic ones such as .com, .org and .edu, and country codes such as .in. Below those are second-level domains, such as example.com, and then subdomains, such as www.example.com or mail.example.com. Each part of the tree is a zone, managed by authoritative name servers that hold its records. A fully qualified domain name (FQDN) gives the complete path, such as www.example.com.

Definition: DNS. The Domain Name System, a distributed hierarchical database and protocol that translates domain names into IP addresses and other records.

Resource Records

DNS stores resource records: A (name to IPv4 address), AAAA (name to IPv6 address), CNAME (an alias for another name), MX (the mail server of a domain, with a priority), NS (the authoritative name servers of a zone), PTR (reverse lookup, address to name), TXT (text, used for email security such as SPF) and SOA (start of authority for a zone). Each record has a TTL (time to live) saying how long it may be cached.

Name Resolution

When a browser needs www.example.com, the stub resolver on the computer asks a recursive resolver (from the ISP, or a public one such as 8.8.8.8 or 1.1.1.1). If the answer is not cached, the recursive resolver performs iterative queries: it asks a root server, which refers it to the .com TLD server, which refers it to the authoritative server for example.com, which returns the A record. The resolver returns the address to the client and caches it for the TTL. The browser, the operating system and the resolver all cache answers, so most lookups are very fast. DNS normally uses UDP port 53, and TCP for large responses and zone transfers. The command nslookup or dig queries DNS.

DNS Security

DNS was not designed with security. In DNS spoofing (cache poisoning), forged answers send users to fake sites. DNSSEC adds digital signatures so that answers can be verified, and DNS over HTTPS (DoH) and DNS over TLS (DoT) encrypt queries for privacy.

Table 4.3: DNS record types

Type Maps Example
A Name to IPv4 www → 93.184.216.34
AAAA Name to IPv6 www → 2606:2800::1
CNAME Alias to name blog → www.example.com
MX Domain to mail server example.com → mail.example.com
NS Zone to name server example.com → ns1.example.com

Example 4.3: Tracing a DNS resolution

Problem: A student types notes.college.edu in a browser for the first time. List the queries made and what is cached afterwards.

Solution:

  1. The browser and OS caches have no entry, so the stub resolver asks the recursive resolver.
  2. The resolver asks a root server, which refers it to the .edu TLD servers.
  3. The .edu server refers it to the authoritative servers for college.edu.
  4. The authoritative server returns the A record for notes.college.edu.
  5. The resolver returns the address and caches it; a second lookup is answered from the cache.

Result: Three referral steps the first time; zero network queries to the hierarchy the second time.

hierarchy = {".": {"edu": "edu-tld"},
             "edu-tld": {"college.edu": "ns.college.edu"},
             "ns.college.edu": {"notes.college.edu": "10.20.30.40"}}
cache = {}
def resolve(name):
    if name in cache:
        return cache[name], ["cache hit"]
    steps, server = [], "."
    keys = ["edu", "college.edu", name]
    for k in keys:
        steps.append(f"ask {server:<15} for {k}")
        server = hierarchy[server][k]
    cache[name] = server
    return server, steps
for attempt in (1, 2):
    ip, steps = resolve("notes.college.edu")
    print(f"lookup {attempt}: {ip}")
    for s in steps:
        print("   ", s)

Output

lookup 1: 10.20.30.40
    ask .               for edu
    ask edu-tld         for college.edu
    ask ns.college.edu  for notes.college.edu
lookup 2: 10.20.30.40
    cache hit

Common mistakes

  • Thinking one central server holds all names. DNS is distributed.
  • Confusing a CNAME (alias) with an A record (address).
  • Forgetting caching and TTLs, which explain why DNS changes take time to spread.

Key takeaways

  • DNS translates names to addresses using a hierarchy: root, TLD, authoritative.
  • Records: A, AAAA, CNAME, MX, NS, PTR, TXT and SOA, each with a TTL.
  • Recursive resolvers query iteratively and cache answers.
  • DNS uses UDP port 53; DNSSEC, DoH and DoT add security.

Practice questions

  1. Which DNS record gives a domain's mail server?
  2. What is a recursive resolver?
  3. Which port does DNS use?

Answers to the practice questions

  1. The MX record.
  2. A server that finds the full answer for a client by querying the hierarchy and caching results.
  3. Port 53, mainly over UDP.

Sources

  • Official BCA syllabus Computer Networks, course code 26BCA404DS02, Unit IV