DHCP

beginner dhcp ip-address dora networking lan

DHCP (Dynamic Host Configuration Protocol) is what assigns our laptop an IP address the moment we connect to Wi-Fi. Without it, we’d manually configure IP, subnet mask, gateway, and DNS on every device.

In simple language: DHCP is the network’s receptionist — “welcome, here’s your IP, here’s the gateway, here’s the DNS server, please use them for the next few hours.”

Why DHCP Exists

Before DHCP, network admins maintained spreadsheets of IPs and assigned them by hand. Imagine doing that for a coffee shop with 50 phones connecting and disconnecting all day.

DHCP solves this by:

  • Automatically picking an unused IP from a pool.
  • Handing out network settings (gateway, DNS, subnet mask).
  • Reclaiming IPs when devices leave.

The DORA Handshake

DHCP works in four steps. We remember them as DORA.

Client (no IP yet)                    DHCP Server
       │                                    │
       │── 1. DISCOVER (broadcast) ────────>│   "Anyone got an IP for me?"
       │                                    │
       │<── 2. OFFER (broadcast) ───────────│   "Sure, take 192.168.1.42"
       │                                    │
       │── 3. REQUEST (broadcast) ─────────>│   "I'll take 192.168.1.42"
       │                                    │
       │<── 4. ACK (broadcast) ─────────────│   "Confirmed, here's the lease"
       │                                    │

Discover — the client has no IP, so it broadcasts to 255.255.255.255: “Hey any DHCP server, I need an address.” Source IP is 0.0.0.0.

Offer — one or more DHCP servers respond with a candidate IP and lease details.

Request — the client picks one offer (usually the first) and broadcasts its choice. The broadcast tells the other servers their offer was rejected so they can put the IP back in the pool.

Acknowledge — the chosen server confirms and the client commits the IP, gateway, DNS, and lease time.

What Else DHCP Hands Out

Besides the IP, a DHCP response usually includes:

  • Subnet mask255.255.255.0
  • Default gateway — the router’s IP, e.g. 192.168.1.1
  • DNS servers — e.g. 1.1.1.1, 8.8.8.8
  • Lease time — how long the IP is ours
  • NTP server (optional) — for time sync

Lease & Renewal

The IP is ours for a lease period (often 24 hours on home routers, shorter on busy networks).

  • At 50% of lease time — the client tries to renew with the same server (unicast request).
  • At 87.5% — if no answer yet, it broadcasts to any server (REBINDING).
  • If the lease fully expires — the client gives up the IP and starts DORA again.

This is why we sometimes see brief Wi-Fi hiccups when a lease expires and the device hasn’t renewed in time.

Inspect & Trigger DHCP

# Linux: see current lease
cat /var/lib/dhcp/dhclient.leases

# Linux: release & renew
sudo dhclient -r       # release
sudo dhclient          # request a new lease

# macOS: renew lease
sudo ipconfig set en0 BOOTP
sudo ipconfig set en0 DHCP

# Windows
ipconfig /release
ipconfig /renew

Interview Tip

Just remember DORA and that it’s all over UDP ports 67 (server) and 68 (client). Bonus: mention that DHCP uses broadcasts because the client has no IP yet, so it can’t direct traffic at a specific server.