C.W.K.
Stream
Lesson 06 of 12 · published

DHCP

~15 min · dhcp, lease, reservation, dora

Level 0Pinger
0 XP0/101 lessons0/12 achievements
0/150 XP to next level150 XP to go0% complete

How devices get their IP automatically

Plug a laptop into Ethernet or join a Wi-Fi network and it magically gets an IP address, a subnet mask, a default gateway, and DNS servers. That magic is DHCP (Dynamic Host Configuration Protocol). Without DHCP, every device on your network would need a manually assigned static IP — and you'd have to track them yourself.

The DORA dance

DHCP is a four-step conversation, mnemonically DORA:

  1. Discover — "Hi, anyone here speak DHCP?" The new device broadcasts to 255.255.255.255 because it doesn't have an IP yet.
  2. Offer — The DHCP server (usually your router) replies: "Here, you can have 192.168.1.42, with this subnet mask, this gateway, these DNS servers."
  3. Request — The device formally asks for that specific offer, in case multiple servers offered different addresses.
  4. Acknowledge — The server confirms: "It's yours. Lease expires in 24 hours."

Leases — IPs are rented, not given

An IP isn't yours forever. DHCP issues a lease for a configurable period (24 hours is common at home, much shorter on busy networks). Your device renews the lease in the background before it expires. If a device disappears, the IP eventually returns to the pool.

Reservations — predictable IPs without going static

Want a server to always get the same IP without configuring it manually? Use a DHCP reservation: tell the router "when you see MAC address aa:bb:cc:dd:ee:ff, always hand out 192.168.1.100." You get DHCP's auto-config plus a static IP's predictability. This is the right pattern for any machine you SSH into frequently.

Code

Inspect your DHCP lease (macOS)·bash
# Show full lease info for Wi-Fi
ipconfig getpacket en0

# Just the assigned IP
ipconfig getifaddr en0

# Force a renew (kicks off DORA again)
sudo ipconfig set en0 BOOTP
sudo ipconfig set en0 DHCP
Linux equivalents·bash
# Show lease file
cat /var/lib/dhcp/dhclient.leases

# Force renew
sudo dhclient -r en0   # release
sudo dhclient en0      # request

External links

Exercise

Run ipconfig getpacket en0 (macOS) or cat /var/lib/dhcp/dhclient.leases (Linux) and find: your assigned IP, your subnet mask, the lease duration, the gateway, the DNS servers, and your DHCP server's IP. Bonus: log into your router's admin page and set a DHCP reservation for the machine you'll use most through this quest — predictable IPs make every later lesson easier.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.