The DHCP Protocol and Dynamic Addressing
You connected to the dormitory Wi-Fi — and Instagram opened without your configuring anything. Who gave you the IP address, the mask, the gateway and the DNS server? DHCP did this in a few milliseconds. Today you will watch in a simulator the four-step “negotiation” called “Discover → Offer → Request → Acknowledge”, learn how the IP address “lease” is renewed, and find out why a computer sometimes gets a strange address such as 169.254.x.x.
Lesson goals and plan
By the end of the lesson you will…
- explain the task of DHCP, the client-server model and its use of UDP ports 67/68
- name the main settings of a DHCP server (address pool, exclusions, reservation, options, lease time)
- describe each message of the DORA process (source/destination IP and MAC, broadcast/unicast)
- calculate the lease time and the T1 (renewal) and T2 (rebinding) timers
- read the results of ipconfig /all, /release, /renew and identify DHCP problems (APIPA, NAK, pool exhaustion)
- explain why a DHCP relay agent is needed
- model DHCP logic (pool allocation, lease state) in Python
Plan (according to the syllabus)
- The role of the DHCP protocol in automatic IP address distribution and its client-server operating principle
- The Discover, Offer, Request and Acknowledge stages of DHCP and the process of managing an IP address lease
Think of DHCP as a rented apartment: the server is the landlord, the IP address is the apartment, the lease time is the contract. If you do not extend the contract in time, the apartment is given to someone else :ik-uy:
If every student typed in an IP address by hand, someone would certainly pick the neighbour’s address and both of them would lose their Internet. In a university network, however, one server (often the router itself) keeps all the addresses in a “ledger”: which address has been given to whom, and until when. The protocol that keeps this ledger is DHCP. It works so well that most people do not even know it exists.
Key terms
First try to recall the meaning of the term yourself, then click the card to check.
The role of the DHCP protocol in automatic IP address distribution and its client-server operating principle
For a computer to work in a network it needs at least four settings: an IP address, a network mask, a default gateway and a DNS server. They can be entered by hand on every device (static), but in a network with hundreds of laptops and phones this is impossible. DHCP automates this work.
DHCP (Dynamic Host Configuration Protocol) is an application-layer protocol working in the client-server model that automatically assigns IP addresses and network settings to devices connected to the network temporarily (on a lease basis). UDP is used as the transport: the server listens on port 67, the client on port 68. DHCP is an extension of the old BOOTP protocol.
:ik-kompyuter: DHCP client
Any device: a laptop, a phone, a Smart TV, an IP camera. If the “obtain an IP address automatically” mode is enabled in the operating system, it sends a DHCP request when it connects to the network.
:ik-server: DHCP server
At home — the Wi-Fi router itself; in an organization — Windows Server, Linux (isc-dhcp-server, Kea) or a Cisco router. The server manages the address pool, the table of leases and the options.
Static and dynamic addressing
| Criterion | Static (manual) | Dynamic (DHCP) |
|---|---|---|
| Configuration | Separately on every device | Once — on the server |
| Probability of error | High (IP conflict, mask error) | Low |
| Address stability | Permanent | May change (with a reservation — permanent) |
| Where it is used | Servers, routers, network printers | User devices, guest Wi-Fi |
| Use of addresses | An occupied address stays allocated even if idle | After the lease ends the address is given to someone else |
The DHCP server’s “ledger”: what is configured?
Pool (scope)
For example 192.168.1.100 – 192.168.1.199 (/24). When the pool runs out, new devices cannot get an address.
Exclusions
Addresses that are in the pool but are not handed out — for static devices (for example .1 is the router).
Reservation
MAC 00-1B-A9-4C-21-77 → always 192.168.1.40. The printer’s address does not change, but it is still obtained through DHCP.
Options
The mask (1), the gateway (3), DNS (6), the domain name (15), the lease time (51) and others.
Lease time
On home routers often 1 day, on guest Wi-Fi — a few hours, on Windows Server 8 days by default.
Relay
If the server is in another VLAN/network, a router delivers the broadcast request to it.
A DHCP server on a Cisco router (example)
For the department computer room the following configuration distributes addresses to the 192.168.10.0/24 network; the first 10 addresses are left for static devices:
Cisco IOS — DHCP serverRouter(config)# ip dhcp excluded-address 192.168.10.1 192.168.10.10 Router(config)# ip dhcp pool KAFEDRA Router(dhcp-config)# network 192.168.10.0 255.255.255.0 Router(dhcp-config)# default-router 192.168.10.1 Router(dhcp-config)# dns-server 8.8.8.8 1.1.1.1 Router(dhcp-config)# lease 1 ! 1 day Router# show ip dhcp binding ! leases granted
Relay agent: when the server is in another network
The client does not know the DHCP server’s address, so it sends its first message as a broadcast (255.255.255.255). A router does not pass a broadcast to another network. The solution is a relay agent: on the router interface in the client’s network ip helper-address 10.0.0.5 is written. The router catches the broadcast message, adds its own interface address to it (the giaddr field) and sends it to the server as unicast. By looking at giaddr the server knows from which pool to give an address. Thanks to this, one central DHCP server is enough for the whole university.
If someone plugs their own “home router” into the network, it too starts handing out wrong addresses as a DHCP server (rogue DHCP). An attacker can also pretend to be the gateway. Switches have a DHCP Snooping feature against this: DHCP replies are allowed only through “trusted” ports.
The Discover, Offer, Request and Acknowledge stages of DHCP and the process of managing an IP address lease
DHCP is just like looking for a rented apartment: you place an ad (“I need an apartment”), the landlords make offers, you choose one, and its owner confirms “agreed”. These four steps are called DORA for short.
| Step | From → to | Source IP → destination IP | Content |
|---|---|---|---|
| Discover | Client → everyone | 0.0.0.0:68 → 255.255.255.255:67 | “I need an IP!” It contains the client’s MAC address (chaddr) and the transaction number (xid) |
| Offer | Server → client | 192.168.1.1:67 → the offered IP or broadcast | “I offer you 192.168.1.105” + the mask, gateway, DNS, lease time |
| Request | Client → everyone | 0.0.0.0:68 → 255.255.255.255:67 | “I accept this server’s offer” (the Server Identifier option). Broadcast — so that the other servers also know their offers were rejected |
| Acknowledge | Server → client | 192.168.1.1:67 → 192.168.1.105 or broadcast | “I confirm.” The lease has begun. If refused — DHCPNAK |
Whether the Offer and ACK are sent as broadcast or unicast depends on the “broadcast” flag in the client’s request: some clients cannot accept a unicast packet until they have received an IP address. That is why in Wireshark you can see both cases. After the ACK arrives, many clients check the address with a gratuitous ARP (Lecture 13): if a reply comes — the address is taken, and the client sends DHCPDECLINE.
Simulator: DORA and the lease life cycle
A student’s laptop is connecting to the dormitory Wi-Fi. First go through DORA step by step, then move the time forward and watch how the lease states change. The “Server went down” button shows what happens at T1 and T2.
:ik-wifi: DHCP simulator — the dormitory Wi-Fi (24-hour lease)
Managing the lease: T1, T2 and other messages
- BOUND — the lease is in force
The count starts from the moment the ACK arrives. If the lease time is L, the client sends nothing until T1.
- T1 = 0.5 · L — RENEWING
The client sends a unicast DHCPREQUEST to the server that gave the address. If an ACK arrives, the lease is counted anew. Often this is a single packet that the user does not notice.
- T2 = 0.875 · L — REBINDING
If its own server does not answer, the client sends the DHCPREQUEST as a broadcast — any DHCP server (for example a backup server) may confirm the lease.
- L — the lease expired
If nobody answers, the client gives up the address and starts DORA from the beginning.
| Message | Who sends it | When |
|---|---|---|
DHCPNAK | Server | The address the client asked for cannot be given (for example, the laptop has moved to another network and is asking for the old address) |
DHCPDECLINE | Client | The address that was given turned out to be taken in the ARP check |
DHCPRELEASE | Client | The client voluntarily gives up the address (ipconfig /release) |
DHCPINFORM | Client | The IP is static, but other settings (for example DNS) are needed |
Watching DHCP with ipconfig
C:\Users\Talaba> ipconfig /all Wireless LAN adapter Wi-Fi: Physical Address. . . . . . . . . : 3C-52-82-1A-7F-09 DHCP Enabled. . . . . . . . . . . : Yes IPv4 Address. . . . . . . . . . . : 192.168.1.105(Preferred) Subnet Mask . . . . . . . . . . . : 255.255.255.0 Lease Obtained. . . . . . . . . . : Saturday, November 28, 2026 9:02:14 AM Lease Expires . . . . . . . . . . : Sunday, November 29, 2026 9:02:14 AM Default Gateway . . . . . . . . . : 192.168.1.1 DHCP Server . . . . . . . . . . . : 192.168.1.1 DNS Servers . . . . . . . . . . . : 192.168.1.1
C:\Users\Talaba> ipconfig /renew An error occurred while renewing interface Ethernet : unable to contact your DHCP server. Request has timed out. C:\Users\Talaba> ipconfig Autoconfiguration IPv4 Address. . : 169.254.37.12(Preferred) Subnet Mask . . . . . . . . . . . : 255.255.0.0 Default Gateway . . . . . . . . . :
| Command / sign | What it does / what it means |
|---|---|
ipconfig /release | Sends a DHCPRELEASE; the IP address becomes 0.0.0.0 |
ipconfig /renew | Asks for a new address (first it tries to request the old address) |
Lease Obtained / Expires | The time the lease began and will end — the difference is the lease time |
Autoconfiguration … 169.254.x.x | APIPA — the DHCP server did not answer; a cable, Wi-Fi or server problem |
Linux: dhclient -v eth0 / ip addr | Equivalent commands in Linux |
Modeling DHCP logic in Python
Inside a DHCP server simple algorithms actually run: finding a free address in the pool, calculating the lease time, determining the state. Try writing them yourself. Use input() without a prompt and click the :ik-tekshir: Check button.
Mini-boss: the DHCP server log
The start and end of the pool are input, then the number of events n and n events: DISCOVER MAC or RELEASE MAC. For DISCOVER: if this MAC already has an address — give that address, otherwise give the smallest free address and print “MAC → IP”; if there is no free address — “MAC → NAK”. For RELEASE: the address is freed and “MAC bo‘shatdi IP” is printed (if it has no address nothing is printed). +50 XP
Common mistakes
| Situation / mistake | Cause | The right way |
|---|---|---|
| The printer’s address changes every week, and nobody can print | The printer gets an ordinary dynamic address | Make a reservation or give a static address outside the pool |
| An IP conflict with a server that has a static address | The static address is inside the DHCP pool and not excluded | excluded-address or shrink the pool |
| Computers in another VLAN get 169.254.x.x | The relay agent is not configured | ip helper-address on the router interface |
| New devices cannot connect at a conference | The pool is small, the lease is long (old leases are still occupying addresses) | Enlarge the pool, shorten the lease on the guest network |
| “DHCP is the same thing as DNS” | Both work automatically, so they get confused | DHCP gives out addresses, DNS turns a name into an address (Lecture 15) |
| Plugging a home router into the network | Rogue DHCP — a wrong gateway gets distributed | DHCP Snooping; connect the home router in “access point” mode |
Reinforcement
// REMEMBER IN 1 MINUTE
- DHCP — automatic IP + mask + gateway + DNS; client-server, UDP 67 (server) / 68 (client).
- DORA: Discover (broadcast) → Offer → Request (broadcast) → ACK.
- The lease: T1 = 50% → unicast renewal; T2 = 87.5% → broadcast; L → INIT.
- Pool, exclusions, reservation, options (3 — gateway, 6 — DNS, 51 — lease).
- 169.254.x.x (APIPA) — no server was found; for another network — a relay agent.
Final test
Review questions
What is the task of DHCP and which settings does it give?
It automatically gives devices an IP address, mask, default gateway, DNS server and other options, on a lease basis.
In which model and on which ports does DHCP work?
In the client-server model, over UDP: server 67, client 68.
Compare static and dynamic addressing.
Static — manual, permanent, for servers and routers; dynamic — automatic, temporary, for user devices, with few errors.
Explain each message of DORA.
Discover — the client looks for a server; Offer — the server offers an address; Request — the client asks for the chosen offer; ACK — the server confirms and the lease begins.
Why are Discover and Request sent as broadcast?
Discover — the client does not know the server’s address; Request — so that all the servers know which offer was accepted.
What are the T1 and T2 timers?
T1 (50%) — a unicast renewal request to its own server; T2 (87.5%) — a broadcast request to any server. If the lease expires, the client gives up the address.
When are DHCPNAK and DHCPDECLINE sent?
NAK — when the server cannot give the address the client asked for; DECLINE — when the client finds through ARP that the address it was given is taken.
Why is a relay agent needed?
A router does not pass a broadcast; the relay forwards the client’s request as unicast to a server in another network and points to the right pool via giaddr.
When does an APIPA address appear and what should be done?
When the DHCP server does not answer (169.254.0.0/16). Check the cable/Wi-Fi connection, that the server is working and the relay configuration, and run ipconfig /renew.
What is a rogue DHCP and how is it protected against?
An unauthorized DHCP server hands out wrong settings. Protection — DHCP Snooping on switches.
Independent work
The independent study topic in the course syllabus: “The Role of DHCP, ICMP, NAT and IPv6 Technologies in the Network.” (6 hours; in this lesson — the DHCP part).
- From the result of
ipconfig /allcalculate the lease time and write down the T1 and T2 times as exact clock times. - Run
ipconfig /releaseandipconfig /renew, capture the DORA messages in Wireshark (filter:dhcp); write the source/destination IP and MAC addresses of every message in a table. - Design a DHCP scheme for your variant: justify the pool, exclusions, reservations, options and lease time.
| Criterion | Points |
|---|---|
| The plan or program is complete and correct (pool, options, lease calculated) | 2 |
| The DORA and lease process is explained correctly | 1 |
| Screenshots / Wireshark records or code are attached | 1 |
| The conclusion is well founded, the formatting is tidy | 1 |
Summary
Your lesson results
Your results are saved in this browser. Read all the sections and complete the exercises and assignments.