Overview

DHCP is the protocol used to automatically distribute IP addresses and other TCP/IP configurations. DHCP is a very commonly used protocol. It is important to understand how it works.

What is DHCP(Dynamic Host Configuration Protocol)?

DHCP (Dynamic Host Configuration Protocol) is the protocol used to automatically configure IP addresses and other configurations required for TCP/IP communication.

In order to communicate with TCP/IP, it is a prerequisite that the TCP/IP configurations are correct. If the configurations are incorrect, of course, normal communication will not be possible. Specific configurations include the following.

  • IP address / Subnet mask
  • Default gateway IP address
  • DNS server IP address

Users who are familiar with information technology will be able to configure these settings without difficulty. However, for users who are not so familiar with information technology, it can be a challenge to configure TCP/IP by themselves. Even experienced users often make mistakes. In order to eliminate such mistakes, it is effective to automate the configuration. DHCP is the protocol for this purpose.

DHCP automatically configures the necessary TCP/IP settings once the host is connected to the network, allowing even users unfamiliar with IT technology to make the correct configurations. This also prevents problems caused by simple misconfigurations.

DHCP message encapsulation

DHCP is a protocol located in the application layer that uses UDP in the transport layer. Note that although DHCP is a protocol located at the application layer, its purpose is not to define application functions or data formats, but rather to configure the necessary configurations for TCP/IP communication.

DHCP messages are encapsulated in UDP header. Well-known port numbers are 67 and 68: 67 for the DHCP server and 68 for the DHCP client. Further encapsulation is done with IP header. The physical signal is then sent out to the transmission medium by encapsulating it with an Ethernet header and an 802.11 (Wi-Fi) header.

Figure: DHCP message encapsulation
Figure: DHCP message encapsulation

Overview of DHCP behavior

To use DHCP, prepare a DHCP server in advance and register TCP/IP configurations, such as IP addresses to be distributed, etc. Windows/Linux servers can be used as DHCP servers. Routers/Layer 3 switches also have a DHCP server function.

When a DHCP client host connects to the network, it exchanges the following four messages with the DHCP server to automatically configure TCP/IP settings.

  1. DHCP DISCOVER
  2. DHCP OFFER
  3. DHCP REQUEST
  4. DHCP ACK
Figure: Overview of DHCP behavior
Figure: Overview of DHCP behavior

The DHCP exchange described above uses broadcast. To begin with, the DHCP client does not know its own IP address. Of course, the IP address of the DHCP server is also unknown. Even if the client does not know the IP address of the DHCP server, broadcast is used when the client wants to send some data.The idea is that if you send a broadcast to everyone on the same network, if there is a DHCP server on the same network, the DHCP server will respond back. In order to use broadcast, the DHCP server and DHCP client must, in principle, be connected to the same network.This is because routers interconnecting networks do not forward broadcasts to other networks.

When DHCP is used to obtain configuration information, the IP address of a host can change frequently, making it time-consuming to identify the host if the IP address changes. When DHCP is used to automatically set IP addresses, it is also possible to distribute a fixed IP address.

DHCP Relay Agent

The DHCP client and DHCP server must be on the same network, but this can be difficult. A company’s internal network is divided into multiple networks, e.g., for each department. If a DHCP server is prepared for each network, many DHCP servers will be needed and server management will become complicated. It is natural to want a single DHCP server to distribute TCP/IP configuration information to DHCP clients on multiple networks.

To distribute TCP/IP configuration information to DHCP clients on multiple networks with a single DHCP server, configure a DHCP pool for each network. The DHCP Relay Agent function is then used.

DHCP Relay Agent is a function that converts DHCP broadcast messages to unicast.The DHCP Relay Agent function is commonly used on routers; enable the DHCP Relay Agent function on the router on the network to which the DHCP client is connected.

With DHCP Relay Agent, DHCP server distributes TCP/IP configuration information to DHCP clients on different networks as follows.

  1. DHCP client broadcasts DHCPDISCOVER.
  2. When a router with DHCP Relay Agent enabled receives a DHCPDISCOVER broadcast message from a DHCP client, it converts the DHCP server IP address to a unicast as the destination IP address and forwards it. At this time, information on the IP address of the DHCP relay agent is also added.
  3. The DHCP server determines which DHCP pools to distribute to clients based on the IP address information in the DHCP Relay Agent. The DHCP server then returns DHCPOFFER from the appropriate DHCP pool to the router of the DHCP relay agent.
  4. The router converts the DHCPOFFER to a broadcast and forwards it.

Thereafter, DHCPREQUEST and DHCPACK are forwarded in the same manner.

Figure: DHCP Relay Agent
Figure: DHCP Relay Agent

Summary

Points

  • DHCP allows for automatic TCP/IP configuration, including IP addresses.
  • The four main DHCP messages are
    • DHCPDISCOVER
    • DHCPOFFER
    • DHCPREQUEST
    • DHCPACK
  • DHCP messages are exchanged on broadcast basis. Therefore, as principle, the DHCP server and DHCP client must be connected on the same network.