Computer Networks / Lecture / Lecture 14
Lecture · Computer Networks

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.

:ik-kitob: Lecture 14 ⏱ 2 academic hours (80 minutes) 🚇 Packet simulators ⚡ An IP address on lease
14

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)

  1. The role of the DHCP protocol in automatic IP address distribution and its client-server operating principle
  2. 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:

Why, even when 200 students connect to the Wi-Fi at the same time, does nobody’s IP address clash?

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.

Definition

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

Table 14.1. Comparing manual and automatic assignment
CriterionStatic (manual)Dynamic (DHCP)
ConfigurationSeparately on every deviceOnce — on the server
Probability of errorHigh (IP conflict, mask error)Low
Address stabilityPermanentMay change (with a reservation — permanent)
Where it is usedServers, routers, network printersUser devices, guest Wi-Fi
Use of addressesAn occupied address stays allocated even if idleAfter the lease ends the address is given to someone else

The DHCP server’s “ledger”: what is configured?

:ik-royxat:

Pool (scope)

For example 192.168.1.100 – 192.168.1.199 (/24). When the pool runs out, new devices cannot get an address.

:ik-taqiq:

Exclusions

Addresses that are in the pool but are not handed out — for static devices (for example .1 is the router).

:ik-kalit:

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.

:ik-sozlama:

Options

The mask (1), the gateway (3), DNS (6), the domain name (15), the lease time (51) and others.

:ik-vaqt:

Lease time

On home routers often 1 day, on guest Wi-Fi — a few hours, on Windows Server 8 days by default.

:ik-tarmoq:

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.

Client0.0.0.0 Routerhelper-addressgiaddr=192.168.20.1 DHCP server10.0.0.5 broadcast unicast 192.168.20.0/24 10.0.0.0/24
Figure 14.1. The relay agent forwards the client’s broadcast as unicast to a server in another network
Security

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.

Table 14.2. DORA messages (without a relay, in one network)
StepFrom → toSource IP → destination IPContent
DiscoverClient → everyone0.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)
OfferServer → client192.168.1.1:67 → the offered IP or broadcast“I offer you 192.168.1.105” + the mask, gateway, DNS, lease time
RequestClient → everyone0.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
AcknowledgeServer → client192.168.1.1:67 → 192.168.1.105 or broadcast“I confirm.” The lease has begun. If refused — DHCPNAK
Did you know?

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)

DiscoverOfferRequestACK
:ik-noutbuk: LaptopMAC 3C-52-82-1A-7F-09IP: 0.0.0.0
:ik-server: DHCP (router)192.168.1.1pool .100–.199
Click the “Next message” button — the laptop has connected to Wi-Fi, but it has no IP address yet.
Lease time: 0 hours · state: INIT
0 — ACKT1 = 12 hoursT2 = 21 hours24 — expired

Managing the lease: T1, T2 and other messages

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

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

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

  4. L — the lease expired

    If nobody answers, the client gives up the address and starts DORA from the beginning.

Table 14.3. Additional DHCP messages
MessageWho sends itWhen
DHCPNAKServerThe address the client asked for cannot be given (for example, the laptop has moved to another network and is asking for the old address)
DHCPDECLINEClientThe address that was given turned out to be taken in the ARP check
DHCPRELEASEClientThe client voluntarily gives up the address (ipconfig /release)
DHCPINFORMClientThe IP is static, but other settings (for example DNS) are needed

Watching DHCP with ipconfig

cmd — ipconfig /all (abridged)
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
cmd — when no DHCP server is found
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 . . . . . . . . . :
Table 14.4. DHCP commands and “signs”
Command / signWhat it does / what it means
ipconfig /releaseSends a DHCPRELEASE; the IP address becomes 0.0.0.0
ipconfig /renewAsks for a new address (first it tries to request the old address)
Lease Obtained / ExpiresThe time the lease began and will end — the difference is the lease time
Autoconfiguration … 169.254.x.xAPIPA — the DHCP server did not answer; a cable, Wi-Fi or server problem
Linux: dhclient -v eth0 / ip addrEquivalent 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 / mistakeCauseThe right way
The printer’s address changes every week, and nobody can printThe printer gets an ordinary dynamic addressMake a reservation or give a static address outside the pool
An IP conflict with a server that has a static addressThe static address is inside the DHCP pool and not excludedexcluded-address or shrink the pool
Computers in another VLAN get 169.254.x.xThe relay agent is not configuredip helper-address on the router interface
New devices cannot connect at a conferenceThe 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 confusedDHCP gives out addresses, DNS turns a name into an address (Lecture 15)
Plugging a home router into the networkRogue DHCP — a wrong gateway gets distributedDHCP Snooping; connect the home router in “access point” mode

Reinforcement

// REMEMBER IN 1 MINUTE

  1. DHCP — automatic IP + mask + gateway + DNS; client-server, UDP 67 (server) / 68 (client).
  2. DORA: Discover (broadcast) → Offer → Request (broadcast) → ACK.
  3. The lease: T1 = 50% → unicast renewal; T2 = 87.5% → broadcast; L → INIT.
  4. Pool, exclusions, reservation, options (3 — gateway, 6 — DNS, 51 — lease).
  5. 169.254.x.x (APIPA) — no server was found; for another network — a relay agent.
:ik-uy:Wi-Fi at homeThere is a small DHCP server inside the router: phones, TVs and laptops get addresses automatically.
:ik-bino:The universityA central DHCP server and a relay agent on every building’s router — one “ledger” for thousands of devices.
:ik-avtobus:Airport / bus station Wi-FiThe lease is short (a few hours): passengers change quickly, and addresses must be freed quickly.

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

  1. From the result of ipconfig /all calculate the lease time and write down the T1 and T2 times as exact clock times.
  2. Run ipconfig /release and ipconfig /renew, capture the DORA messages in Wireshark (filter: dhcp); write the source/destination IP and MAC addresses of every message in a table.
  3. Design a DHCP scheme for your variant: justify the pool, exclusions, reservations, options and lease time.
Assessment criteria (individual assignment)
CriterionPoints
The plan or program is complete and correct (pool, options, lease calculated)2
The DORA and lease process is explained correctly1
Screenshots / Wireshark records or code are attached1
The conclusion is well founded, the formatting is tidy1

Summary

DHCPAutomatic IP, mask, gateway, DNS — client-server, UDP 67/68.
Dynamic addressingThe address is temporary, on a lease basis; few conflicts, centralized management.
Server settingsPool, exclusions, reservation, options, lease time.
DORADiscover (bc) → Offer → Request (bc) → ACK; rejection — NAK.
The leaseT1 = 50% (unicast), T2 = 87.5% (broadcast), L — the address is returned.
Relayip helper-address — one server serves many networks.
Diagnosticsipconfig /all, /release, /renew; 169.254.x.x — no server.
SecurityAgainst a rogue DHCP — DHCP Snooping.

Your lesson results

Your results are saved in this browser. Read all the sections and complete the exercises and assignments.

My personal notes