Safekipedia

Dynamic Host Configuration Protocol

Discoverer · ages 10+Adapted 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 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.

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), 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.

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. 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 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 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

Question 1 of 5

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.