Files
ilnmors-homelab/docs/theories/network/dhcp.md
2026-03-15 04:41:02 +09:00

3.1 KiB

DHCP (Dynamic Host Configuration Protocol)

Before DHCP emerged, every client had to set their own static IP or using RARP(Reverse Address Resolution Protocol). They have critical problems.

  • Static IP

    • Each host has their own IP regardless they run or not. It cause lack of IP address.
    • If administrator made configuration mistake, the network itself could stop. For instance, IP conflict, or subnet configuration error, etc.
  • RARP

    • RARP works on L2, it makes hard to implement on hardware.
    • RARP server had to exist on every subnet(L2), it was inefficient.

To solve this problem, BOOTP was developed and it evolved as DHCP. DHCP works on L3, and like its name they lease IP dynamically. It allocates IP to hosts with 3 steps. Lease, renewal, and release.

Lease

When DHCP server gets request from host to allocate IP, DHCP server choose one IP address from its subnet pool, and it responds IP/subnet and information to the hosts. It follows the process called DORA.

  • DHCP Discover

The host which has no IP address broadcast discover packet including its MAC to local network. Only DHCP server responds this packet, the others discard the packets.

  • DHCP Offer

When DHCP server gets discover packet, DHCP server broadcast Offer packet including host's MAC of which sends discovery packet. Only host which sends discovery packet, the others discard the packets.

  • DHCP Request

When the host gets offer packet, it consider the network has DHCP server and broadcast request packet to the local network. More than one DHCP server can exist in one network, therefore host broadcast request packet.

  • DHCP ACK

When DHCP server gets the Request packet, it searches for an IP address which can be allocated in its pool. When DHCP server finds an available IP address, it sends to ACK packet including IP address and subnet, and optional information(DNS, gateway, etc...) with reservation time.

Renewal

The host allocated IP from DHCP try to renew its IP before it expires. There are two chances to renew reservation time. The first try to renew is when the reservation time remains half of them; T1. In this time, host uses unicast. If the first try failed, then it try one more time when 87.5% of the lease time has passed; T2. In this time, the host uses broadcast. All try fails, client gives up the leased IP and try the lease process again. DHCP server release the IP address from the host.

  • DHCP Request

The host sends request packet to DHCP server as unicast.

  • DHCP ACK

When DHCP server gets the request, it sends ACK packet to the host as unicast.

Release

When the host doesn't use IP address anymore, DHCP server makes IP as available IP in its pool. Especially, client can send DHCPRELEASE to DHCP server explicitly when it doesn't need IP address.

DHCP relay

Commonly, DHCP is located in router. Because router is the center of networks, and it takes charge of number of networks. However, DHCP server doesn't have to be located in router because of existence of DHCP relay. When router gets DHCP packets (DORA), router can relay the packets as unicast between host and DHCP server which are in different subnet.