DHCP


DHCP (Dynamic Host Configuration Protocol) is the automation engine of networking.

Without DHCP, network administrators would have to manually walk over to every single computer, printer, and phone in an office and type in a unique IP address. If they made a typo and gave two devices the same IP, both would break (IP Conflict).

DHCP prevents this by acting as the Hotel Receptionist of the network.

The Core Concept: "The Lease"

When you walk into a hotel, you don't own the room. You are given a key card for Room 205. You can use it for 3 days. After 3 days, if you don't renew it, the receptionist takes the room back and gives it to someone else.

  • The Guest: Your Computer (identified by its MAC Address).

  • The Receptionist: The DHCP Server (usually your Router).

  • The Room Number: The IP Address.

  • The Stay Duration: The Lease Time.

How it works: The "DORA" Process

This is the standard interview answer for how DHCP works. It involves four steps that happen the millisecond you connect to Wi-Fi or plug in a cable.

  1. D - Discover: Your computer wakes up. It has a MAC address but no IP. It shouts to the whole network (Broadcast): "Is there a DHCP server here? I need an IP!"

  2. O - Offer: The DHCP server hears the shout. It checks its pool of available numbers. It replies: "I hear you, MAC address XYZ. I can offer you IP 192.168.1.50."

  3. R - Request: Your computer sees the offer and replies: "Great, I will take 192.168.1.50."

  4. A - Acknowledge: The server finalizes it: "Okay, I've written it down. 192.168.1.50 is yours for 24 hours. Here is the Subnet Mask and Gateway info too."

Visualizing the DORA Process

Here is a sequence diagram showing the conversation between the Client (your laptop) and the Server (Router).

Why this matters for Cloud Infrastructure

When you use AWS, Azure, or Google Cloud, you rely on DHCP heavily, even if you don't see it.

A. Booting Virtual Machines (EC2)

When you click "Launch Instance" in AWS:

  1. AWS creates a virtual hard drive and a virtual network card (NIC) with a new MAC address.

  2. The instance boots up.

  3. The OS (Linux/Windows) runs the DORA process.

  4. The AWS VPC (Virtual Private Cloud) has a hidden DHCP server that catches this request and assigns the Private IP (e.g., 10.0.0.5) to that instance.

  5. This is why you can't hard-code static IPs inside the operating system of a cloud server. If you force Linux to use 10.0.0.5 inside its config files, but AWS DHCP thinks it should be 10.0.0.9, your server will become unreachable. You must let DHCP handle it.

B. Static vs. Dynamic (Reservations)

  • Dynamic DHCP: Good for laptops and phones. Their IP might change tomorrow. No one cares.

  • Static DHCP (Reservation): Vital for Servers.

    • If you run a Database Server, you don't want its IP changing every time it reboots.

    • In the cloud, when you "assign a specific private IP" to an instance via the AWS Console, you are actually creating a DHCP Reservation. You are telling the cloud DHCP server: "Whenever you see MAC Address X, ALWAYS give it IP Y."

Summary

  • MAC: The permanent ID card (Hardware).

  • IP: The temporary room number (Location).

  • DHCP: The receptionist that assigns the room number to the ID card.


Last updated