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 removes the need to set up each network device by hand. It has two parts: a DHCP server, which is installed in one central place on the network, and client software, which 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 using DHCP.
DHCP can be used on many kinds of networks, 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 receive 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), and 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 defined in 1984 to set up simple devices, such as diskless workstations, with an IP address. It worked in the data link layer, which made it hard to use on many server systems, and a server was needed on each network link. In September 1985, the Bootstrap Protocol (BOOTP) replaced RARP. It 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, but it could give out IP addresses from a pool and take them back when they were no longer in use. It could also deliver many extra settings to devices, including settings for specific platforms. Four years later, in 1997, the DHCPINFORM message type (used for WPAD) and other small changes were added, and this version remains the core of the standard for IPv4 networks. DHCPv6 was first defined in 2003, and in 2018 its definition was replaced, merging prefix delegation and stateless address autoconfiguration.
Overview
The Internet Protocol (IP) sets out how devices communicate within and across local networks on 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, and 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, 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, and addresses that are not renewed can be taken back and reused. With automatic allocation, the server permanently gives a client an address from a range set by an administrator, and 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, and devices may use link-local addressing for tasks limited to their own local network link.
DHCP sends messages over the connectionless User Datagram Protocol (UDP), using 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, and 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 with ping, and a client may check with ARP, to make sure no other device is already using it. 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, but the protocol does not require this, since devices are often unplugged without warning.
Client configuration parameters
A DHCP server can give a device extra setup settings, called configuration parameters. RFC 2132 describes the available DHCP options defined by Internet Assigned Numbers Authority (IANA) - DHCP and BOOTP PARAMETERS.
A DHCP client can choose, change, and replace the settings it receives 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. One way it does this is by setting 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 and what they can do. 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 allows the server to 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. However, DHCP servers can also give out IP addresses for several subnets. In that case, a client that does not yet have an IP address cannot reach a DHCP server on a different subnet, because 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 installed on those subnets. The relay agent runs on a network device that can handle 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 servers' addresses are set by hand in the relay agent. When the server replies, the relay agent passes the reply to the client 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 depending on how the server responds to the messages the client sends.
Reliability
DHCP stays reliable in a few ways: periodic renewal, rebinding, and failover. Each client is given a lease that lasts for some time. Once half of that time has passed, the client starts trying to renew the lease by sending a message to the server that originally granted it. If that server is down or cannot be reached, the client keeps trying from time to time, so it can renew the lease once the server is back.
If the server stays unreachable for a long time, the client tries to rebind by broadcasting its request, which reaches all available DHCP servers, and any server that can renew the lease will do so. For rebinding to work, a backup server must have accurate information about the client, which is hard to keep correct when two servers may update the same lease database. A plan for fault-tolerant DHCP servers was submitted to the Internet Engineering Task Force, but it was never formalized. If rebinding fails, the lease eventually expires, and the client must stop using its IP address. The client then starts over by broadcasting a DHCPDISCOVER message and accepts any IP address offered to it, which breaks any ongoing connections because the address has changed.
IPv6 networks
DHCP was first made for networks that use Internet Protocol version 4 (IPv4). After IPv6 networks were built and started being used, DHCP was also used to give out settings on these networks, even though IPv6 has its own way of setting up addresses called stateless address autoconfiguration. The version of the protocol made for IPv6 is called DHCPv6.
See also: DHCP snooping
The basic DHCP has no way to check who is who, so it can be attacked in three main ways. A fake DHCP server, often called "rogue DHCP", can give clients wrong information. This can stop a client from getting online, which is a denial-of-service attack, or it can let an attacker sit in the middle of a connection, which is a man-in-the-middle attack. Because DHCP also gives clients the addresses of DNS servers, an attacker can send a client to its own DNS server and control the answers it gets. Other attacks happen when clients use credentials that belong to someone else, 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, and these tags are used to control access to network resources. Another extension, Authentication for DHCP Messages (RFC 3118), can check DHCP messages, but it has not been widely used because managing keys for many clients is hard. Newer proposals use 802.1X or PANA, which both carry EAP, to check DHCP requests.

Quiz time!
5 questions about Dynamic Host Configuration Protocol
What does DHCP automatically give to devices connected to 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.