The Big Picture: Who Gives Me an Address?
You walk into a café and connect your phone to Wi-Fi. A moment later the Internet works. You never typed an IP address, a mask, a gateway or a DNS server. How did your phone know all that?
It asked. A small program on the router, called a DHCP server, answered. Think of a hotel front desk: you arrive, say "I need a room", and the desk gives you a room number (IP address), tells you where the exit is (gateway) and where to get directions (DNS). The room is yours for a limited time.
5.1 Automatic IP Assignment
What it is: DHCP (Dynamic Host Configuration Protocol) hands out network settings automatically. Without it, you would have to type every setting on every device, and make sure no two devices share an address.
What DHCP gives your PC:
| Setting | Why you need it |
|---|---|
| IP address | Your address on this network (Section 2) |
| Subnet mask | Tells your PC which addresses are local (Section 2.3) |
| Default gateway | The router, the way out to other networks (Sections 2 and 8) |
| DNS servers | Who translates names to IPs (Section 4) |
| Lease time | How long you may keep the address (5.3) |
These extras (gateway, DNS and so on) are called DHCP options.
Who runs the DHCP server? In a home, the router does. In an office, it is often a Windows Server or a dedicated device. Your PC is the DHCP client.
Dynamic versus static.
| Kind | Meaning | Used for |
|---|---|---|
| Dynamic (DHCP) | The server picks an address from a pool and lends it | Laptops, phones, ordinary PCs |
| Static | You type a fixed address by hand | Servers, printers, the router itself |
| DHCP reservation | The server always gives the same address to one MAC address | A fixed address without touching the device |
The server keeps a pool (a range of addresses it may give out, such as 192.168.1.100 to 192.168.1.199) and a table of who has which address, tied to each device's MAC address.
If no DHCP server answers. Windows gives itself an address in 169.254.x.x (called APIPA, Automatic Private IP Addressing) after a short wait. This only works on the local network, with no gateway. If you see a 169.254 address in ipconfig, it means DHCP did not work: check the cable, the Wi-Fi, or the router.
A chicken-and-egg problem. When your PC starts, it has no IP address and does not know where the DHCP server is. So it sends its first message as a broadcast from the address 0.0.0.0 to 255.255.255.255 (everyone). DHCP uses UDP (Section 6) with two special ports: the server listens on port 67 and the client on port 68.
5.2 The DORA Process (Discover, Offer, Request, Acknowledge)
What it is: Getting an address takes four messages. The first letters spell DORA:
YOUR PC (DHCP client) DHCP SERVER (router)
1. DISCOVER "Is there a DHCP server out there? I need an address."
(broadcast: from 0.0.0.0 to 255.255.255.255) ─────────────────────────►
2. OFFER "Hello! You can have 192.168.1.25 for 24 hours.
Mask 255.255.255.0, gateway 192.168.1.1, DNS 192.168.1.1."
◄─────────────────────────────────────────────────────────────────────
3. REQUEST "Yes please, I would like 192.168.1.25."
(still broadcast, so any other servers know which offer you took) ──────►
4. ACK "Done. 192.168.1.25 is yours, starting now."
◄─────────────────────────────────────────────────────────────────────
Now the PC configures its NIC with the address and starts using the network.
| Step | Name | Sent by | Sent to | Meaning |
|---|---|---|---|---|
| 1 | Discover | Client | Everyone (broadcast) | "I need an address" |
| 2 | Offer | Server | Client | "Here is one you can have" |
| 3 | Request | Client | Everyone (broadcast) | "I accept this offer" |
| 4 | Acknowledge (ACK) | Server | Client | "Confirmed, it is yours for the lease time" |
Why is the Request a broadcast? A network can have more than one DHCP server. Each might send an offer. The Request tells all of them which offer you picked, so the others can take their offers back.
Before using the address, many PCs also do a quick check to see that nobody else already uses it (for example by sending an ARP question for that IP, Section 3). If someone does, the PC refuses the address and starts again.
After DORA the PC knows: its IP, its mask, its gateway and its DNS. Then it typically uses ARP to find the gateway's MAC address, and DNS to find the website's IP. The earlier sections now work together:
DHCP ──► I have an IP, a gateway and DNS
ARP ──► I know the gateway's MAC
DNS ──► I know the website's IP
TCP ──► I open a connection (Section 6)
Watch it on your own PC (read-only):
ipconfig /all
Look for these lines on the active adapter:
| Line | What it shows |
|---|---|
| DHCP Enabled | Yes means the address came from DHCP |
| DHCP Server | The address of the server that answered |
| Lease Obtained | When your lease started |
| Lease Expires | When it ends |
Get-NetIPConfiguration
Get-NetAdapter
5.3 Lease Renewal
What it is: A DHCP address is a loan, not a gift. It comes with a lease time (for example 24 hours, though many networks use a few hours or a day; a café may use less). When the lease ends, the address goes back into the pool for someone else.
Why lend instead of give? Phones come and go. If addresses were kept forever, a busy café would run out of addresses after a few hundred customers. A lease means unused addresses are recycled.
Renewal happens before the lease ends:
Lease starts (0%)
│
│ ... PC uses the address ...
│
├── 50% of lease (T1): PC asks the SAME server: "May I keep this address?"
│ server says yes (ACK) ──► lease starts again from zero
│
├── 87.5% of lease (T2): if the server did not answer, the PC asks ANY server
│
└── 100%: lease expired. PC must give up the address and start DORA again
(The 50% and 87.5% points are the usual defaults.) A renewal is much shorter than DORA: only Request and ACK.
What this means for you:
| Situation | What happens |
|---|---|
| You stay connected for days | The PC silently renews, over and over, and keeps the same IP |
| You turn the PC off for a while and come back | The server often still remembers you and gives the same address |
| You join a different network | A new DORA gives you a new address |
| The router is rebooted | Clients may get new addresses |
Commands to know. ipconfig /release gives the address back and ipconfig /renew asks again. They change your connection (you briefly lose network), so this course only reads the lease with ipconfig /all.
Common DHCP problems:
| Symptom | Likely cause |
|---|---|
169.254.x.x address | No DHCP server answered |
| "IP address conflict" warning | Two devices have the same address (for example a static address inside the DHCP pool) |
| Everything on the network loses connection at the same time | The DHCP server (router) restarted or failed |
| No Internet but address looks fine | Check the gateway and DNS lines, not just the IP |
Summary
| Topic | Remember this |
|---|---|
| DHCP | Gives IP, mask, gateway, DNS and lease time automatically |
| Ports | UDP 67 (server) and UDP 68 (client) |
| DORA | Discover, Offer, Request, Acknowledge; first two messages are broadcasts from 0.0.0.0 |
| APIPA | A 169.254.x.x address means no DHCP answer |
| Lease | A loan with an end time; renewal begins at about half of the lease |
| Reservation | Same IP for one MAC address without typing it on the device |
| Commands | ipconfig /all shows DHCP server and lease times |