DHCP (Dynamic Host Configuration Protocol) Basics


IP Networks use the Dynamic Host Configuration Protocol (DHCP), or Bootstrap Protocol (BOOTP) to dynamically assign an IP address whenever a TCP host connects to the local area network. The DHCP protocol has been around for quite some time. The implementation of DHCP on the local area network is quite simple. There are generally no more than three components related to DHCP on the network, such as the DHCP server, the DHCP client, and the DHCP relay agent if you have a network with more than one subnet.

DHCP Server

The DHCP server is used to centralize and manage the pool of IP addresses that will be used to configure your network clients. A DHCP server could run on a variety of different types of network servers, such as Windows Server, or Linux. In addition, there are many network appliances such as the typical consumer-based Internet routers you may even have in your home network. The main purpose of the DHCP server is to service DHCP clients and provide an IP configuration that is appropriate for the network segment that the client is located on. When a DHCP server negotiates an IP lease with the client, it will offer in its lease to the client, not only the IP address, but also other IP settings such as a subnet mask, default gateway, DNS settings, etc. Here are some of the most common lease options that are assigned to DHCP clients

 

Code Option Name Description
1 Subnet Mask Specifies the subnet mask
3 Router Routers (Gateways) on the client’s subnet
6 DNS Servers List of DNS servers available for the client
15 Domain Name DNS Domain Suffix the client should use
44 WINS/NBNS Servers List of NetBIOS Name Servers
46 WINS/NBT Node Type Configure NetBIOS clients as 1 = b-node, 2 = p-node, 4 = m-node, and 8 = h-node.

 

For a complete list of DHCP options, please visit IETF.org: RFC 2132

 

DHCP Client

Most network devices, especially computers are configured by default as DHCP Clients. When a DHCP client boots up and senses network connectivity, it sends out a DHCP Discover on the network. This special packet is a broadcast packet. Any DHCP server that receives this Discover packet will respond back with a DHCP Offer packet. The client may receive multiple offers from different DHCP servers. It will respond back to the Offer with a Request and if the DHCP server receives this response from the client, it will send back an Acknowledgement that the client may proceed with the use of the IP in the original offer. This process is also known as DORA (Discover, Offer, Request, Acknowledgement). Once the DHCP lease is accepted and processed by the client, it holds on to this IP for a fixed amount of time that is set by the lease, usually 8 days (configurable in the DHCP scope). At 50% of the lease time, the client will begin the renegotiation of the lease.
dhcp client

If the client is unable to communicate with its DHCP server, it will attempt to do so again at 87.5% of the lease. It will continue to renegotiate until it is able to or the lease expires. If the lease expires, the process starts again with the client sending out a Discover packet. If the client is unable to acquire a lease, for most operating systems, it will issue itself an APIPA address. APIPA is short for Automatic Private IP Addressing. APIPA addresses are within the 169.254.x.x/16 subnet range. The DHCP client assigns itself the last two octets of an APIPA address automatically. An algorithm is used and factors in the client’s MAC address to ensure that the APIPA address is unique on the network. This will at least allow all the DHCP clients on a single network to continue to communicate with each other in the event of a DHCP server failure. However, APIPA does not assign a default gateway since there is no router configured on the 169.254.x.x subnet so clients will have no Internet connectivity with an APIPA address.

 

The DHCP relay Agent

The DHCP relay agent is a Bootstrap Protocol that relays DHCP (DORA) messages between DHCP clients and DHCP servers on different IP Subnets. A relay agent can be a computer or device such as a router that intercepts DHCP broadcast packets and relays them as unicast packets to the configured DHCP server(s). The DHCP server would then send responses back to the DHCP relay agent, and the relay agent sends the information back to the DHCP client.
dhcp dora

Since broadcast packets are not passed through routers, the relay agent is needed so that you can avoid having a DHCP server implemented on every subnet where you have DHCP clients.

 

The process in obtaining an IP address from a DHCP server is fairly simple and straightforward. This basic process, while taken for granted by many network administrators, is key in understanding how clients obtain and negotiate IP leases. The process in obtaining a valid IP address from a DHCP server can be broken down into four phases. These four phases are as follows: DHCP Discover, DHCP Offer, DHCP Request, and DHCP Acknowledgement. Let’s examine these phases for a client that is simply plugged into the network. When the network interface is brought online, the process begins as follows:

DHCPDISCOVER

In the first phase, the client broadcasts messages on the subnet to discover all available DHCP servers. A network administrator can configure a DHCP Relay Agent on the gateway’s interface for relaying the broadcast packet directly to a DHCP server in situations where a DHCP server is not physically located on the same segment as the DHCP clients. If a Relay Agent intercepts the packet, it will update the GIADDR (Gateway IP Address) field. This client creates a User Datagram Protocol (UDP) packet with the IP destination address of 255.255.255.255 (Broadcast).

 

Type: UDP
Source IP: 0.0.0.0
Source Port: 68
Destination IP: 255.255.255.255
Destination Port: 67

DHCPOFFER

When a DHCP server receives an IP lease request from a client, it immediately reserves an IP address for the client and extends an IP lease offer by sending a DHCPOFFER message to the client. This message contains the client’s MAC address, the IP address that the server is offering, the subnet mask, the lease duration, and the IP address of the DHCP server making the offer. The DHCP server specifies the IP lease address in the YIADDR (Your IP Address) field.

Type: UDP
Source IP: DHCP Server’s IP
Source Port: 67
Destination IP: 255.255.255.255 (or DHCP Relay Agent IP if used)
Destination Port: 68

DHCPREQUEST

A client can receive DHCP offers from multiple servers, but it will accept only one DHCP offer and broadcast a DHCP request message. Based on the Transaction ID field in the request, servers are informed whose offer the client has accepted. When other DHCP servers receive this message, they withdraw any offers that they might have made to the client and return the offered address to the pool of available addresses.

Type: UDP
Source IP: 0.0.0.0
Source Port: 68
Destination IP: 255.255.255.255
Destination Port: 67

DHCPACK

When the DHCP server receives the DHCPREQUEST message from the client, the configuration processes enters its final phase. The acknowledgement phase involves sending a DHCPACK packet to the client. This packet includes the lease duration and any other configuration information that the client might have requested. At this point, the IP configuration process is completed. If the DHCP server is unable to offer the lease (especially for DHCP requests to renew an existing lease), the DHCP server will send a DHCP Negative Acknowledgement, or DHCPNACK, back to the client.

Type: UDP
Source IP: DHCP Server’s IP
Source Port: 67
Destination IP: 255.255.255.255 (or DHCP Relay Agent IP if used)
Destination Port: 68

 

When DHCP clients already have an active lease in place, they will attempt to renew the lease at 50% of the lease time. For example, if the lease was issued for 8 days, the client will attempt to re-negotiate the lease at 4 days. If it is unsuccessful in contacting the DHCP server at that time, it will attempt again when it reaches 87.5% of the lease period. If it is unsuccessful at this point, the client will continue regularly sending DHCPREQUEST packets until the lease is expired. Once the lease expires, the client will begin the process again from the DHCPDISCOVER phase. If the client is unsuccessful in obtaining an IP, by default, it will assign itself an APIPA address (Windows clients).

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: