Course contents

Unit 8: Core Network ServicesLesson 8.2 (2 of 4 in this unit)74 of 104 in the Network Fundamentals course

DHCP

Learn how a device gets its IP address, subnet mask, default gateway and DNS server automatically as soon as it joins a network. This lesson covers DHCP for IPv4.

Beginner · 12 min read · Before this: IP Addressing

Covers DORA process, UDP 67/68, Leases, T1 & T2, DHCP relay, Cisco DHCP config and DHCP snooping.

Technical definition

DHCP (Dynamic Host Configuration Protocol) is a client-server protocol that supplies IP addressing and other settings, such as a subnet mask, default gateway and DNS servers. A dynamically allocated address is valid for a lease period. For IPv4, DHCP uses UDP ports 67 (server) and 68 (client); initial allocation commonly uses Discover, Offer, Request and Acknowledge, while renewal uses Request and Acknowledge.

When you connect a laptop to a network, it needs an IP address and a few other settings before it can communicate properly. DHCP (Dynamic Host Configuration Protocol) supplies those settings automatically, so nobody has to configure every device by hand.

Why DHCP exists

A typical PC or phone that reaches other networks and uses names needs four settings: an IP address, a subnet mask, a default gateway and a DNS server. (A device that only talks to its own subnet needs no gateway, and one that only uses IP addresses needs no DNS server.) Typing these into every laptop, phone and printer by hand is slow, and people make mistakes: two devices end up with the same address, or a typo in the gateway cuts a PC off from the internet. Phones and laptops also move between networks all day, and each network needs different settings.

DHCP solves all of these problems. One server holds the correct settings for the network and hands them out on request. Addresses are only lent for a set time (the lease). When a visitor leaves, the address goes back into the pool for someone else once the lease runs out, or straight away if the device releases it on the way out. This happens every time you join a Wi-Fi network at home, at work or in a café.

What DHCP gives a device

Here is an example for a small office using the network 192.168.10.0/24:

Diagram
What DHCP gives a device
What DHCP gives a device
SettingExampleWhat it's for
IP address192.168.10.100The device's address on the network
Subnet mask255.255.255.0Tells the device which destinations are local
Default gateway192.168.10.1The router used to reach other networks
DNS server192.168.10.2Translates names into IP addresses
Lease time8 hoursHow long the assignment is valid
Read each row across: the left box names the item, the others describe it.

The server sends these values as DHCP options. Common ones are option 1 (subnet mask), option 3 (router, meaning the default gateway) and option 6 (DNS servers). In this example, 192.168.10.2 runs both DHCP and DNS, but they can just as easily be separate devices.

A DHCP lease works much like checking into a hotel. You don't bring your own room number. The front desk gives you one for the length of your stay (the lease) and tells you everything else you need, such as where the exit is (the gateway).

Who's involved

Diagram
Who's involved
Who's involved
ComponentJob
DHCP clientAsks for settings, for example a laptop or phone. Almost every device is a DHCP client by default.
DHCP serverHands out addresses and settings from a pool. At home this is the home router; in an office it is often a server or the router.
Scope / poolThe range of addresses the server may lend for one subnet, plus the settings that go with it
LeaseThe loan of one address to one client, for a set time
SwitchCarries the messages within the VLAN
DHCP relayForwards DHCP messages to a server on another subnet
Each item on the left, with what it means on the right.

On a home network, all of this is in one box: the home router is the default gateway, the DHCP server and usually a DNS forwarder too.

Watch it: getting an address (DORA)

Getting an address is a four-message exchange, remembered as DORA: Discover → Offer → Request → Acknowledge. In simple terms:

  1. Discover (client): "I'm new here and have no address. Is there a DHCP server?" Sent as a broadcast, because the client doesn't know who the server is.
  2. Offer (server): "You can have 192.168.10.100, with this mask, gateway and DNS server, for 8 hours."
  3. Request (client): "Yes, please. I'll take the offer from that server." This is still a broadcast, so any other server that made an offer knows it wasn't chosen.
  4. Acknowledge (server): "Done. The address is yours for 8 hours." The client then configures itself.

