Beginner 10 min read

๐Ÿ“ก What Is DHCP? How Your Device Gets an IP Address Automatically

๐Ÿ“˜ What You Will Learn

  • What DHCP is and why we need it
  • What settings DHCP gives your device
  • The 4 steps of a DHCP conversation (DORA)
  • What a lease is, and when it is renewed
  • Dynamic IP vs static IP vs DHCP reservation
  • How to see your DHCP settings on Windows and Linux
  • How to fix the most common DHCP problems

๐Ÿง  What Is DHCP?

DHCP stands for Dynamic Host Configuration Protocol. It gives a device its network settings automatically, so nobody has to type them in.

When your phone joins your home Wi-Fi, it gets a private IP address like 192.168.1.10 without you doing anything. That is DHCP.

DHCP gives your device:

๐Ÿ‘‰ In a home network, the DHCP server is usually your router. The device asking for settings is the DHCP client.

DHCP uses UDP. The server listens on port 67. The client listens on port 68.

Simple meaning:

New device  --->  "I need network settings!"  --->  Router (DHCP server)
New device  <---  IP, gateway, DNS, lease time <---  Router (DHCP server)

๐Ÿ“ฆ Easy Analogy

Think of checking in to a hotel.

Hotel front desk          =  DHCP server (your router)
Guest with no room        =  New device
Room number               =  IP address
Key card valid for 12 h   =  Lease time
Directions and phone list =  Gateway and DNS servers
Checking out              =  Releasing the address

You walk in and ask for a room. The desk offers one. You say you will take it. The desk confirms and gives you a key card, valid for a set time. If you stay longer, you ask the desk to extend it. When you leave, the room goes back to the pool for the next guest.

๐Ÿค” Why Do We Need DHCP?

  • No typing: every phone, laptop and TV gets its settings by itself
  • No mix-ups: the server keeps track of which address it gave to which device, so two devices do not get the same one
  • Moving around: your phone gets new settings at home, in college and in a cafรฉ
  • Easy to manage: all settings are in one place, the router

Without DHCP, you would type an IP address, a mask, a gateway and DNS servers by hand on every device. One typo, and the device may have no internet.

๐Ÿ”„ How DHCP Works: DORA

A new device has no IP address yet, so it cannot talk to one server directly. Instead, it shouts to everyone on the local network. This is called a broadcast: a message sent to all devices on the local network.

The conversation has 4 steps. Their first letters spell DORA.

Device (client)                                           DHCP server (router)
|                                                       |
|-- 1. DISCOVER: "Is any DHCP server here?" ----------->|   (broadcast)
|<-- 2. OFFER: "You can use 192.168.1.10" --------------|
|-- 3. REQUEST: "I will take 192.168.1.10" ------------>|   (broadcast)
|<-- 4. ACK: "It is yours for 12 hours" ----------------|
Step Message Meaning
1 Discover The device asks: "Is there a DHCP server?"
2 Offer The server offers an address and settings
3 Request The device says: "I choose this offer"
4 Acknowledge The server confirms. The address is now yours

If more than one DHCP server answers, the device picks one offer. The other servers see that their offer was not chosen.

โณ Leases and Renewal

An address from DHCP is not yours forever. It is leased, which means lent for a set time.

Two timers decide what happens before the lease ends:

Timer When What the device does
T1 (renewal) Half the lease time Asks the same server to extend the lease
T2 (rebinding) 87.5% of the lease time If the server did not answer, asks any DHCP server

Example for a 12-hour lease:

0 h  ------------ 6 h ------------ 10.5 h ------ 12 h
lease starts      T1: ask to       T2: ask any     lease ends
                  renew            server

Usually the server says yes, and the lease starts over. That is why your home devices usually keep the same address.

When a device leaves the network on purpose, it can send a release message. The server then marks the address as free.

๐Ÿงฑ Dynamic vs Static vs Reservation

Method How it works Good for
Dynamic (DHCP) The server picks an address from a pool. It may change later Phones, laptops, TVs
Static You type the address by hand on the device Servers and printers
DHCP reservation The server always gives the same address to the same device, matched by its MAC address Devices that need a fixed address, such as a port forwarding target

A MAC address is the unique hardware address of a network card. See the Switch vs Router vs Hub tutorial.

Port forwarding needs a fixed address for the target device. See the NAT and Port Forwarding tutorial.

โš ๏ธ If you type a static address by hand, choose one outside the router's DHCP pool. Otherwise the router may give the same address to another device.

๐Ÿ› ๏ธ Try It: See DHCP at Work

Step 1: See Your DHCP Settings

Windows (Command Prompt):

ipconfig /all

Look under your active adapter (Wi-Fi or Ethernet). Sample output (yours will differ):

