DHCP allows hosts to automatically & dynamically learn & update various aspects of their network configuration (IP address, subnet mask, default gateway, DNS server, etc.). While there’s nothing that DHCP does that can’t be done manually, the sheer volume of configurations that would need to be made on each node of even modestly sized networks makes DHCP essential in modern networking. Particularly in the consumer space, DHCP is the primary force that allows people’s internet connections to ‘just work.‘
DHCP is typically used for client devices (phones, workstations, etc.) and less so for network infrastructure (routers, dedicated servers, etc.).
In smaller networks (home networks) the router typically acts as the DHCP server. In larger networks the DHCP server is likely a more robust Linux or Windows server.
DHCP Messages
DHCP uses various messages to communicate between clients and servers. You don’t need to know very many for the CCNA, but some of the common ones are explained in the below sections. Here is a list of the most noteworthy with a brief description:
Messages sent by DHCP Servers
- OFFER — Offers an IP address to a client
- ACK — Acknowledges a client’s acceptance of an offered address (acknowledges REQUEST)
- NAK — Opposite of ACK, declines a client’s REQUEST
Messages sent by DHCP Clients
- DISCOVER — Used by clients to find local DHCP servers
- REQUEST — Requests use of an offered IP address
- RELEASE — Tells the server that the client no longer needs its IP address
- DECLINE — Tells the server it will not use the offered IP address
Note
Remember that
- DHCP Servers use port UDP 67
- DHCP Clients use port UDP 68
Requesting an IP Address
Addresses are ‘leased’ — they are given to a host for a limited amount of time. This helps conserve the pool of available addresses on the network, which is especially useful in large, publicly accessible networks.
Addresses are generally assigned automatically, but in the event you need to manually request (‘renew’) a DHCP address there are commands to do so. See Verifying & Configuring IP Parameters On Clients.
The process for assigning an IP address to a DHCP client involves four steps:
- DHCP Discover
- A broadcast message from the client asking if there are any DHCP servers in the network
- DHCP Offer
- A broadcast or unicast message from server to the client offering an IP address that the client can use, and requesting confirmation
- DHCP Request
- A broadcast message from the client. Usually the offered IP is fine, and the client sends a message saying it would like to use it
- DHCP Ack
- A broadcast or unicast message from the server to the client. The server confirms that it has reserved the IP for that particular client
Step | Direction | Broad/Unicast |
---|---|---|
Discover | Client → Server | Broadcast |
Offer | Server → Client | Broadcast or Unicast |
Request | Client → Server | Broadcast |
Ack | Server → Client | Broadcast or Unicast |
The acronym DORA is used by some to help remember these steps. |
Releasing an IP Address
Clients can prematurely ‘release’ their assigned IP address before its lease is up. See Verifying & Configuring IP Parameters On Clients for info on specific platforms.
Release messages are Unicast from a client to the server.
DHCP Relay
You may choose to configure the routers in a network to act as the DHCP servers for their connected LANs, but this is tedious to set up. In large, enterprise networks it is common to use one centralized DHCP server for the entire network. Unfortunately, this means that the server won’t receive some or all of its client’s broadcast messages (broadcast messages are not forwarded out of their local subnet).
The solution is to configure routers to act as DHCP relay agents. A relay agent will forward client broadcast DHCP messages to the DHCP server as unicast messages.
The relay agent acts purely as a middle-man between the client and server. It does not make any decisions for the client or the server i.e. it does not accept an IP on behalf of the client, it only forwards the DHCP Offer along so the client can decide on its own as normal.
Strictly speaking, a DHCP client wouldn’t know if it was talking to its server through an agent or not. The server doesn’t explicitly know either, although you could probably intuit that based on the router’s source and destination IP address used for the DHCP messages.
DHCP Pools
Effectively a subnet block of addresses to be assigned to DHCP clients, and includes other info such as DNS server, default gateway, etc.
You should generally use a separate DHCP pool for each network the server is acting as DHCP server for.
Configuration
Cisco IOS
DHCP Server
(config)#ip dhcp excluded-address lower-limit-ip upper-limit-ip
- Specifies a range of addresses that won’t be leased to DHCP clients.
(config)#ip dhcp pool pool-name
- Create a DHCP pool, and enters DHCP Config mode.
(dhcp-config)#network ip-address [/prefix-length | netmask]
- Specify the subnet of addresses to be assigned to clients in the current pool. Will not assign addresses specified in the
excluded-address
command.
- Specify the subnet of addresses to be assigned to clients in the current pool. Will not assign addresses specified in the
(dhcp-config)#dns-server ip-address
- Specify the DNS server that DHCP clients should use.
(dhcp-config)#domain-name domain-name
- Specify the domain name of the network. (i.e. PC1 = pc1.bri.gg)
(dhcp-config)#default-router ip-address
- Specify the default gateway for DHCP clients. If you’re configuring this on a router (which is likely if you’re using Cisco IOS commands!) then this will probably be the router’s own address.
(dhcp-config)#lease [days hours minutes] | infinite
- Specify the lease time, or set it to unlimited (not recommended).
DHCP Relay Agent
A single command is needed, though note that it must be run from interface config mode of the interface connected to the subnet of DHCP client devices.
(config-if)#ip helper-address dhcp-server-ip-addr
- Configures the IP address of the DHCP server to forward DHCP messages to. Also enables the router as a DHCP relay agent. The router must actually have a route to the DHCP server.
DHCP Client
It is possible, though uncommon, to use DHCP to configure the interfaces of a router. Here’s how:
(config-if)#ip address dhcp
- Note this is run from interface config mode. The selected interface will automatically get an address using DHCP.