If your router or switch does not have any configuration on it, you can follow these steps for adding a basic configuration: 8 easy steps for basic Cisco switch configuration.
Table of Contents
Define the excluded IP addresses from the DHCP pool
Before starting to configure the DHCP server on your router, you need to think about how many IP addresses should be excluded from the pool. These IP addresses will be assigned as static IP addresses to different devices which require a static IP address. For example your router, switch or server.
On the router, you need to run a similar command. Please adjust the commands according to your environment.
R2#configure terminal Enter configuration commands, one per line. End with CNTL/Z. R2(config)#ip dhcp excluded-address 192.168.100.1 192.168.100.100 R2(config)#
Configure the DHCP pool
After identifying the static IP addresses which were excluded from the pool, you need to define a pool on the router. The DHCP clients will receive an IP address dynamically from this pool.
Add the following command on your router:
ip dhcp pool DHCPRouter # define a name according to your needs
Define the IP subnet
After creating the DHCP pool, you need to configure the subnet /network from which the IP addresses will be allocated to the clients.
Run a similar command on your router. Adjust it according to your environment.
R2(config)#ip dhcp pool DHCPRouter R2(dhcp-config)#network 192.168.100.0 255.255.255.0 R2(dhcp-config)#
Specify the default router used by your DHCP clients
Next, you need to specify the default router (gateway) which will be allocated to your DHCP clients.
Specify the DNS server used by your DHCP clients
If you also want to assign a DNS server dynamically to your DHCP clients, you need to add a similar command on your router.
Specify the domain name used by your DHCP clients
If your hosts are part of a domain and you want it added to your DCHP clients, you need to configure the domain name.
Configure the lease time
By default, the Cisco router allocates the IP address to your DHCP clients for 1 day. If you want to change the default lease time, you can change it with the lease command:
R2(config)#ip dhcp pool DHCPRouter R2(dhcp-config)#lease ? <0-365> Days infinite Infinite lease R2(dhcp-config)#lease 7 R2(dhcp-config)#
Save the config and test if the DHCP server is working properly
The last step you need to take is to save the running-config to startup-config and to test if the DHCP server is working as intended.
R2#copy running-config startup-config Destination filename [startup-config]? Building configuration... [OK] R2#
In my lab, I will use 2 clients – a Cisco switch and a Ubuntu laptop – in order to test if DHCP server is working properly.
I will start with the Cisco switch. The switch is connected to the Cisco router via an Ethernet cable. The switch interface is configured to acquire its IP address through the DHCP protocol.
SW1#show running-config interface fastEthernet 0/24 Building configuration... Current configuration : 66 bytes ! interface FastEthernet0/24 no switchport ip address dhcp end SW1#show ip int brief fastEthernet 0/24 Interface IP-Address OK? Method Status Protocol FastEthernet0/24 192.168.100.103 YES DHCP up up SW1#
For more details regarding your DHCP server and the IP address allocated to your switch run the below commands.
show dhcp server show dhcp lease
Lets see if the Ubuntu laptop received an IP address from the DHCP server running on the Cisco router.
It seems that the DHCP server is working properly and the clients are able to acquire the IP address via DHCP protocol.
If you want to check the statistics for your DHCP server, you need to run the below command:
R2#show ip dhcp server statistics Memory usage 57602 Address pools 1 Database agents 0 Automatic bindings 2 Manual bindings 0 Expired bindings 0 Malformed messages 0 Secure arp entries 0 Message Received BOOTREQUEST 0 DHCPDISCOVER 19 DHCPREQUEST 8 DHCPDECLINE 0 DHCPRELEASE 3 DHCPINFORM 0 Message Sent BOOTREPLY 0 DHCPOFFER 6 DHCPACK 6 DHCPNAK 2 R2#
To find out how many clients are using IP addresses from your DHCP pool, run a similar command on your device.
R2#show ip dhcp binding Bindings from all pools not associated with VRF: IP address Client-ID/ Lease expiration Type Hardware address/ User name 192.168.100.101 01f8.b46a.ba31.38 Apr 02 2023 12:25 PM Automatic 192.168.100.103 0063.6973.636f.2d65. Mar 27 2023 12:12 PM Automatic 3862.612e.3730.3930. 2e61.3034.312d.4661. 302f.3234 R2#
I hope you find this post useful. Share it on your social media channels so that other people can read it too.