IP Addresses & Routing

DHCP Explained: The Four-Message Exchange

Follow how a device gets its IP address automatically, what comes with the lease and how to fix things when the exchange fails.

Key takeaways

  • The four messages are Discover, Offer, Request and Acknowledge, often remembered as DORA.
  • The server lends an address for a limited time, called a lease, which the device renews before it runs out.
  • Along with the address come the subnet mask, default gateway and DNS servers.
  • A 169.254.x.x address on a computer usually means no DHCP server answered.
  • Two DHCP servers on one network cause confusing, intermittent faults.

DHCP, the Dynamic Host Configuration Protocol, gives a device its network settings automatically when it joins. In the usual case four messages pass: the device asks who can configure it, a server offers an address, the device requests that offer and the server confirms it. The whole thing often takes well under a second.

It is why you can join a network and start browsing without typing a single number. When it fails, you get messages about "obtaining IP address" and a connection that goes nowhere.

Why it exists

Every device needs an IP address that nobody else on the network is using, plus a few related settings. Typing these by hand into each phone and laptop would be slow and error-prone. DHCP, defined for IPv4 in RFC 2131, keeps one record of what is handed out and manages it for you.

At home, the DHCP server is normally built into your router. In larger organizations it runs on a server or on core network equipment.

The four messages

A new device has no address yet and doesn't know where the server is. So it starts by shouting to the whole local network. It sends from 0.0.0.0 to the broadcast address 255.255.255.255. DHCP uses UDP, with the server listening on port 67 and the client on port 68.

Discover, Offer, Request, Acknowledge
New device DHCP server Discover 1 Broadcast: is there a DHCP server here? Offer 2 Here is an address and settings you could use Request 3 I accept the offer from this particular server Acknowledge 4 Confirmed: the lease starts now New device DHCP server Discover 1 Broadcast: is there a DHCP server here? Offer 2 Here is an address and settings you could use Request 3 I accept the offer from this particular server Acknowledge 4 Confirmed: the lease starts now

Discover. The client identifies itself, mainly by its hardware address, and may say which options it wants or which address it held before.

Offer. A server picks a free address from its pool or scope and proposes it, with a lease time. It may first check that nothing is already using that address.

Request. The client answers, usually still by broadcast. The message names the chosen server. If several made offers, the others learn they were not selected and release what they set aside.

Acknowledge. The server records the lease and confirms the settings. Before using the address, the client may check with ARP that nobody else answers for it. If someone does, it sends a Decline and starts over.

What arrives with the address

Extra settings travel as numbered options, listed in RFC 2132 and later documents.

Option Setting
1 Subnet mask
3 Router (default gateway)
6 DNS servers
15 Domain name
51 Lease time
54 Server identifier

Other options point phones at their configuration server, tell machines how to boot over the network, or supply time servers. A wrong option affects every device that renews, which makes DHCP a quick place to change settings and an equally quick place to break them. A bad DNS entry here is a classic cause of "everything is connected but nothing loads".

Leases and renewal

An address is borrowed. The lease time says how long. A client doesn't wait until the last moment.

The life of a lease, with default renewal points
Lease starts The server acknowledges and the device configures itself. About 50% elapsed The client asks its original server directly to extend the lease. About 87.5% elapsed If still unanswered, it broadcasts so any server can respond. Lease expires The client must stop using the address and begin again. Lease starts The server acknowledges and the device configures itself. About 50% elapsed The client asks its original server directly to extend the lease. About 87.5% elapsed If still unanswered, it broadcasts so any server can respond. Lease expires The client must stop using the address and begin again.

A successful renewal needs only the Request and Acknowledge steps. A server can refuse with a NAK, for example when the device has moved to a network where that address is wrong, and the client starts a fresh Discover.

A polite client can send Release when it is done, though many simply disappear and let the lease lapse.

Short leases suit guest networks and busy venues, where visitors come and go and the pool could run out. Longer leases suit stable homes and offices and ride out a brief server outage. There is no single right value.

Reservations versus static addresses

If a printer or storage box should always have the same address, you have two choices. A reservation tells the server to give a particular hardware address the same IP every time. A static address is typed into the device itself.

Reservations are usually easier: all the assignments live in one place, and the device still picks up changed DNS or gateway settings. If you set static addresses, choose them outside the DHCP pool, or you risk two devices claiming one address.

Across more than one subnet

