Dynamic Host Configuration Protocol
The Dynamic Host Configuration Protocol (DHCP) is a network management protocol used on Internet Protocol-based networks. It automatically gives devices connected to a network their IP addresses and other settings. It works in a client–server setup.
DHCP means that people do not have to set up each network device by hand. It has two parts. A DHCP server is installed in one central place on the network. Client software runs on each computer or device through its protocol stack. When a device connects to the network, and again from time to time after that, the client requests a set of settings from the server.
DHCP can be used on many kinds of networks. These range from small residential networks in homes to large campus networks and regional ISP networks. Many routers and residential gateways can act as DHCP servers. Most home network routers get a unique IP address from the ISP network. Inside a local network, a DHCP server gives each device its own local IP address.
DHCP works on networks that use Internet Protocol version 4 (IPv4). It also has a version for IPv6. The IPv6 version of the protocol is commonly called DHCPv6.
History
The Reverse Address Resolution Protocol (RARP) was created in 1984. It helped simple devices, such as diskless workstations, get an IP address. It worked at the data link layer, which made it hard to use on many server systems. Each network link needed its own server. In September 1985, the Bootstrap Protocol (BOOTP) took its place. BOOTP added a relay agent, so one central BOOTP server could serve devices on many IP subnets.
DHCP was first defined in October 1993. It was based on BOOTP. It could give out IP addresses from a pool and take them back when they were no longer being used. It could also send many extra settings to devices, including settings for specific platforms. Four years later, in 1997, a message type called DHCPINFORM, used for WPAD, and some other small changes were added. This version is still the main standard for IPv4 networks. DHCPv6 was first defined in 2003. In 2018, its definition was replaced. The new version combined prefix delegation and stateless address autoconfiguration.
Overview
The Internet Protocol (IP) sets out how devices talk to each other on local networks and across the Internet. A DHCP server can manage IP settings for devices on its local network by giving them IP addresses automatically. DHCP works on the client–server model. When a computer or other device connects to a network, the DHCP client software sends a broadcast request for the information it needs. Any DHCP server on the network may answer. The server keeps a pool of IP addresses and settings such as the default gateway, domain name, name servers, and time servers. Clients usually ask for this information right after booting, and then again from time to time. On large networks with several connected parts, small helper programs called DHCP relay agents on the routers let one server serve the whole network.
The server can give out addresses in three ways. With dynamic allocation, a network administrator sets aside a range of addresses for clients on the LAN to request. Addresses that are not renewed can be taken back and used again. With automatic allocation, the server permanently gives a client an address from a range set by an administrator. It tries to give the client the same address it had before. With manual allocation, an administrator matches each client's MAC address to a fixed IP address. DHCP is used for Internet Protocol version 4 (IPv4) and IPv6. Devices may also use link-local addressing for tasks that only need their own local network link.
DHCP sends messages over the connectionless User Datagram Protocol (UDP). It uses the same port numbers as BOOTP. The server listens on port 67, and the client listens on port 68. The process has four steps, often shortened to DORA: discovery, offer, request, and acknowledgement. A client usually starts by sending a broadcast request. If the client and server are in different broadcast domains, a DHCP Helper or DHCP Relay Agent may be used. A client that is renewing an address it already has can talk directly to the server using unicast.
The client first sends a discovery message to the broadcast address of its network. It may ask for a specific IP address. The message includes the client's Ethernet hardware address. The server reserves an address and sends an offer. The client replies with a request for that address, and the server confirms it with an acknowledgement. Before using an address, a server may check it with ping. A client may check it with ARP. These checks make sure no other device is already using the address. Clients can also ask for extra information, such as web proxy settings through WPAD. When a device leaves the network, it may send a release message. The protocol does not require this, because devices are often unplugged without warning.
Client configuration parameters
A DHCP server can give a device extra setup settings, called configuration parameters. Internet Assigned Numbers Authority (IANA) keeps a list of these settings in DHCP and BOOTP PARAMETERS.
A DHCP client can choose, change, and replace the settings it gets from a DHCP server. On Unix-like systems, these changes usually follow the settings in the file /etc/dhclient.conf.
Options
Options are small pieces of information sent in a set pattern: a code, a length, and then the value. The first part is the option code, the second part tells how many more parts follow, and the rest holds the information itself. For example, a message saying an offer is being made uses the code 53 for "DHCP message type," then 1 part to follow, then the value "offer."
The following tables list the available DHCP options.
DHCP message types
This table lists the DHCP message types. These codes are the value in the DHCP extension 53, shown in the table above.
Client vendor identification
A DHCP client can share information about the company that made it and what it can do. It does this by sending a special value called the Vendor Class Identifier (Option 60) in its requests. This helps the DHCP server know what extra information the client might need in its reply. For example, some set-top boxes use this value to tell the server what kind of device they are. An Aruba campus wireless access point sends the value 'ArubaAP,' and the server can then reply with the address of an Aruba wireless controller, so the access point knows where to register itself. This helps the server tell different client machines apart and handle their requests properly.
Other extensions
Relay agent information sub-options
The relay agent information option (option 82) is a container that holds extra parts attached to DHCP requests sent between a DHCP relay and a DHCP server.
| Code | Name | Length |
|---|---|---|
| 40 | Network information service domain | Minimum of 1 octet |
| 41 | Network information servers | Multiples of 4 octets |
| 42 | Network Time Protocol (NTP) servers | Multiples of 4 octets |
| 43 | Vendor-specific information | Minimum of 1 octets |
| 44 | NetBIOS over TCP/IP name server | Multiples of 4 octets |
| 45 | NetBIOS over TCP/IP datagram Distribution Server | Multiples of 4 octets |
| 46 | NetBIOS over TCP/IP node type | 1 octet |
| 47 | NetBIOS over TCP/IP scope | Minimum of 1 octet |
| 48 | X Window System font server | Multiples of 4 octets |
| 49 | X Window System display manager | Multiples of 4 octets |
| 64 | Network Information Service+ domain | Minimum of 1 octet |
| 65 | Network Information Service+ servers | Multiples of 4 octets |
| 68 | Mobile IP home agent | Multiples of 4 octets |
| 69 | Simple Mail Transfer Protocol (SMTP) server | Multiples of 4 octets |
| 70 | Post Office Protocol (POP3) server | Multiples of 4 octets |
| 71 | Network News Transfer Protocol (NNTP) server | Multiples of 4 octets |
| 72 | Default World Wide Web (WWW) server | Multiples of 4 octets |
| 73 | Default Finger protocol server | Multiples of 4 octets |
| 74 | Default Internet Relay Chat (IRC) server | Multiples of 4 octets |
| 75 | StreetTalk server | Multiples of 4 octets |
| 76 | StreetTalk Directory Assistance (STDA) server | Multiples of 4 octets |
| Code | Name | Length |
|---|---|---|
| 50 | Requested IP address | 4 octets |
| 51 | IP address lease time | 4 octets |
| 52 | Option overload | 1 octet |
| 53 | DHCP message type | 1 octet |
| 54 | Server identifier | 4 octets |
| 55 | Parameter request list | Minimum of 1 octet |
| 56 | Message | Minimum of 1 octet |
| 57 | Maximum DHCP message size | 2 octets |
| 58 | Renewal (T1) time value | 4 octets |
| 59 | Rebinding (T2) time value | 4 octets |
| 60 | Vendor class identifier | Minimum of 1 octet |
| 61 | Client identifier | Minimum of 2 octets |
| 66 | TFTP server name | Minimum of 1 octet |
| 67 | Bootfile name | Minimum of 1 octet |
| Code | Name | Length | RFC |
|---|---|---|---|
| 1 | DHCPDISCOVER | 1 octet | 2132: §9.6 |
| 2 | DHCPOFFER | 1 octet | 2132 |
| 3 | DHCPREQUEST | 1 octet | 2132 |
| 4 | DHCPDECLINE | 1 octet | 2132 |
| 5 | DHCPACK | 1 octet | 2132 |
| 6 | DHCPNAK | 1 octet | 2132 |
| 7 | DHCPRELEASE | 1 octet | 2132 |
| 8 | DHCPINFORM | 1 octet | 2132 |
| 9 | DHCPFORCERENEW | 1 octet | 3203: §4 |
| 10 | DHCPLEASEQUERY | 1 octet | 4388: §6.1 |
| 11 | DHCPLEASEUNASSIGNED | 1 octet | 4388 |
| 12 | DHCPLEASEUNKNOWN | 1 octet | 4388 |
| 13 | DHCPLEASEACTIVE | 1 octet | 4388 |
| 14 | DHCPBULKLEASEQUERY | 1 octet | 6926: §6.2.1 |
| 15 | DHCPLEASEQUERYDONE | 1 octet | 6926 |
| 16 | DHCPACTIVELEASEQUERY | 1 octet | 7724: §5.2.1 |
| 17 | DHCPLEASEQUERYSTATUS | 1 octet | 7724 |
| 18 | DHCPTLS | 1 octet | 7724 |
| Code | Name | Length | RFC |
|---|---|---|---|
| 77 | User Class | Minimum of 2 octets | 3004 |
| 82 | Relay agent information | Minimum of 2 octets | 3046 |
| 85 | Novell Directory Service (NDS) servers | Minimum of 4 octets, multiple of 4 octets | 2241: §2 |
| 86 | NDS tree name | Variable | 2241: §3 |
| 87 | NDS context | Variable | 2241: §4 |
| 100 | Time zone, POSIX style | Variable | 4833 |
| 101 | Time zone, tz database style | Variable | 4833 |
| 114 | DHCP Captive Portal | Variable | 8910 |
| 119 | Domain search | Variable | 3397 |
| 121 | Classless static route | Variable | 3442 |
| 209 | Configuration File | Variable | 5071 |
| 210 | Path Prefix | Variable | 5071 |
| 211 | Reboot Time | Variable | 5071 |
| 224–254 | site-specific options | Variable | 3942 |
Relaying
In small networks, where only one IP subnet is managed, DHCP clients talk directly to DHCP servers. Sometimes, though, DHCP servers give out IP addresses for several subnets. In that case, a client that does not have an IP address yet cannot reach a DHCP server on a different subnet. Its broadcast can only be heard on its own subnet.
To help clients on subnets without a DHCP server, a DHCP relay agent can be set up on those subnets. The relay agent runs on a network device that handles routing between the client's subnet and the server's subnet. It receives the client's broadcast and sends it to the DHCP servers using unicast. The server addresses are entered into the relay agent by hand. When the server replies, the relay agent passes the reply to the client. It does this in an Ethernet frame addressed to the client's device address. If a client cannot accept unicast packets before it has an IP address, it can set a flag asking for a broadcast reply instead.
Client states
A DHCP client can get these messages from a server:: §4.4
- DHCPOFFER
- DHCPACK
- DHCPNAK
The client changes its DHCP state based on how the server answers the messages the client sends.
Reliability
DHCP stays reliable in a few ways: renewing, rebinding, and failover. Each client gets a lease that lasts for some time. Once half of that time has passed, the client tries to renew the lease by sending a message to the server that gave it. If that server is down or cannot be reached, the client keeps trying from time to time, so it can renew the lease when the server is back.
If the server stays unreachable for a long time, the client tries to rebind. It sends its request to all available DHCP servers, and any server that can renew the lease will do so. For rebinding to work, a backup server needs correct information about the client. This is hard to keep correct when two servers may update the same lease database. A plan for fault-tolerant DHCP servers was sent to the Internet Engineering Task Force, but it was never made official. If rebinding fails, the lease eventually runs out, and the client must stop using its IP address. The client then starts over by sending a DHCPDISCOVER message and accepts any IP address offered to it. This can break ongoing connections, because the address has changed.
IPv6 networks
DHCP was first made for networks that use Internet Protocol version 4 (IPv4). Later, people built IPv6 networks. DHCP was also used on these networks to give out settings. IPv6 has its own way to set up addresses, called stateless address autoconfiguration. The version of DHCP made for IPv6 is called DHCPv6.
See also: DHCP snooping
Basic DHCP cannot check who is who. This means bad actors can attack it in a few ways. A fake DHCP server, often called "rogue DHCP", can give devices wrong information. This can stop a device from getting online, which is a denial-of-service attack. It can also let an attacker secretly sit in the middle of a connection, which is a man-in-the-middle attack. DHCP also gives devices the addresses of DNS servers. So an attacker could send a device to its own DNS server and control the answers it gets. Other attacks use someone else's login details, or keep asking for new addresses until none are left for other devices.
DHCP has some ways to reduce these problems. The Relay Agent Information Option lets network operators add tags to messages on their trusted network. These tags help control access to network resources. Another extension, Authentication for DHCP Messages (RFC 3118), can check DHCP messages. However, it has not been widely used, because managing keys for many devices is hard. Newer ideas use 802.1X or PANA to check DHCP requests. Both of these work with EAP.

Quiz time!
4 questions about Dynamic Host Configuration Protocol
What does DHCP do for the devices on a network?
Keep exploring
This article is a child-friendly adaptation of the Wikipedia article on Dynamic Host Configuration Protocol, available under CC BY-SA 4.0.
Images from Wikimedia Commons. Tap any image to view credits and license.