Configuring DHCP (Dynamic Host Configuration Protocol) on Cisco routers allows for the automatic assignment of IP addresses and network configurations to devices within a network. This guide covers how to set up a Cisco router as a DHCP server, configure it as a DHCP client, and use it as a DHCP relay agent.
## 1. Cisco Router as a DHCP Server
By configuring a Cisco router to act as a DHCP server, you enable it to dynamically assign IP addresses and other network settings to DHCP clients.
### Configuration Steps:
**a. Create a DHCP Pool**
Define a pool of IP addresses that the DHCP server can allocate to clients.
```shell
Router(config)# ip dhcp pool [pool_name]
```
**b. Define Network and Subnet**
Specify the network address and subnet mask for the DHCP pool.
```shell
Router(dhcp-config)# network [network_address] [subnet_mask]
```
**c. Set the Default Gateway**
Assign the default gateway, typically the router's own IP address.
```shell
Router(dhcp-config)# default-router [default_gateway_ip]
```
**d. Configure DNS Server**
Provide the IP address of one or more DNS servers.
```shell
Router(dhcp-config)# dns-server [dns_server_ip]
```
**e. Set Lease Time**
Determine how long an IP address is leased to a client.
```shell
Router(dhcp-config)# lease [days] [hours] [minutes]
```
**f. Exclude Specific IP Addresses**
Reserve certain IP addresses within the range that should not be assigned to clients (e.g., for servers or devices requiring static IPs).
```shell
Router(config)# ip dhcp excluded-address [start_ip] [end_ip]
```
**g. Verification**
- To verify IP address assignments:
```shell
Router# show ip dhcp binding
```
- To view the DHCP configuration:
```shell
Router# show running-config | section dhcp
```
## 2. Cisco Router as a DHCP Client
Configuring a Cisco router as a DHCP client is useful when the router needs to obtain its IP address automatically, such as when connecting to an ISP.
### Configuration Steps:
**a. Interface Configuration**
Enter the configuration mode for the interface that will receive the DHCP-assigned IP address.
```shell
Router(config)# interface [interface_name]
```
**b. Enable DHCP on the Interface**
Set the interface to acquire its IP address via DHCP.
```shell
Router(config-if)# ip address dhcp
```
**c. Activate the Interface**
Ensure the interface is active and capable of sending and receiving data.
```shell
Router(config-if)# no shutdown
```
**d. Verification**
- To check the IP address assigned to the interface:
```shell
Router# show ip interface brief
```
- To view detailed DHCP lease information:
```shell
Router# show dhcp lease
```
## 3. Cisco Router as a DHCP Relay Agent
When clients are on a different subnet than the DHCP server, the router can act as a DHCP Relay Agent to forward requests.
### Configuration Steps:
**a. Identify the Interface Connected to Clients**
Access the interface configuration mode for the interface connected to the client network.
```shell
Router(config)# interface [interface_name]
```
**b. Configure the Relay Agent**
Set the router to forward DHCP requests to the DHCP server's IP address.
```shell
Router(config-if)# ip helper-address [dhcp_server_ip]
```
**c. Optional: Modify IP Helper Functions**
By default, `ip helper-address` forwards several types of broadcasts. To prevent forwarding unnecessary protocols:
```shell
Router(config)# no ip forward-protocol udp [port_number]
```
**d. Verification**
- To confirm the helper address is set:
```shell
Router# show ip interface [interface_name]
```
- To troubleshoot DHCP relay activity:
```shell
Router# debug ip dhcp server events
```
## Conclusion
By configuring DHCP on Cisco routers, you streamline network management and reduce the potential for configuration errors. Whether acting as a DHCP server, client, or relay agent, the router can efficiently handle IP address assignments, making network administration more straightforward.