All four messages travel in UDP datagrams. Select any message to see its addresses and ports.

Step 1 of 4 · Discover
Client / Laptop
No IP address yet
LAN / VLAN 10
192.168.10.0/24
DHCP Server
IP 192.168.10.2
Client settings after the ACK
IP:
192.168.10.100
Mask:
255.255.255.0
Gateway:
192.168.10.1
DNS:
192.168.10.2
Lease:
8 hours

Arrows run from each message's sender to its receiver. Rows show message order, not separate cables or elapsed time to scale. Port numbers identify services or conversations, not physical switch sockets.

Reading the addresses

IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.

An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.

  • Client / Laptop: No IP address yet
  • DHCP Server: IP 192.168.10.2

* The Offer and ACK can be broadcast or unicast, depending on the client's state and broadcast flag.

DORA: Discover, Offer, Request, Acknowledge.

Ports and addresses

DHCP runs over UDP: the server listens on UDP 67, and the client listens on UDP 68.

MessageSource IPDestination IPUDP ports
Discover0.0.0.0255.255.255.25568 → 67
OfferServer IPBroadcast or offered address67 → 68
Request (first time)0.0.0.0255.255.255.25568 → 67
ACKServer IPBroadcast or assigned address67 → 68

0.0.0.0 means "I don't have an address yet". 255.255.255.255 is the limited broadcast address: it reaches every device in the local broadcast domain and is never forwarded by routers. Later, when the client renews its lease, it uses its own assigned address as the source.

Pools, exclusions and reservations

Diagram
Pools, exclusions and reservations
Pools, exclusions and reservations
TermMeaningOffice example
Pool (scope in Windows Server)Addresses and settings for one subnet.100 to .200
LeaseA time-limited assignment8 hours
ExclusionAn address the server must not hand out.150, set manually on a device
ReservationAn address kept for one particular clientThe printer always gets .120
Read each row across: the left box names the item, the others describe it.

A device with a reservation still uses DHCP, while a static address is typed into the device itself. Plan exclusions so that manually set addresses never overlap with the addresses DHCP hands out.

Keeping the address: renewal, rebinding and expiry

A client doesn't wait for its lease to run out. It tries to renew the lease well before then:

For this eight-hour example, the default T1 is four hours and T2 is seven hours. These are the starts of renewal and rebinding, not a limit of two requests. The server can supply other timer values, and the client retries if no answer arrives. A missed reply at T1 does not expire the address: the client can keep using it while the lease remains valid.

Stage 1 of 5

0 h · lease startsThe client has a 8-hour lease. Nothing to do yet.

This is the DHCP client's address-lease timeline in hours, not a network path. Default timers: T1 at 50% of the lease, T2 at 87.5%. Servers can be configured with other values.
Diagram
Keeping the address: renewal, rebinding and expiry
Keeping the address: renewal, rebinding and expiry
StageWhat the client doesHow
T1 · renewing (default 50%)Asks the original server to extend the leaseUnicast DHCPREQUEST
T2 · rebinding (default 87.5%)Asks any available server to extend itBroadcast DHCPREQUEST
Expiry (100%)Stops using the addressStarts DORA again
Read each row across: the left box names the item, the others describe it.

A successful renewal needs only a Request and an ACK, not all four DORA messages. A client that restarts can also ask for its previous address back.

The clock is a simplified IPv4 teaching model: its no-answer case shows selected stages, not every retransmission or a DHCPNAK rejection. For a real client, compare its lease-expiry time with a packet capture before diagnosing an expired address. See RFC 2131, section 4.4.5 for renewal, rebinding and expiry rules.

DHCP server on another subnet: relay

Organisations often run one central DHCP server for many VLANs. But routers don't forward the client's broadcast. Instead, the router interface facing the clients acts as a DHCP relay: it receives the broadcast and forwards it to the server as a normal unicast packet.

Step 1 of 8 · Discover
Two subnets · 192.168.10.0/24 ↔ 192.168.20.0/24
Client
VLAN 10
Router / relay
IP 192.168.10.1
DHCP server
IP 192.168.20.10

1. Discover · Broadcast on VLAN 10 · UDP 68 → 67

Is there a DHCP server out there?

Device key: Client (laptop)

Arrows run from each message's sender to its receiver. Rows show message order, not separate cables or elapsed time to scale. Port numbers identify services or conversations, not physical switch sockets.

Reading the addresses

IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.

An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.

  • Client: VLAN 10
  • Router / relay: IP 192.168.10.1
  • DHCP server: IP 192.168.20.10
DHCP relay: the router forwards DORA between VLAN 10 and a server on another subnet.

The relay writes its client-facing address into the giaddr (gateway IP address) field. That is how the server knows which pool to use: a giaddr of 192.168.10.1 means "use the 192.168.10.0/24 pool". The server replies to the relay, not straight to the client.

Checking DHCP on a Windows client

ipconfig /all
Diagram
Checking DHCP on a Windows client
Checking DHCP on a Windows client
FieldWhat to look for
DHCP EnabledYes
IPv4 AddressAn address in the expected subnet
Subnet MaskThe right mask
Default GatewayThe right router
DHCP ServerThe server you expect
DNS ServersThe DNS addresses you expect
Lease Obtained / ExpiresWhen the lease started and when it ends
Each item on the left, with what it means on the right.

To ask for a fresh lease:

ipconfig /release ipconfig /renew

/release gives the current address back to the server, and /renew starts a new request. Run ipconfig /all again afterwards: if the IPv4 address is still 169.254.x.x, no DHCP server answered.

When DHCP fails

Diagram
When DHCP fails
When DHCP fails
SymptomLikely causeCheck first
No lease at allServer down or pool exhaustedThe DHCP service, free addresses in the pool
Only one VLAN failsRelay or VLAN problemVLAN assignment, helper address
Address from the wrong subnetWrong VLAN or an unexpected serverThe switch port's VLAN, which server answered
Local works, remote doesn'tGateway or routingThe gateway option, routes
IP addresses work, names don'tDNSThe DNS option, whether the DNS server is reachable
Discover seen, no OfferPath or server problemRelay, routing, ACLs, server
Read each row across: the left box names the item, the others describe it.

These are clues, not proof. Follow the four messages and find where the exchange stops.

A Windows device that gets no answer gives itself a 169.254.x.x address (APIPA, Automatic Private IP Addressing). macOS does the same. Seeing 169.254 almost always means "DHCP didn't work". The address allows only limited local communication, with no gateway and no internet.

DHCP security: snooping

A rogue DHCP server (a home router plugged into the office network by mistake, or an attacker) can hand clients the wrong gateway or DNS server. DHCP snooping on the switch blocks DHCP server replies from ports that shouldn't send them:

PortSetting
Towards the real DHCP server (or relay)Trusted
To user devicesUntrusted

Trusted ports must follow the real path to the server. If you get this wrong, the switch blocks legitimate replies too.

Predict it: four broken DHCP setups

Predict · scenario 1

An IPv4 client has an eight-hour lease with default timers. Its first unicast request at T1 gets no answer. Has its address expired?

Predict · scenario 2

The server supplies valid T1 and T2 values different from 50% and 87.5%. Must the client ignore them and use those percentages?

Predict · scenario 3

The office DHCP server is switched off. A Windows laptop joins the network. What happens?

Predict · scenario 4

Every address in the pool .100 – .200 is leased. A new phone joins. What happens?

Predict · scenario 5

One central DHCP server serves VLAN 10 and VLAN 30. VLAN 10's router interface has ip helper-address configured, but VLAN 30's doesn't. What happens?

Predict · scenario 6

A client has the correct IP address, mask and gateway. It can ping 8.8.8.8, but websites won't load by name. What is the most likely cause?

