What Is DHCP and How Does It Assign IP Addresses?

DHCP (Dynamic Host Configuration Protocol) is the service that automatically gives a device an IP address, subnet mask, default gateway and DNS servers when it joins a network. Your router almost certainly runs a DHCP server, which is why phones and laptops get online without you typing any network settings.

Without DHCP, every device would need its address configured by hand, and two devices given the same address would knock each other offline. This guide explains how DHCP hands out addresses, what a lease is, how reservations work and how to fix the most common DHCP errors.

What DHCP provides

DHCP for IPv4 is defined in RFC 2131, with the configuration options it can carry listed in RFC 2132. A DHCP server does more than assign an address. A typical response from a home router includes:

SettingDHCP optionExample value
IP addressThe yiaddr field192.168.1.57
Subnet maskOption 1255.255.255.0
Default gateway (router)Option 3192.168.1.1
DNS serversOption 6192.168.1.1 or a public resolver
Domain nameOption 15home.example.com
Lease timeOption 5186400 seconds (24 hours)

The addresses a DHCP server hands out are almost always private ones from the RFC 1918 ranges. You can confirm which kind of address you received with our IP address type checker.

How DHCP works: the DORA process

DHCP runs over UDP. Servers listen on port 67 and clients on port 68. Because a new device has no address yet, the first messages are broadcasts. The exchange is usually remembered as DORA:

  1. Discover. The client sends a DHCPDISCOVER from source 0.0.0.0 to the broadcast address 255.255.255.255, identifying itself by its MAC address.
  2. Offer. Every DHCP server that hears it may reply with a DHCPOFFER proposing an address and options.
  3. Request. The client picks one offer and broadcasts a DHCPREQUEST naming the chosen server. Broadcasting this step lets any other servers know their offers were declined.
  4. Acknowledge. The chosen server confirms with a DHCPACK. The client may then check that nobody else is using the address (for example with an ARP probe) and configures its interface.

Other message types handle the edge cases: DHCPNAK refuses a request (for instance when a laptop asks to keep an address from a different network), DHCPDECLINE tells the server an offered address is already in use, and DHCPRELEASE gives an address back early.

DHCP relays on larger networks

Broadcasts do not cross routers, so business networks with many subnets usually run one central DHCP server and configure each router as a DHCP relay. The relay picks up broadcasts on the local subnet and forwards them as unicast to the server, adding the subnet's gateway address so the server knows which address pool to use.

Leases and renewal

An address from DHCP is a lease, not a permanent assignment. RFC 2131 sets two timers based on the lease length:

  • T1 (renewal), by default at 50% of the lease. The client contacts the server that issued the lease directly and asks to extend it. Normally the server agrees and the address does not change.
  • T2 (rebinding), by default at 87.5% of the lease. If the original server has not answered, the client broadcasts to ask any server to extend the lease.

If the lease expires without renewal, the client must stop using the address and start again from Discover. This is why a device that stays connected usually keeps the same local address for months, while a device that is away longer than the lease time may come back with a different one. The same mechanism, run by your ISP, is one reason your public address changes, as explained in our guide to static vs dynamic IP addresses.

The address pool

The server hands out addresses from a configured range, called a pool or scope, for example 192.168.1.100 to 192.168.1.199. Addresses outside the pool but inside the subnet stay free for devices you configure manually. Use the subnet calculator to see which addresses are valid for your network before choosing a range.

DHCP reservations vs static IPs

Printers, NAS boxes, game consoles and anything you forward ports to need an address that does not change. There are two ways to get one:

  • DHCP reservation (also called static lease or address binding). In the router's DHCP settings you tie a MAC address to an IP. The device still uses DHCP, but always receives the same address. Settings like DNS servers stay centrally managed.
  • Manual static IP. You type the address, mask, gateway and DNS into the device itself. Pick an address outside the DHCP pool to avoid conflicts.

Reservations are usually the better choice at home, because everything is managed in one place. They are the first step in setting up port forwarding.

Note: Phones and computers often use a randomized "private" MAC address per Wi-Fi network. A reservation keyed to the real hardware MAC will not match. Either reserve the randomized address shown in the router's client list or turn off address randomization for that network.

Viewing and renewing your DHCP lease

Windows

ipconfig /all
ipconfig /release
ipconfig /renew

ipconfig /all shows whether DHCP is enabled, which DHCP server answered and when the lease was obtained and expires. /release gives the address back and /renew requests a new lease; run them from an elevated Command Prompt.

macOS

ipconfig getpacket en0           # full DHCP response, including lease_time
sudo ipconfig set en0 DHCP       # restarts DHCP on the interface

Linux

ip addr show                                   # "dynamic" marks a DHCP address
nmcli connection down "Wired connection 1" && nmcli connection up "Wired connection 1"
sudo networkctl renew eth0                     # on systemd-networkd systems

On phones, turning Wi-Fi off and on, or choosing "Forget this network" and reconnecting, performs a fresh DHCP exchange.

Common DHCP problems and fixes

The device has a 169.254.x.x address

If no DHCP server answers, Windows, macOS and most Linux setups assign themselves a link-local address from 169.254.0.0/16 (RFC 3927). Windows may also report "unable to contact your DHCP server". The device can only talk to its neighbours, not the internet. Check the cable or Wi-Fi association, restart the router, and make sure the router's DHCP server is enabled.

The pool is full

A network with many guests or smart-home gadgets can run out of addresses, especially with long lease times. New devices then connect to Wi-Fi but never get an address. Enlarge the pool, shorten the lease time, or remove stale reservations.

IP address conflicts

A conflict usually means someone configured a static IP inside the DHCP pool. Move the static device outside the pool or convert it to a reservation.

Two DHCP servers on one network

Plugging a second router into your network with DHCP enabled creates a rogue DHCP server. Devices get addresses from whichever answers first, and some end up with the wrong gateway. When adding a second router as an access point, disable its DHCP server. Managed switches offer DHCP snooping, which blocks offers from untrusted ports, to prevent this on business networks.

DHCP and IPv6

IPv6 hosts can configure themselves with SLAAC from router advertisements, so DHCP is optional. DHCPv6 (RFC 8415) uses UDP ports 546 and 547 and can assign addresses, supply DNS servers, or delegate whole prefixes to routers. Many ISPs use DHCPv6 prefix delegation to give your router an IPv6 prefix, while your devices on the LAN use SLAAC. Android has historically not supported stateful DHCPv6 address assignment, so networks that rely only on DHCPv6 for addresses leave Android devices without IPv6.

Frequently asked questions

Should I turn off DHCP on my router?

Only if another device, such as a dedicated server or a main router upstream, is providing DHCP on the same network. With no DHCP server at all, every new device would need manual settings.

Is DHCP a security risk?

DHCP has no built-in authentication, so anyone on the local network can run a rogue server or exhaust the pool by requesting many addresses. On a home network the risk is low; on shared or business networks, DHCP snooping and port security on switches address it.

What lease time should I use?

For a home network, the common default of about a day is fine. Guest networks and busy public Wi-Fi benefit from shorter leases, such as one to four hours, so addresses from departed devices return to the pool quickly.

Does DHCP assign my public IP address?

Often, yes. Many ISPs use DHCP to give your router its WAN address. That lease works the same way as the ones your router hands out, which is why your public IP can change after a long outage or a modem replacement.

Try it yourself

Put this guide into practice with our free tools.

Keep reading

Copied to clipboard