Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

DNS

DNS (Domain Name System) maps human names to IP addresses using a global hierarchical database with caching and delegation, and engineers use it to design, troubleshoot and optimise name resolution performance and reliability.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

DNS is the system that turns human-friendly domain names (like www.example.com) into IP addresses used by routers and hosts. Engineers use DNS knowledge when they design networks, troubleshoot web and email failures, configure caching and load balancing, and reason about latency, availability and security of services.

Key ideas

Start with the basic definitions (I define each term before using it):

  • Domain Name System (DNS): the distributed, hierarchical database and protocol that maps domain names to network resource data (most commonly IP addresses). DNS runs over UDP (usually) and TCP (for large responses or zone transfers) and is an application-layer protocol in the Internet protocol suite. Default port is 53 for both UDP and TCP. Without EDNS(0), UDP responses are limited to 512 bytes and larger answers set the TC (Truncated) bit to signal TCP retry; with EDNS(0), clients advertise a larger UDP payload size (often 1232–4096 bytes).
  • Domain name: a human-readable label built from components (labels) separated by dots, read right-to-left as a hierarchy (e.g., www.example.com where com is a top-level domain). Labels are case-insensitive; each label is up to 63 octets and the full domain name up to 255 octets. Traditional DNS names use letters, digits, and hyphen; internationalized names use IDNA/punycode (xn--).
  • Resolver (or DNS resolver): software that answers application requests by performing the necessary DNS queries. There are two roles: stub resolver and recursive resolver.
    • Stub resolver: a minimal resolver inside an end-host application (OS library) that sends queries to a recursive resolver and waits for answers.
    • Recursive resolver: a server that takes a name query from a stub resolver and performs the full sequence of queries on the DNS hierarchy until it can return a final answer. It performs iterative queries (RD=0) to upstream authoritative servers on behalf of the client.
  • Authoritative name server: a DNS server that holds the definitive records (zone data) for a domain and can directly answer queries for names in that zone.
  • Iterative query: a mode where the server returns the best answer it has (often a referral to another name server) and the client (resolver) continues querying the referred server.
  • Recursive query: a mode where the server performs further queries on behalf of the client until it can return a final answer or an error.
  • Caching: storing DNS answers for a period to avoid repeated queries and reduce latency and load. The storage time is controlled by TTL (Time To Live), a field in DNS resource records (measured in seconds).
  • Common DNS record types: A (IPv4 address), AAAA (IPv6), NS (name server delegation), CNAME (alias to another name), MX (mail exchanger), SOA (start of authority — zone metadata), PTR (reverse mapping via in-addr.arpa/ip6.arpa), TXT (text), DS (delegation signer for DNSSEC).

DNS resolution path (what to draw and label): draw a left-to-right diagram with: "Client (stub resolver)" -> arrow to "Recursive resolver" -> arrow to "Root server (.)" -> arrow to "TLD server (e.g., com)" -> arrow to "Authoritative server (example.com)". Label arrows with the query type (usually UDP), and on each server box show it returns either a referral (NS records + glue IPs) or an authoritative answer. Also draw a side box for local cache on the recursive resolver and label TTL on cached entries. Indicate that the stub-to-recursive query has RD=1, while the recursive resolver uses iterative queries (RD=0) to the root/TLD/authoritative servers.

Delegation and referrals: the root zone contains NS records delegating each TLD to its authoritative servers. Each step returns NS records for the next zone; recursion or iteration continues until an authoritative server for the queried name is reached.

Caching semantics and correctness: caches obey TTL values in seconds; a cached record is valid for the TTL from the time it was received. Negative caching (caching of NXDOMAIN responses) is permitted and controlled by the SOA or NSEC records; negative TTLs are typically shorter. Per RFC 2308, the negative TTL is the lesser of the SOA.MINIMUM field and the SOA RR's TTL, and negative caching applies to both NXDOMAIN and NODATA (NOERROR with empty answer) responses.

Performance and reliability ideas: caching reduces latency and root/TLD load. Recursive resolvers may use multiple root and TLD instances for resilience. DNS responses can be signed (DNSSEC) for authenticity — DNSSEC adds additional record types (RRSIG, DNSKEY) and larger response sizes, which can push DNS over TCP or trigger EDNS0 usage. DNSSEC establishes a chain of trust using DS records in the parent zone that point to DNSKEYs in the child zone.

Security basics: DNS is vulnerable to spoofing unless DNSSEC is used; common attacks include cache poisoning and DDoS amplification using open resolvers. Privacy-focused transports like DNS over TLS (DoT) and DNS over HTTPS (DoH) encrypt resolver traffic but do not by themselves authenticate DNS data; they complement, not replace, DNSSEC.

Assumptions stated where used: when we use probabilistic models of client query arrival times we will explicitly state the arrival process (e.g., Poisson) and independence assumptions.

Formulas

H = 1 - e^{-λ·TTL}

  • H: cache hit probability for a particular DNS name under the assumption that queries for that name arrive as a Poisson process with rate λ (in s^-1) and TTL is in seconds. Applies when inter-arrival times are exponential and TTL is fixed.