Broadcasts don't cross routers. In a network with many subnets, a relay agent on each one, normally the router, forwards requests to a central server and records which subnet they came from, so the server can choose from the matching pool. If one VLAN gets no addresses while others work, check its relay setting first, then whether the server has a scope for that subnet and free addresses in it.

A worked example: sizing a small network

Say a cafe uses the range 192.168.10.0/24 for customers. That block has 254 usable addresses. The router takes 192.168.10.1, and the owner wants a few fixed devices, so the pool runs from .50 to .250, giving 201 addresses.

Customers stay about an hour, but suppose the lease is set to a full day. Each phone that wanders past and joins keeps its address reserved until tomorrow. On a busy day more than 201 different devices could appear, and by afternoon newcomers get nothing, even though only a few dozen people are in the room.

Cutting the lease to a couple of hours returns addresses soon after people leave. A larger subnet, such as a /23, would also give more room. Either change solves it, and the first is usually simpler. In a home with a dozen devices the same pool would never fill, and a one-day lease or longer is perfectly sensible. Subnetting explains how those block sizes work, and the CIDR calculator checks the numbers.

Planning the address plan around it

A little structure saves trouble later. A common pattern splits a subnet into three parts: a few low addresses for the router and network equipment, a block for reserved or static devices such as printers and servers, and the dynamic pool for everything else. Write it down.

Check the other settings the server hands out, too:

  • DNS servers. Give at least two that really work. Clients don't necessarily treat the second as a strict backup, so both should return the same kind of answers, especially if one is a filter or knows internal names.
  • Gateway. It must be an address inside the same subnet.
  • Domain suffix. Set it only if you use local names, and avoid inventing a suffix that belongs to someone else on the public internet. The name home.arpa is set aside for home networks.

After changing any option, remember that devices keep their old settings until they renew. Reconnect a test machine and read its configuration before assuming the change took effect everywhere.

Reading the evidence

When a fault is stubborn, look at both ends. The router or server log usually records each message with the client's hardware address. What you see narrows the search quickly.

In the log Likely meaning
Nothing at all The request never arrives: link, VLAN or relay problem
Discover, then nothing The server has no free address or no matching scope
Repeated Discover and Offer Offers are not reaching the client
Request answered with NAK The client asked for an address that doesn't fit here
Decline The client found the offered address already in use

A packet capture on your own network shows the same messages in detail, including every option the server sent. The display filter dhcp in current Wireshark versions isolates them; older ones used bootp, after the earlier protocol DHCP grew out of.

When it fails

If a Windows or macOS computer shows an address beginning 169.254, it gave itself a link-local address after hearing nothing. It can talk to similar neighbors but not reach the internet.

To ask again on Windows:

ipconfig /release
ipconfig /renew
ipconfig /all

On macOS, for an interface named en0 (yours may differ):

sudo ipconfig set en0 DHCP
ipconfig getpacket en0

On Linux, the method depends on the network manager. With NetworkManager, bringing the connection down and up with nmcli connection down NAME and nmcli connection up NAME requests a new configuration.

Then work through the likely causes:

  1. Link problem. On Wi-Fi, a wrong password or weak signal can look like an address failure.
  2. Server off or hung. Restart the router and see whether all devices are affected.
  3. Pool exhausted. Compare the number of leases with the pool size. Shorten the lease or enlarge the range.
  4. Allow list or filtering. A router that blocks unknown devices may trip on a randomized MAC address.
  5. Security software on the device blocking UDP 67 and 68.

More walk-throughs are in fixing "obtaining IP address" errors.

Rogue servers

Clients generally accept an offer without proof of who sent it. A second server, often a spare router plugged in by its LAN port, will hand out wrong gateways to some devices. The symptom is that certain machines work and others don't, changing after reconnection. The server identifier shown by ipconfig /all tells you who answered.

The same weakness could be abused deliberately, so managed switches offer DHCP snooping, which permits server replies only on trusted ports. At home, simply make sure one device is serving addresses, and put extra routers into access point mode.

What about IPv6?

IPv6 works differently. Routers announce the network prefix in advertisements, and devices can form their own addresses, called SLAAC. DHCPv6 exists as well, with its own messages, and is used for some settings or managed networks. It does not hand out the default gateway; that comes from router advertisements. See SLAAC and DHCPv6 for how the pieces fit.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in IP Addresses & Routing →

Latest news on this topic