Wireless LAN adapter Wi-Fi:

   DHCP Enabled. . . . . . . . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 192.168.1.10(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Monday, 2 November 2026 8:00:00 AM
   Lease Expires . . . . . . . . . . : Tuesday, 3 November 2026 8:00:00 AM
   Default Gateway . . . . . . . . . : 192.168.1.1
   DHCP Server . . . . . . . . . . . : 192.168.1.1
   DNS Servers . . . . . . . . . . . : 192.168.1.1
  • DHCP Enabled: Yes means the address came from DHCP
  • DHCP Server is the device that gave you the address (your router)
  • Lease Obtained and Lease Expires show the lease

Linux:

ip addr
ip route

Sample output (yours will differ):

3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
    inet 192.168.1.10/24 brd 192.168.1.255 scope global dynamic wlan0
       valid_lft 85123sec preferred_lft 85123sec

default via 192.168.1.1 dev wlan0 proto dhcp metric 600
192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.10 metric 600
  • The word dynamic means the address came from DHCP
  • valid_lft is how many seconds are left on the lease, and it counts down
  • default via 192.168.1.1 is your default gateway (your router)

Step 2: Watch the DORA Conversation

Your computer does DORA silently, so you normally never see it. To show it, I ran a tiny DHCP server (dnsmasq) and a DHCP client (dhclient) on one test computer. The output below is real, from my run. Your addresses will differ.

What the client printed (shortened):

DHCPDISCOVER on vc0 to 255.255.255.255 port 67 interval 3
DHCPOFFER of 192.168.50.135 from 192.168.50.1
DHCPREQUEST for 192.168.50.135 on vc0 to 255.255.255.255 port 67
DHCPACK of 192.168.50.135 from 192.168.50.1
bound to 192.168.50.135 -- renewal in 17444 seconds.
  • 255.255.255.255 is the broadcast address, and port 67 is the DHCP server port
  • bound to means the client now uses the address
  • renewal in is how many seconds until the client asks to renew. The exact number can be a bit different from T1

What the server logged (shortened):

DHCPDISCOVER(vs0) 22:d8:2a:b6:7a:01
DHCPOFFER(vs0) 192.168.50.135 22:d8:2a:b6:7a:01
DHCPREQUEST(vs0) 192.168.50.135 22:d8:2a:b6:7a:01
DHCPACK(vs0) 192.168.50.135 22:d8:2a:b6:7a:01

The server knows the client by its MAC address (22:d8:2a:b6:7a:01).

The server's Offer also carried the settings. These lines are real, from the same run (shortened):

option: 51 lease-time  12h
option: 58 T1  6h
option: 59 T2  10h30m
option:  1 netmask  255.255.255.0
option:  6 dns-server  8.8.8.8
option:  3 router  192.168.50.1

For a 12-hour lease, T1 is 6 hours and T2 is 10 hours 30 minutes, just like the timeline above.

Afterwards, the client's ip addr showed (real output):

inet 192.168.50.135/24 brd 192.168.50.255 scope global dynamic vc0
   valid_lft 43193sec preferred_lft 43193sec

43193 seconds is about 12 hours, minus a few seconds.

Step 3: Release and Renew (Windows)

โš ๏ธ ipconfig /release switches off your address, so the internet stops until you run /renew. Save your work first.

Open Command Prompt as Administrator:

ipconfig /release
ipconfig /renew
  • /release sends a release message to the DHCP server and gives up the address
  • /renew asks the server for an address again

On Linux, the safest way to renew is to turn your Wi-Fi or network off and on again. Your system then asks the DHCP server again.

Step 4: Know the 169.254 Address

If a device asks for an address and no DHCP server answers, it may give itself an address starting with 169.254. Such an address works only on the local network, and there is no internet. If you see it, DHCP did not work. See the What Is an IP Address? tutorial.

โŒ Common Errors & Solutions

Error / Symptom Cause Fix
The IP address starts with 169.254 No DHCP server answered Restart the router, then reconnect to Wi-Fi or re-plug the cable
No internet after ipconfig /release The address was given up Run ipconfig /renew
unable to contact your DHCP server (Windows) The server did not answer in time Check your connection and restart the router
An "IP address conflict" message Two devices have the same address, often a static address inside the DHCP pool Use a DHCP reservation, or choose a static address outside the pool
Devices get odd gateway or DNS settings Two DHCP servers on one network, for example a second router Turn DHCP off on the extra router
A port forwarding rule stopped working The target device got a new address Create a DHCP reservation for it
No inet line in ip addr (Linux) The device did not get an address Reconnect to the network and check the connection
New devices cannot join The router's address pool is full Make the pool larger, or shorten the lease time

๐Ÿ’ก Pro Tip

For a device that needs a fixed address, use a DHCP reservation instead of typing a static address on the device. Everything stays in one place (the router), and there is no risk of two devices sharing an address.

๐ŸŽฏ Final Summary

- DHCP gives devices their network settings automatically
- It gives: IP address, subnet mask, default gateway, DNS servers, lease time
- At home, the router is the DHCP server
- DHCP uses UDP: server port 67, client port 68
- DORA = Discover, Offer, Request, Acknowledge
- Discover and Request are broadcasts
- An address is leased: renew at half the lease (T1), ask any server at 87.5% (T2)
- Dynamic = from DHCP, static = typed by hand, reservation = same address for the same MAC
- 169.254.x.x means no DHCP server answered
- Windows: ipconfig /all, ipconfig /release, ipconfig /renew
- Linux: ip addr (look for dynamic), ip route

๐Ÿ“Œ Next Tutorial

What Is DNS ? : How a name like google.com tur into an IP address.


TechWithJuned ยท Learn โ†’ Execute โ†’ Build

โœ๏ธ Written by TechWithJuned Team

๐Ÿ’ฌ Questions & Discussion

Have a doubt? Ask below โ€” no login needed.

Loading comments...