Table of Contents Link to heading
- Dynamic Host Configuration Protocol (DHCP)
- DHCP Operation
- Automatic Private IP Addressing (APIP)
- Cisco IOS Commands
- DHCP Relay Agent
- Router As A DHCP Client
- DHCP Starvation
Dynamic Host Configuration Protocol (DHCP) Link to heading
DHCP provides the following advantages:
- It reduces the amount of configuration on devices.
- It reduces the likelihood of configuration errors on devices acquiring address information.
- It gives you more administrative control by centralizing IP addressing information and management.
- An address is not permanently assigned to a host but is only “leased” for a
period of time.
- If the host is powered down or taken off the network, the address is returned to the pool for reuse.
- This feature is especially helpful for mobile users who come and go on a network.
Since DHCP clients do not accept incoming connections, it does not matter if their IP address changes.
Server, routers, and switches, if being mission critical devices, must be statically assigned IP addresses to ensure that they will not change and are not dependant on DHCP.
DHCP Operation Link to heading
The configuration of the DHCP server requires that a block of addresses, called an address pool, be defined to be assigned to the DHCP clients on a network.
When acquiring addressing information, a DHCP client goes through four steps:
- A client generates a DHCPDISCOVER local broadcast to discover who the
DHCP servers are on the LAN segment.
- Source is 0.0.0.0
- Destination 255.255.255.255
- All DHCP servers on the segment can respond to the client with a
DHCPOFFER unicast message, which offers IP addressing information to the
client. If a client receives messages from multiple servers, it chooses one
(typically the first one). DHCPOFFER server messages include the following
information:
- IP address of the client,
- Subnet mask of the segment,
- IP address of the default gateway,
- DNS domain name,
- DNS server address(es),
- WINS server address or addresses,
- TFTP server address or addresses,
- Duration of the lease,
- and more
- There are two scenarios after DHCPOFFER:
- Upon choosing one of the offers, the client responds to the corresponding server with a DHCPREQUEST broadcast message, informing the server(s) the addressing information it chooses.
- If only one server is available and the client determines that the only offered configuration is invalid (for example, due to a duplicate IP address or there are not enough available IP addresses in the DHCP scope to support the client volume), it sends a DHCPDECLINE packet back to the server and restarts the DHCP lease process.
- There are two scenarios after DHCPREQUEST:
- The DHCP server responds with a DHCPACK, which is an acknowledgement to the client indicating that it received the DHCPREQUEST message and that the client accepted the addressing information.
- The DHCP server responds with a DHCPNACK, which tells the client the offer is no longer valid and the client should request addressing information again. This can happen if the client is tardy in responding with a DHCPREQUEST message after the server generated the DHCPOFFER message.
When a client shuts down gracefully, it can generate a DHCPRELEASE message, telling the server it no longer needs its assigned IP address. Most DHCP configurations involve a lease time, which specifies a time period that the client is allowed to use the address. Upon reaching this time limit, the client must renew its lease with the current server or get new IP addressing information.
Automatic Private IP Addressing (APIP) Link to heading
However, only Microsoft Windows operating systems perform APIP; other operating systems, such as Linux, will not enable the NIC if they can’t obtain IP addressing for the NIC.
Cisco IOS Commands Link to heading
Configuration Link to heading
To configure a Cisco device as a DHCP server, you need to do the following steps:
- Define a DHCP address pool with the ip dhcp pool command, and specify the network address, subnet mask, default gateway, DNS server, and other options for the pool.
- Exclude any addresses that you want to reserve for static assignment, such as the default gateway, with the ip dhcp excluded-address command.
- Optionally, configure any DHCP options that you want to provide to the clients, such as the TFTP server address for VoIP phones (option 150).
For example, to configure a DHCP pool for network VLAN10 (192.168.10.0/24), with the default gateway 192.168.10.1 and the DNS server 192.168.2.10:
Router(config)# ip dhcp excluded-address 192.168.10.1 192.168.10.10
Router(config)# ip dhcp pool VLAN10
Router(dhcp-config)# network 192.168.10.0 255.255.255.0
Router(dhcp-config)# default-router 192.168.10.1
Router(dhcp-config)# dns-server 192.168.2.10
Router(dhcp-config)# domain-name vlan10.example.com
Verification Link to heading
You can verify the DHCP server configuration with the show ip dhcp binding command, which displays the mappings between IP addresses given out via the DHCP server and the client’s MAC addresses, and the show ip dhcp server statistics command, which displays the number of DHCP messages received and sent by the server.
DHCP Relay Agent Link to heading
This is useful when the DHCP server is not on the same subnet as the clients.
When a client device on a network segment requests an IP address through DHCP, it sends out a broadcast packet. Since DHCP only works on the LAN to which it is connected, it cannot cross a router. To remedy this situation, DHCP relay was created. It gives DHCP an option so that a router intercepts the DHCP client’s broadcast request, creates a unicast request to the DHCP server on a different LAN, and the DHCP server can give a unicast response to the router based on the DHCP option, that then passes on the DHCP response to the requesting DHCP client.
The configured interface is the one connecting to the LAN without a DHCP server.
Router(config)# interface interface_#
Router(config-if)# ip helper-address external_DHCP_server_IP_#
Router As A DHCP Client Link to heading
Cisco routers are typically manually configured with static IP addresses.
The office still requires a public IP address to allow internal hosts outbound connectivity to the Internet through NAT.
In this case, the router will receive the public IP address on its outside interface from the ISP via DHCP.
The configured interface is the one facing the ISP:
Router(config)# interface interface_#
Router(config-if)# ip address dhcp
Router(config-if)# no shutdown