DNS and DHCP
DNS - Domain Name System
DNS is the "phone book" of the Internet. It translates human-readable domain names (like www.google.com) into IP addresses (like 142.250.80.46) that computers use to communicate.
DNS Hierarchy
- Root DNS Servers: The top of the DNS hierarchy. There are 13 root server clusters (labeled A through M) worldwide. They know the addresses of all TLD servers.
- TLD (Top-Level Domain) Servers: Manage domains like .com, .org, .net, .edu, .uk, .in. They know the addresses of authoritative name servers.
- Authoritative Name Servers: Hold the actual DNS records for specific domains. Managed by domain owners or their DNS providers.
- Recursive Resolver: The DNS server your ISP or organization provides. It queries other DNS servers on your behalf and caches results.
DNS Resolution Process
- User types
www.example.comin browser - Browser checks its local DNS cache
- If not cached, OS checks its hosts file (
/etc/hosts) - If not found, query goes to the Recursive Resolver (ISP's DNS)
- Resolver checks its cache; if not found, queries a Root Server
- Root server responds with the address of the .com TLD server
- Resolver queries the .com TLD server, which responds with the authoritative name server for example.com
- Resolver queries the authoritative server, which returns the IP address
- Resolver caches the result and returns it to the client
- Browser connects to the IP address
DNS Record Types
| Record Type | Purpose | Example |
|---|---|---|
| A | Maps domain to IPv4 address | example.com → 93.184.216.34 |
| AAAA | Maps domain to IPv6 address | example.com → 2606:2800:220:1:248:1893:25c8:1946 |
| CNAME | Alias — maps one domain to another | www.example.com → example.com |
| MX | Mail exchange — specifies mail servers | example.com → mail.example.com (priority 10) |
| NS | Name server — specifies authoritative DNS servers | example.com → ns1.example.com |
| PTR | Reverse DNS — maps IP to domain name | 93.184.216.34 → example.com |
| TXT | Text records — SPF, DKIM, domain verification | v=spf1 include:_spf.google.com ~all |
| SOA | Start of Authority — zone information | Primary NS, admin email, serial number, TTL |
| SRV | Service location records | _http._tcp.example.com → server:port |
DHCP - Dynamic Host Configuration Protocol
DHCP automatically assigns IP addresses and other network configuration (subnet mask, default gateway, DNS servers) to devices on a network. Without DHCP, every device would need to be manually configured.
DHCP DORA Process
DHCP uses a 4-step process called DORA to assign IP addresses:
- Discover: Client broadcasts a DHCPDISCOVER message to find available DHCP servers. Source: 0.0.0.0, Destination: 255.255.255.255
- Offer: DHCP server responds with a DHCPOFFER containing an available IP address, subnet mask, lease duration, and other options.
- Request: Client broadcasts a DHCPREQUEST to accept the offered IP address (and inform other DHCP servers it's declining their offers).
- Acknowledge: DHCP server sends a DHCPACK confirming the IP address assignment. The client can now use the IP address.
DHCP Lease and Static vs Dynamic IP
| Feature | Static IP | Dynamic IP (DHCP) |
|---|---|---|
| Assignment | Manually configured | Automatically assigned by DHCP |
| Changes | Never changes | May change on lease renewal |
| Management | Complex (manual tracking) | Easy (centralized) |
| Use Case | Servers, printers, routers | Workstations, laptops, phones |
| Cost | Higher (ISP charges) | Lower |
Ready to Level Up Your Skills?
Explore 500+ free tutorials across 20+ languages and frameworks.