Skip to content
We areTOP 1%

How does DHCP assign an IP address to a device? Explain DORA.

MediumConceptARP, DHCP & NAT
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews

Answer

DHCP (Dynamic Host Configuration Protocol) automatically gives a device an IP address and other settings when it joins a network, so nobody has to configure each device by hand. It runs over UDP (server port 67, client port 68) and uses four messages, remembered as DORA: Discover, Offer, Request, Acknowledge.

  • The client has no IP address yet, so it broadcasts, using source 0.0.0.0 and destination 255.255.255.255.
  • Besides the address, the server supplies the subnet mask, default gateway, DNS servers and a lease time; the client tries to renew the lease when half of it has passed.
  • The Request is broadcast so that every server that made an offer learns which one was accepted. If the server is on another subnet, a router acting as a DHCP relay agent forwards the messages.

Example: A laptop joins the office Wi-Fi:

Laptop -> broadcast : DISCOVER  "I need an address"
Server -> laptop    : OFFER     "you can use 192.168.1.50, lease 24 h"
Laptop -> broadcast : REQUEST   "I accept 192.168.1.50 from this server"
Server -> laptop    : ACK       "confirmed; mask 255.255.255.0, gateway 192.168.1.1"

If no server answers, the laptop gives itself a 169.254.x.x address and cannot reach the internet.

More in ARP, DHCP & NAT

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account