E[T] = H·t_local + (1 - H)·t_miss

  • E[T]: expected resolution time (seconds) observed by a client.
  • H: cache hit probability (dimensionless).
  • t_local: time to answer from cache (seconds).
  • t_miss: time cost when the name is not in cache, including recursive queries to authoritative servers (seconds).

t_miss ≈ t_rec + t_root + t_tld + t_auth

  • t_rec: processing time at recursive resolver (seconds).
  • t_root, t_tld, t_auth: network round-trip times to root, TLD, and authoritative servers respectively (seconds). This additive model assumes queries are mostly sequential; parallelisation can reduce sum.

HitRate = Hits / TotalQueries

  • HitRate: empirical cache hit fraction over measurement window (dimensionless).
  • Hits: number of queries served from cache (count).
  • TotalQueries: total queries received (count).

Note: TTL is measured in seconds (SI unit second, s). Latencies t_x are in seconds (commonly presented in milliseconds, 1 ms = 0.001 s).

Worked examples

Example 1 — Cache hit probability (numerical): Given: query arrival rate λ = 0.001 s^-1 (one query every 1000 s ~ 16.7 min), TTL = 3600 s (1 hour). Use the Poisson-arrival model.

  1. Formula: H = 1 - e^{-λ·TTL}
  2. Compute exponent: λ·TTL = 0.001 × 3600 = 3.6
  3. e^{-3.6} ≈ 0.02732
  4. H = 1 - 0.02732 = 0.97268 Final answer: cache hit probability H ≈ 0.973 (97.3%).

Example 2 — Expected resolution time: cache hit vs miss Given: H = 0.6 (60% hits), t_local = 5 ms = 0.005 s, t_rec = 1 ms = 0.001 s, t_root = 20 ms = 0.020 s, t_tld = 30 ms = 0.030 s, t_auth = 40 ms = 0.040 s. Assume sequential queries for miss so t_miss = t_rec + t_root + t_tld + t_auth.

  1. Compute t_miss: 0.001 + 0.020 + 0.030 + 0.040 = 0.091 s (91 ms).
  2. Formula: E[T] = H·t_local + (1 - H)·t_miss.
  3. E[T] = 0.6 × 0.005 + 0.4 × 0.091 = 0.003 + 0.0364 = 0.0394 s. Final answer: expected resolution time E[T] ≈ 0.0394 s (39.4 ms).

Example 3 — Step-by-step trace (theory question): resolving www.example.com using recursive resolver

  1. Client (stub) asks recursive resolver: "A record for www.example.com" (UDP).
  2. Recursive has no cache; sends an iterative query (RD=0) to a root server for www.example.com. Root replies with NS records for .com and glue IPs (referral).
  3. Recursive queries one .com TLD server for www.example.com. TLD responds with NS records for example.com authoritative servers.
  4. Recursive queries an authoritative server for example.com. Authoritative server replies with an A record for www.example.com.
  5. Recursive caches the A record with the TTL from the response and returns the A record to the stub resolver. If iterative queries are used by the client (rare), the client repeats steps itself following referrals until it reaches the authoritative server.

Common mistakes

  • Forgetting negative caching (NXDOMAIN) can also be cached, usually with its own TTL from SOA.
  • Using the Poisson-derived hit probability without stating the arrival-process assumption; students often omit assumptions.
  • Adding round-trip times incorrectly: recursive resolvers can query some servers in parallel; assuming strictly sequential adds pessimistic latency.
  • Ignoring UDP and TCP roles: large DNS responses or zone transfers use TCP; DNSSEC makes responses larger and may force TCP.

For your exam

Typical question forms and what full-marks answers include:

  • Definitions: give clear definitions and differences (e.g., recursive vs iterative, authoritative vs recursive), plus examples.
  • Short notes: describe DNS hierarchy, record types (A, AAAA, CNAME, NS, SOA, MX), and TTL semantics; include a drawn diagram of the resolution path and label each box and arrow. Also outline the DNS message format (header flags QR, Opcode, AA, TC, RD, RA, RCODE; sections Question/Answer/Authority/Additional) and state the default port number (53).
  • Derivations: derive cache hit probability assuming Poisson arrivals (show exponential inter-arrival distribution and integrate); state assumptions clearly.
  • Numericals: compute hit probabilities, expected resolution time given latencies and TTL, show all steps, include units and final answer with units.
  • Protocol trace/algorithm: step-by-step trace of queries and responses for resolving a name (include referrals, authoritative answers and caching action).
  • Practical/config tasks (less common in theory exam): show usage/syntax of dig or nslookup to query DNS (useful to mention but not required unless a lab question).

A full-marks answer will: define terms, state assumptions, present diagrams where asked, show stepwise algebra for derivations, carry units and compute final numbers, and mention real-world caveats (e.g., parallelisation, DNSSEC, TCP fallback).

Quick check

  1. What does TTL in a DNS record measure?
  2. Name two record types used to point an email to a mail server and to alias one name to another.
  3. Under a Poisson arrival model with rate λ, what is the probability that the next query for a name arrives within TTL seconds?

Answers: TTL measures how long (in seconds) a cached DNS record may be used; MX for mail exchanger and CNAME for alias; 1 - e^{-λ·TTL}.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?