DHCP (Dynamic Host Configuration Protocol) is an internet protocol that allows computers in a network to obtain an IP address and all the network parameters automatically from the ISP. This eliminates the need to set the IP addresses manually of all computers in the network.
DHCP is based on the previous protocol BOOTP.
DHCP is part of the TCP/IP stack, and it uses UDP as the transport protocol.
It uses port 67 for server/relay agent reception and port 68 for client reception.
The message structure of the DHCP protocol is the same for every message, but the content of the fields is different.
“Op”: identifies the message as either request (1) or reply (2).
“HW Type” (“htype”): identifies the type of hardware address that uses the host. It is the same id used in the ARP protocol.
“HW Len” (“hlen”): is the length in bytes of the hardware address.
Campo “Hops”: is the number of relay agents that the message crosses. The sender sets this field in zero, and each relay agent increments it by one.
“Transaction ID” (“xid”): is a random number that the client sets on the request message, and the server copies it back in the reply message. It is used to match the reply with its request.
“Secs”: is the time in seconds since the first attempt to obtain an address or since the last renewal.
“Flags”: this field contains only the broadcast flag. The client sets this flag if the replies have to be sent broadcast.
“Client IP Address” (“ciaddr”): is the current IP address of the client. Zero in case that it is not assigned yet.
“Your IP Address” (“yiaddr”): is the IP address that the server is offering to the client.
“Next Server IP Address” (“siaddr”): is the IP address of the next server to be used in the bootstrap process (for example, to download the OS image).
“Gateway Relay IP Address” (“giaddr”): is the IP address of the relay agent. The relay agents set this field before forwarding a message.
“Client Hardware Address” (“chaddr”): is the hardware address of the client.
“Server Name” (“sname”): is the name of the server. Usually, it is not used and is legacy from BOOTP.
“Boot File Name” (“file”): is the path of the boot file. Usually, it is not used and is legacy from BOOTP.
Options: the options included in a message are variable. Some of them have fixed lengths and other variables. They are composed of these subfields:
- “tag”: 8 bits for the option type.
- “length”: 8 bits for the option length in bytes. In the case of options of fixed length, this subfield is not used.
- “value”: is the value of the option.
Some of the most important options are:
- Subnet Mask (1)
- Router Address (3)
- Domain Name Server (6)
- Domain Name (15)
- Address Lease Time (51)
- DHCP Message Type (53)
- Server Identifier (54)
- Lease Renewal Time (58)
According to the client’s finite state machine, there are three different processes: DORA, RENEWAL, and RELEASE.
DORA Process:
- In “Init” state, the client has no configuration assigned, and it sends a DISCOVER message.
- In “Selecting” state, the client is waiting for the OFFER messages from different servers.
- In “Requesting” state, the client selects the offered configuration, and then it sends a REQUEST message.
- If the server accepts the requested configuration, then it sends an ACK message. After receiving this message, the client that now has a configuration assigned goes to “Bound” state, and the DORA process ends.
RENEWAL Process:
- When the T1 timeout is elapsed, the client enters the “Renewing” state. It sends a REQUEST message to the server that gave the current configuration.
- If message ACK is received, the client goes again to “Bound” state.
- If message ACK is not received and the T2 timeout is elapsed, the client enters the “Rebinding” state. So, a new DORA process begins.
- When the lease time expires, the client enters “Init” state and is not allowed to operate in the network until it gets a new configuration.
Release Process:
- When the client does not need the configuration assigned anymore (for example, when the host powers off), it sends a RELEASE message to the server to free the lease.
Scenario without relay agent:
When the DHCP servers are in the same subnet that the clients are, there is no need to use relay agents.
DORA Process:
- DISCOVER:
The client sends a DISCOVER in broadcast to all servers in the subnet. - OFFER:
Every server in the subnet sends an OFFER with the offered configuration to the client.
The “yiaddr” field contains the IP address offered. Option 54 has the IP address of the server. - REQUEST:
The client selects one of the offered configurations and then sends a REQUEST. Broadcast is sent so that all servers receive the message, even to those that do not offer the accepted configuration. This allows servers to flush this offer from memory. - ACK:
The server that receives the REQUEST checks if that configuration belongs to it. And if it is so, send an ACK message to confirm the lease.
RENEWAL Process:
- REQUEST:
When the remaining lease time is half of the original, the client sends a REQUEST message in unicast. The field “ciaddr” has the IP address that is being requested for a renewal. - ACK:
The server receives the REQUEST message, and if it can renew the lease, then it sends back an ACK in unicast. The field “yiaddr” contains the IP address renewed. Option 54 has the IP address of the server.
RELEASE Process:
- RELEASE:
When the client uses no more the configuration assigned, then sends a message RELEASE in unicast. The field “ciaddr” contains the IP address to be released.
Scenario with relay agent:
When DHCP servers are in different subnets than the clients, then relay agents are necessary.
DORA Process:
- DISCOVER:
The client sends a DISCOVER in broadcast. The relay agent receives the message and forwards it to the server, which is in a different subnet, in unicast. The relay agent completes the field “giaddr” with the interface’s IP address where it received the message. - OFFER:
The server sends an OFFER in unicast to the address that is in “giaddr” field. The field “yiaddr” contains the IP address offered. Option 54 has the IP address of the server. The relay agent receives the message and forwards it to the client in broadcast. - REQUEST:
The client selects one of the offered configurations and then sends a REQUEST in broadcast. The field “yiaddr” has the chosen IP address. Option 54 has the IP address of the selected server.
The relay agent receives the message and forwards it to the server, which is in a different subnet, in unicast. The relay agent completes the field “giaddr” with the interface’s IP address where it received the message. - ACK:
The server that receives the REQUEST checks if that configuration belongs to it. And if it is so, send an ACK in unicast to the address that is in “giaddr” field to confirm the lease. The relay agent receives the message and forwards it to the client in broadcast.
RENEWAL Process:
This process is the same as without a relay agent because the messages are unicast between client and server.
RELEASE Process:
This process is the same as without a relay agent because the messages are unicast between client and server.
Conclusions:
- Network traffic of the server using a relay agent is unicast.
- DORA process is the only one that changes.
- Field “giaddr” is used only with relay agents.
- Latency of the DORA process is increased because of the relay agents.