Home / Articles / Introduction to DHCP
Introduction to DHCP
Dynamic Host Configuration Protocol
DHCP (Dynamic Host Configuration Protocol) is a network management protocol used on Internet Protocol (IP) networks whereby a DHCP server dynamically assigns an IP address and other network configuration parameters to each device on a network so they can communicate with other IP networks.
DHCP automates and centrally manages these configurations rather than requiring network administrators to manually assign IP addresses to all network devices. DHCP can be implemented on networks ranging in size from home networks to large campus networks and regional Internet service provider networks.
IP Address Allocation
DHCP supports three mechanisms for IP address allocation:
-
Dynamic allocation — A network administrator assigns a range of IP addresses to DHCP, and each DHCP client on a LAN is configured to request an IP address from the DHCP server during network initialization. The request-and-grant process uses a lease concept with a controllable time period.
-
Automatic allocation — DHCP assigns a permanent IP address to a client (chosen from its pool of available addresses). This differs from dynamic allocation only in that the DHCP server tries to reassign the same address each time.
-
Static allocation (manual) — The DHCP server allocates an IP address based on a table of MAC address/IP address mappings. Only clients with a recognized MAC address will receive an IP address.
DHCP Message Structure
A DHCP message consists of the following fields:
| Field | Size | Description |
|---|---|---|
op |
1 byte | Message op code: 1=BOOTREQUEST, 2=BOOTREPLY |
htype |
1 byte | Hardware address type (1 = Ethernet) |
hlen |
1 byte | Hardware address length (6 for Ethernet MAC) |
hops |
1 byte | Client sets to 0; relay agents increment this |
xid |
4 bytes | Transaction ID — random number chosen by client |
secs |
2 bytes | Seconds elapsed since client started the process |
flags |
2 bytes | Broadcast flag and reserved bits |
ciaddr |
4 bytes | Client IP address (if already has one) |
yiaddr |
4 bytes | "Your" IP address — the address being offered |
siaddr |
4 bytes | Next server IP address |
giaddr |
4 bytes | Relay agent IP address |
chaddr |
16 bytes | Client hardware address (MAC address) |
sname |
64 bytes | Optional server hostname |
file |
128 bytes | Boot file name |
options |
variable | Optional parameters |
DHCP Options
The options field allows DHCP to carry additional configuration information. Options are encoded as type-length-value (TLV) triples. Common options include:
- Option 1 — Subnet mask
- Option 3 — Default gateway (router)
- Option 6 — DNS server addresses
- Option 12 — Hostname
- Option 15 — Domain name
- Option 51 — Lease time
- Option 53 — DHCP message type (Discover, Offer, Request, Ack, etc.)
- Option 54 — DHCP server identifier
- Option 255 — End of options
DHCP Message Flow (DORA)
The standard DHCP exchange is known as DORA:
-
DHCP Discover — The client broadcasts a
DHCPDISCOVERmessage on the network subnet using the destination address255.255.255.255to locate available DHCP servers. -
DHCP Offer — Each available DHCP server responds with a
DHCPOFFERmessage that includes an available network address and other configuration parameters. -
DHCP Request — The client broadcasts a
DHCPREQUESTmessage, telling all servers which offer it has accepted. All other servers know their offer was declined and can return the address to their pool. -
DHCP Acknowledge — The selected DHCP server sends a
DHCPACKto the client, including the lease duration and any other requested configuration. The client then performs final network configuration.
If the server cannot satisfy the request, it sends a DHCPNAK (negative acknowledgment) and the client must start over.
Leases and Bindings
A DHCP lease is the amount of time a DHCP server grants a client permission to use an IP address. When a lease expires, the client must renew it or stop using the address.
- T1 (renewal time) — At 50% of the lease time, the client attempts to renew directly with the DHCP server that granted the lease.
- T2 (rebinding time) — At 87.5% of the lease time, if renewal failed, the client broadcasts to any available DHCP server to try to rebind.
- Expiry — If rebinding fails, the client must stop using the address and start the DORA process again.
A DHCP binding is the association between an IP address and a MAC address that the server maintains in its database. For static allocation, bindings are created manually. For dynamic allocation, bindings are created and destroyed as leases are granted and expire.