Routelearn.net
Course menu

Unit 8: Core Network ServicesLesson 8.2 (2 of 4 in this unit)55 of 84 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

DHCP (Dynamic Host Configuration Protocol) is a client-server protocol that automatically gives a device an IP address, subnet mask, default gateway, DNS server addresses and other settings for a limited time, called a lease. For IPv4, it uses UDP ports 67 (server) and 68 (client) and a four-message exchange: Discover, Offer, Request and Acknowledge.

In simple terms: When a device joins a network, DHCP hands it the settings it needs to communicate, so nobody has to type them in by hand.

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

To use an IP network fully, every device needs four settings: an IP address, a subnet mask, a default gateway and a 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, so when a visitor leaves, their address goes back into the pool for someone else. 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:

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

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.

💡 In simple terms: DHCP is 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

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

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
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

* 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

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

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:

Stage 1 of 5

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

Default timers: T1 at 50% of the lease, T2 at 87.5%. Servers can be configured with other values.
StageWhat the client doesHow
T1 · renewing (50%)Asks the original server to extend the leaseUnicast DHCPREQUEST
T2 · rebinding (87.5%)Asks any available server to extend itBroadcast DHCPREQUEST
Expiry (100%)Stops using the addressStarts DORA again

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.

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
192.168.10.1
DHCP server
192.168.20.10

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

Is there a DHCP server out there?

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
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

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

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

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.

Practice: predict what happens

Predict · scenario 1

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

Predict · scenario 2

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

Predict · scenario 3

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 4

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?

Common mistakes

  • 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.
✅ Key takeaways
  • 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?
It usually doesn't get that far. The client tries to renew at T1 (half the lease time) and again at T2 (87.5%). The lease only expires if both attempts fail. The client then stops using the address and starts DORA again. It may get a different address, although servers often hand back the same one if it is still free.
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.