Safekipedia

Dynamic Host Configuration Protocol

Adventurer · ages 7–10Adapted from Wikipedia
A diagram showing how the Dynamic Host Configuration Protocol (DHCP) works using a client/server model, including how traffic is routed between the parts of the network.

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.

An illustration of a typical non-renewing DHCP session; each message may be either a broadcast or a unicast, depending on the DHCP client capabilities.

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.

Application and service parameters: Section 8 
CodeNameLength
40Network information service domainMinimum of 1 octet
41Network information serversMultiples of 4 octets
42Network Time Protocol (NTP) serversMultiples of 4 octets
43Vendor-specific informationMinimum of 1 octets
44NetBIOS over TCP/IP name serverMultiples of 4 octets
45NetBIOS over TCP/IP datagram Distribution ServerMultiples of 4 octets
46NetBIOS over TCP/IP node type1 octet
47NetBIOS over TCP/IP scopeMinimum of 1 octet
48X Window System font serverMultiples of 4 octets
49X Window System display managerMultiples of 4 octets
64Network Information Service+ domainMinimum of 1 octet
65Network Information Service+ serversMultiples of 4 octets
68Mobile IP home agentMultiples of 4 octets
69Simple Mail Transfer Protocol (SMTP) serverMultiples of 4 octets
70Post Office Protocol (POP3) serverMultiples of 4 octets
71Network News Transfer Protocol (NNTP) serverMultiples of 4 octets
72Default World Wide Web (WWW) serverMultiples of 4 octets
73Default Finger protocol serverMultiples of 4 octets
74Default Internet Relay Chat (IRC) serverMultiples of 4 octets
75StreetTalk serverMultiples of 4 octets
76StreetTalk Directory Assistance (STDA) serverMultiples of 4 octets
DHCP extensions: Section 9 
CodeNameLength
50Requested IP address4 octets
51IP address lease time4 octets
52Option overload1 octet
53DHCP message type1 octet
54Server identifier4 octets
55Parameter request listMinimum of 1 octet
56MessageMinimum of 1 octet
57Maximum DHCP message size2 octets
58Renewal (T1) time value4 octets
59Rebinding (T2) time value4 octets
60Vendor class identifierMinimum of 1 octet
61Client identifierMinimum of 2 octets
66TFTP server nameMinimum of 1 octet
67Bootfile nameMinimum of 1 octet
DHCP message types
CodeNameLengthRFC
1DHCPDISCOVER1 octet2132: §9.6 
2DHCPOFFER1 octet2132
3DHCPREQUEST1 octet2132
4DHCPDECLINE1 octet2132
5DHCPACK1 octet2132
6DHCPNAK1 octet2132
7DHCPRELEASE1 octet2132
8DHCPINFORM1 octet2132
9DHCPFORCERENEW1 octet3203: §4 
10DHCPLEASEQUERY1 octet4388: §6.1 
11DHCPLEASEUNASSIGNED1 octet4388
12DHCPLEASEUNKNOWN1 octet4388
13DHCPLEASEACTIVE1 octet4388
14DHCPBULKLEASEQUERY1 octet6926: §6.2.1 
15DHCPLEASEQUERYDONE1 octet6926
16DHCPACTIVELEASEQUERY1 octet7724: §5.2.1 
17DHCPLEASEQUERYSTATUS1 octet7724
18DHCPTLS1 octet7724
Documented DHCP options
CodeNameLengthRFC
77User ClassMinimum of 2 octets3004
82Relay agent informationMinimum of 2 octets3046
85Novell Directory Service (NDS) serversMinimum of 4 octets, multiple of 4 octets2241: §2 
86NDS tree nameVariable2241: §3 
87NDS contextVariable2241: §4 
100Time zone, POSIX styleVariable4833
101Time zone, tz database styleVariable4833
114DHCP Captive PortalVariable8910
119Domain searchVariable3397
121Classless static routeVariable3442
209Configuration FileVariable5071
210Path PrefixVariable5071
211Reboot TimeVariable5071
224–254site-specific optionsVariable3942
Relay agent sub-options
CodeNameLengthRFC
1Agent Circuit IDMinimum of 1 octet3046
2Agent Remote IDMinimum of 1 octet3046
4Data-Over-Cable Service Interface Specifications (DOCSIS) device class4 octets3256
5Link Selection4 octets3527

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 simplified DHCP client state-transition diagram based on figure 5 of RFC 2131

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

Question 1 of 4

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.