Mistakes that break DHCP

  • Setting a static address inside the DHCP pool. The server doesn't know the address is taken and may lease it to another device, causing an address conflict. Exclude it from the pool or use a reservation.
  • Configuring ip helper-address on the wrong interface. The helper must be on the interface that receives the client broadcasts, not the one facing the server.
  • Treating a 169.254.x.x address as a DNS or internet problem. It means the device never got a DHCP lease, so start with DHCP: the server, the pool, the relay and the VLAN.

When a whole floor gets 169.254.x.x addresses at the same moment, look at what those clients share (the relay, the VLAN, the server) rather than at the PCs one by one.

Five DHCP facts worth keeping
  • A DHCP address doesn't guarantee internet access; the gateway and DNS still have to be right.
  • The DHCP server, default gateway and DNS server can all be different devices.
  • DHCPREQUEST is broadcast when first choosing an offer, but unicast when renewing at T1.
  • Routers don't forward the client's broadcast; a relay (ip helper-address) does.
  • A reservation is handed out by DHCP; a static address is set on the device.

Going further: DHCP on a Cisco router (CCNA)

This section is CCNA level: it shows how the ideas above are configured on a Cisco router. You don't need it to understand how DHCP works, so you can skip it on a first read.

Router as the DHCP server

Here the router is both the default gateway and the DHCP server, and a separate DNS server is at 192.168.10.2. Interface names vary by device.

configure terminal interface GigabitEthernet0/0 ip address 192.168.10.1 255.255.255.0 no shutdown exit ip dhcp excluded-address 192.168.10.1 192.168.10.99 ip dhcp excluded-address 192.168.10.201 192.168.10.254 ip dhcp pool OFFICE network 192.168.10.0 255.255.255.0 default-router 192.168.10.1 dns-server 192.168.10.2 lease 0 8 exit end
CommandWhat it does
ip dhcp excluded-addressKeeps a range out of the pool
ip dhcp pool OFFICECreates a pool named OFFICE
networkThe subnet the pool serves
default-routerThe gateway handed to clients (option 3)
dns-serverThe DNS server handed to clients (option 6)
lease 0 8Lease of 0 days, 8 hours

The two exclusions leave .100 to .200 for clients. Note that dns-server only advertises a DNS server to clients; it doesn't create one.

Check it with:

show ip dhcp binding

Lists the addresses the router has leased, and to which client.

Router as a relay

If the server is at 192.168.20.10 instead, configure the helper address on the interface that receives the client broadcasts:

configure terminal interface GigabitEthernet0/0 ip address 192.168.10.1 255.255.255.0 ip helper-address 192.168.20.10 no shutdown exit end

The remote server still needs a pool for 192.168.10.0/24, and routing must work between the relay and the server. By default, ip helper-address also forwards a few other UDP broadcasts, so it isn't strictly a DHCP-only command.

FAQ

What happens when a device's DHCP lease expires?
The client normally tries to extend its lease before expiry. By default, T1 starts unicast renewal halfway through the lease and T2 starts broadcast rebinding at 87.5%; the server can supply different timers, and clients retry within those phases. If no valid ACK extends the lease before expiry, the client must stop using the address and restart address acquisition. A DHCPNAK can also force it to abandon the lease earlier.
Can two different devices get the same IP from DHCP?
Not under normal operation. The server tracks every address it has leased and won't offer one that is in use, and the client checks that the address isn't taken before using it. Conflicts usually come from a device with a manually set address inside the DHCP pool, which is exactly what exclusions prevent.
What's the difference between a reservation and a static IP?
A reservation is set on the DHCP server. It ties an address to one client (by its MAC address or client ID), and the device still uses DHCP to get it. A static IP address is typed into the device itself and doesn't involve DHCP at all.
Does getting a DHCP address mean the internet will work?
No. DHCP only hands out settings. If the gateway or DNS server it gives out is wrong or unreachable, the device has an address but still can't reach other networks or resolve names. The ISP link or the router can also be down, even when DHCP works.