A tutorial describing how to configure a Cisco router as a DHCP server, I’ll cover DHCP reservation and excluding of IP addresses as well. A DHCP server dynamically assigns IP addresses to hosts in a network, by creating DHCP reservations we can statically assign an IP address to a host based on its MAC address. IP address exclusion prevents conflicts among devices i certain hosts are manually assigned IP addresses. When configuring DHCP reservation it should be done differently for Windows DHCP clients and Linux DHCP clients because both of them make DHCP requests differently.
Configure a DHCP Pool on Cisco
On a Cisco router use the following commands to create a pool of IP addresses with a default gateway, DNS server and lease time.
R1>enable R1#configure terminal R1(config)#ip dhcp pool mynetwork1 R1(dhcp-config)#network 192.168.0.0 255.255.255.0 R1(dhcp-config)#default-router 192.168.0.1 R1(dhcp-config)#dns-server 22.214.171.124 126.96.36.199 R1(dhcp-config)#lease 4 6 30
The name of the pool is mynetwork1 which can be anything and it contains addresses from 192.168.0.1 to 192.168.0.254, the default gateway will be 192.168.0.1, DNS servers are 188.8.131.52 and 184.108.40.206 you can add more IP addresses by dividing them with spaces. Finally the lease time specifies how long the IP addresses will be valid before the client need to get them renewed. Here it is 4 days, 6 hours and 30 minutes.
DHCP IP address exclusion
Certain IP addresses like the IP address of the default gateway router and the DHCP server itself are assigned manually, since the DHCP pool covers the entire subnet containing the manually assigned IP address conflicts might occur. The following command excludes only one IP address
R1(config)#ip dhcp excluded-address 192.168.0.1
To exclude a range of IP addresses use the following command
R1(config)#ip dhcp excluded-address 192.168.0.1 192.168.0.5
Configure DHCP reservation
DHCP reservations are configured based on MAC addresses, an IP is statically assigned to a host with the specified MAC address. As said earlier DHCP reservations should be configured differently based on the DHCP client’s (the host TO which the IP will be assigned) Operating System.
DHCP reservation for Windows Clients
Follow these commands if you’re configuring a reservation for a windows host.
R1(config)#ip dhcp pool iisserver1 R1(dhcp-config)#client-identifier 0108.0027.d4e0.72 R1(dhcp-config)#host 192.168.0.20 255.255.255.0
You need to create a separate pool for each DHCP reservation. The client-identifier is the MAC address of the host added with 01 at the beginning, so in this example the MAC address of the host is 080027d4e072 adding 01 at the beginning gives 01080027d4e072, divide four characters by a dot 0108.0027.d4e0.72
DHCP reservation for Linux Clients
The process is easy for statically assigning IP addresses to Linux hosts. Follow the commands below
R1(config)#ip dhcp pool apachesever1 R1(dhcp-config)#hardware-address 0800.270a.fe5d R1(dhcp-config)#host 192.168.0.30 255.255.255.0
the hardware-address is the MAC address of the Linux host, just enter it as it is. Create a pool for each DHCP reservation.
Useful Cisco DHCP commands
For displaying the IP addresses assigned to hosts use
R1#show ip dhcp binding
Display IP conflicts in the network
R1#show ip dhcp conflict
Display DHCP events as they occur
R1#debug ip dhcp server events
Turn off debugging
R1#undebug ip dhcp server events
Set an interval for cleaning up expired DHCP bindings
R1(config)#ip dhcp binding cleanup interval <10-600 seconds>
Manually clear a binding
R1#clear ip dhcp binding <ip address>