DHCP
Dynamic Host Configuration Protocol
In short
DHCP is a network protocol that automatically gives devices an IP address and other settings, such as the router and DNS server, when they join a network.
What is DHCP?
DHCP, the Dynamic Host Configuration Protocol, is how most devices get their network settings automatically. When a laptop, phone, or server joins a network, a DHCP server hands it an IP address, a subnet mask, the address of the default gateway (the router), and the DNS servers to use. Without DHCP, someone would have to type these settings into every device by hand and make sure no two devices got the same address.
The exchange has four steps, often remembered as DORA: the new device broadcasts a Discover message, a server replies with an Offer, the device sends a Request for that address, and the server confirms with an Acknowledge. The address is not given forever but leased for a set time, such as 24 hours, and the device renews the lease before it expires, so addresses from devices that leave can be reused. DHCP for IPv4 runs over UDP, with servers listening on port 67 and clients on port 68.
Think of a hotel front desk: when you check in, you get a room number for the length of your stay, and when you leave, the room goes back to the pool for the next guest. In home networks, the router usually acts as the DHCP server, while offices and data centers run dedicated servers, and cloud platforms use DHCP to hand out addresses to virtual machines.
DHCP is often confused with DNS. DHCP gives a device its IP address and network settings, while DNS translates domain names such as example.com into IP addresses; DHCP simply tells the device which DNS server to ask. Because DHCP addresses can change, servers and printers usually get a reservation, a fixed address that the DHCP server always gives to that device, or a static IP address configured on the device itself.
Key takeaways
- DHCP automatically assigns IP addresses and network settings to devices.
- The four-step exchange is Discover, Offer, Request, Acknowledge (DORA).
- Addresses are leased for a limited time and renewed before they expire.
- DHCP for IPv4 uses UDP ports
67(server) and68(client). - A DHCP reservation gives a device the same address every time.
Example
# dnsmasq.conf: a DHCP server for a small home or lab network
interface=eth0
# Hand out addresses from .100 to .200, each leased for 24 hours
dhcp-range=192.168.1.100,192.168.1.200,24h
# Settings sent to every client along with its address
dhcp-option=option:router,192.168.1.1
dhcp-option=option:dns-server,192.168.1.1
# Reservation: the device with this MAC address always gets .10
dhcp-host=aa:bb:cc:dd:ee:ff,192.168.1.10Readers ask
What is the difference between DHCP and DNS?
DHCP gives a device its IP address and network settings when it joins a network. DNS translates domain names into IP addresses, and DHCP is usually what tells a device which DNS server to use.
What is a DHCP lease?
A lease is the period of time a device is allowed to use the IP address it was given, such as 8 or 24 hours. The device renews the lease automatically before it expires and usually keeps the same address.
What happens if a DHCP server is unavailable?
A device may keep using an address whose lease hasn't expired yet, or it falls back to a self-assigned link-local address in the 169.254.0.0/16 range. That address only works on the local network segment, so the device typically has no internet access.
See also
- IP AddressNetworking, p. 10An IP address is a numeric label assigned to each device on a network so that data can be routed to it, much like a postal address for a house.
- SubnetNetworking, p. 29A subnet is a smaller network carved out of a larger one by splitting its range of IP addresses, which keeps traffic organized, contained, and easier to secure.
- DNSDevOps & Cloud, p. 16DNS is the internet's naming system that translates human-readable domain names like example.com into the numeric IP addresses computers use to connect.
- UDPNetworking, p. 35UDP is a lightweight internet protocol that sends small, independent messages called datagrams without a connection, favoring speed over guaranteed delivery.
- NATNetworking, p. 17NAT is a technique in which a router rewrites the IP addresses in passing packets, letting many devices on a private network share one public IP address.
- PortNetworking, p. 22A port is a number from 0 to 65535 that identifies a specific program or service on a device, so traffic reaching an IP address gets to the right application.
Spotted a mistake or something missing on this page?Suggest an edit