Domain Name System (DNS)
1. Concept and Purpose of DNS
Computers and routers route packets using numerical IP addresses (e.g., 142.250.190.46), but humans remember alphanumeric names (e.g., www.google.com).
The Domain Name System (DNS) (RFC 1034 / 1035) is a hierarchical, distributed database system that acts as the "phonebook of the Internet," mapping human-readable hostnames to numerical IP addresses.
2. Hierarchical Domain Name Space
The domain namespace is structured as an inverted tree with the Root at the top:
Hierarchy Levels:
- Root Domain (
.): Represented by a null string or dot at the top of the tree. Supervised by ICANN and operated across 13 worldwide root server clusters (A through M). - Top-Level Domains (TLD):
- Generic TLDs (gTLD):
.com(commercial),.org(non-profit),.edu(education),.gov(government). - Country-Code TLDs (ccTLD): Two-letter country codes:
.in(India),.uk(United Kingdom),.us(United States).
- Generic TLDs (gTLD):
- Second-Level Domains: Registered by individuals or corporations (e.g.,
google.com,wikipedia.org). - Subdomains: Created by the domain owner to organize internal services (e.g.,
mail.google.com,cs.stanford.edu).
- FQDN (Fully Qualified Domain Name): Absolute name terminated with a trailing dot (
www.example.com.). - PQDN (Partially Qualified Domain Name): Relative name without trailing dot (
www).
3. The DNS Resolution Process
DNS resolution combines Recursive and Iterative queries:
- Recursive Query (Client to Local DNS Resolver): The client demands that the local resolver do all the legwork to resolve the name or return an error.
- Iterative Query (Local Resolver to Hierarchy Servers): The server contacted responds with the best referral it has ("I don't know the exact IP, but ask this next server").
- Caching & TTL: The local resolver caches the resolved IP for the duration specified in the TTL (Time to Live) field, instantly serving future requests without querying the Internet.
4. DNS Resource Record (RR) Types
The DNS database stores entries called Resource Records (RRs):
| Record Type | Full Name | Purpose | Example |
|---|---|---|---|
| A | Address Record | Maps hostname to 32-bit IPv4 address | example.com. IN A 93.184.216.34 |
| AAAA | IPv6 Address | Maps hostname to 128-bit IPv6 address | example.com. IN AAAA 2606:2800:220:1:: |
| CNAME | Canonical Name | Creates an alias pointing to the true name | www.example.com. IN CNAME example.com. |
| MX | Mail Exchange | Directs incoming email to mail servers | example.com. IN MX 10 mail.example.com. |
| NS | Name Server | Delegates a DNS zone to an authoritative server | example.com. IN NS ns1.example.com. |
| PTR | Pointer Record | Reverse DNS: Maps IP address to Hostname | 34.216.184.93.in-addr.arpa IN PTR example.com. |
| SOA | Start of Authority | Stores zone administrative metadata and serial | Primary NS, Admin email, Refresh timers |
| TXT | Text Record | Human-readable text; SPF/DKIM email verification | v=spf1 include:_spf.google.com ~all |
5. Transport Protocol Usage: UDP vs. TCP on Port 53
DNS uses Well-Known Port 53 on both UDP and TCP:
- UDP Port 53: Used for standard client queries and responses. Standard DNS messages are under ; UDP avoids connection handshake latency.
- TCP Port 53: Used for Zone Transfers (replicating entire DNS databases between primary and secondary name servers) and responses exceeding (or DNSSEC) requiring reliable transmission.
Frequently Asked Questions
QDifferentiate Recursive and Iterative DNS queries.
In a Recursive query, the client places the entire resolution burden on the queried server, which must return either the resolved IP or an error. In an Iterative query, the contacted server returns the IP of the next authoritative server down the chain if it cannot answer directly.
QWhen does DNS use TCP instead of UDP?
For Zone Transfers between primary and secondary DNS servers to ensure database replication integrity, and when query responses exceed the 512-byte UDP packet limit (e.g., DNSSEC).
QWhat is Reverse DNS lookup and which record type performs it?
Reverse DNS resolves a known IP address back into its domain hostname using PTR (Pointer) records inside the special in-addr.arpa domain.
QWhat is the difference between an FQDN and a PQDN?
An FQDN is an absolute name ending with a trailing dot (www.example.com.) that specifies the full path from the root. A PQDN is a relative name without the trailing dot (www) that the resolver completes using a default domain suffix.
QWhat role does TTL play in DNS caching?
TTL (Time to Live) tells resolvers how long they may cache a record. Within that time, repeat queries are answered from the cache without contacting upstream servers. A long TTL reduces load but slows propagation of changes.