How to Configure a Basic DHCPv4 Server
A Cisco router can be configured as a DHCPv4 server. The DHCPv4 server assigns and manages IPv4 addresses from specified address pools within the router to DHCPv4 clients. The steps for configuring the DHCPv4 server on Cisco routers are the following:
Excluding IPv4 Addresses
The router configured as the DHCPv4 server assigns all IPv4 addresses in an address pool unless configured to exclude specific addresses. Typically, some IPv4 addresses in a pool are assigned to network devices manually. So, these addresses should be excluded from being assigned by the DHCPv4 server. Use the following command to exclude particular addresses from being assigned by DHCPv4.
ip dhcp excluded-address <FIRST_IP LAST_IP>
We can exclude a single address or a range of addresses using the first and last addresses of the range. The addresses assigned to the router, including the servers, printers, and other devices that have been manually configured, must be excluded.
Creating a DHCPv4 Pool
After Excluding IP addresses, create and define an IPv4 address pool to assign. The command for creating a DHCPv4 pool is ip dhcp pool <pool-name>. Create a pool with a meaningful name. The ip dhcp pool will also put the router into configuration mode. The prompt of the DHCPv4 mode is Router(dhcp-config)#.
Configuring other network Parameters
We configure several parameters after creating a DHCPv4 pool and entering it into DHCPv4 mode. Some of these parameters are optional, while others must be configured. The address pool and default gateway router must be configured. The DNS server, domain name, DHCP lease duration, and NetBIOS Wins server configuration are optional. The command for these parameters is the following:
Router(dhcp-config)# network <netwowrk address>
This command will attach the IP address pool to the DHCPv4 pool created earlier. The next compulsory command is defaulter-router. The command syntax is the following:
Router(dhcp-config)# default-router <Interface address>
Using the above command, we configure the network’s default router or gateway. Typically, the gateway is the LAN interface of the router closest to the client devices. One gateway is usually required for a network, but we can also configure multiple gateways.
The DNS server, domain name, DHCP lease duration, and NetBIOS Wins server configuration are optional for DHCPv4. The commands for these optional parameters are the following:
Router(dhcp-config)#dns-server <dns-ip-address>
Router(dhcp-config)#domain-name <name>
Router(dhcp-config)#domain-name <name>
Router(dhcp-config)#lease {days [hours] [minutes]| infinite]}
Router(dhcp-config)#netbios-name-server [server-ip-address]
DHCPv4 Example
The figure below shows a sample configuration with basic DHCPv4 parameters configured on router Router0, a DHCPv4 server for the 192.168.1.0/24 LAN.
The DHCPv4 service is, by default, enabled on most Cisco IOS. If someone needs to disable the DHCP service, use the “no service dhcp” command in global configuration mode. To re-enable the service, use the “service dhcp” command in global configuration mode.
Verifying DHCPv4
In the above example, we have configured the DHCPv4 server on Router0 to provide DHCPv4 services to the corresponding LAN. We can verify the DHCPv4 configuration using different commands.
We can use the show running-config command to display the DHCPv4 configuration. We can also use the | pipe to display only the parameter associated with the DHCPv4 configuration; for example, show running-config | begin dhcp. The figure below illustrates the output of this command.
We can verify the DHCP operation using the show ip dhcp binding command. The output of this command is shown in the figure below. It displays a list of all IPv4 addresses to MAC address bindings provided by the DHCPv4 service.
Another command for DHCP operation verification is show ip dhcp server statistics. This command verifies that messages are being received or sent by the router. This command also shows the counter about the number of DHCPv4 messages that have been sent and received.
We can also use the command show ip dhcp pool <pool-name>. The figure below illustrates the output of this command.
We can also verify the DHCPv4 process from the computer running and connected to the DHCPv4 server. As shown in the Figure below, using the ipconfig /all command, we can verify the computer’s IP address information. If an IP address is issued on the computer, it will display the TCP/IP parameters.
In the figure, you can see the output of the ipconfig /all command. The computer-issued IP address is 192.168.1.11, and the DHCP server address is 192.168.1.1. It automatically received an IPv4 address, subnet mask, default gateway, and DNS server address from that pool.