Configuring a Cisco router or switch as a DHCP server

Rate this post



Dynamic Host Configuration Protocol (DHCP) is a client/server protocol which allows you to allocate network configuration parameters like IP addresses, subnet masks, DNS servers, default gateways and many more to end devices. This protocol uses the UDP ports 67 and 68 as defined in RFC 2131. Nowadays allmost network devices support DHCP including workstations, printers, IP phones, handheld devices etc. Using dynamic IP address assigment you can minimize errors which can appear on manual configuration and also reduce the administrative overhead. Cisco embedded the DHCP server functionality beginning with IOS Version 12.0(1)T. By default, the Cisco IOS DHCP server and relay agent features are enabled but are not configured.

Basic configuration

In this setup I will use a Cisco vIOS router image with IOS version 15.6. If by some means the DHCP feature is disabled on your router or switch you can re-enable it by running the following command in global configuration mode:

R1(config)#service dhcp

If the device has a default configuration you must assign an IP address to the router or switch interface where DHCP messages will be sent. In my case I will configure the FastEthernet 0/0 interface with the following IP and subnet mask and then bring up the interface:

R1(config)#interface fastethenet 0/0
R1(config-if)#ip address
R1(config)#no shutdown

Then you must define a pool for the DHCP address allocation using the following command:

R1(config)#ip dhcp pool cioby

Here I have set the pool name to “cioby” but you can use whatever name you want. After running this command you are place in dhcp pool configuration mode denoted by the R1(dhcp-config)# prompt. Now you must specify the range of IP addresses which will be assigned by the server to the clients. Use the following command in dhcp pool configuration mode:


Here using the ‘network’¬†statement I have allocated a range of 254 addresses. The subnet mask can be specified also by using a CIDR notation ‘/24′¬†which is equivalent to Now that the pool of addresses have been defined you must configure some addtional parameters which can be sent to the client, like the default gateway, the DNS servers, the domain name etc.

To define the default gateway for a DHCP client use the following command in dhcp pool configuration mode:


The IP address of the default gateway should be in the same subnet as the clients. You can specify up to 8 addresses but it’s recommnended to stick at only one. Next you need to provide the DNS servers which will be used by the DHCP client to resolve domain names. Use the following command:


Here I have defined 2 DNS servers a primary one and a secondary one for backup. If the client is part of a domain you need to instruct the DHCP server to pass this option also. For this use the following command:


If your network is composed mostly of Windows workstations you can configure a WINS server name to be passed to the clients. To specify the IP of the WINS server use the following command:


Then you should configure the lease time which represents the time a client will keep an IP address before renewing it. While in dhcp pool configuration mode type the following command:

R1(dhcp-config)#lease 0 12

Here I have specified a lease time of 12 hours. The lease command has the following format ‘days [hours] [minutes]‘ with hours and minutes being optional. The default value for the lease is 1 day (24h). You can also use the ‘infinite‘ keyword along with the lease command to specify infinite lease periods. Finally type ‘exit‘ to return to global configuration mode.

Next you must configure the IP addresses which must be excluded from the pool. In my case I will exclude the first 10 IP addresses from the subnet which will be used for static IP assignments. This exclusion is needed to avoid conflicts with devices that have a static IP in this subnet. To configure exclusion use the following command:

R1(config)#ip dhcp excluded-address

Finally type exit to return to privileged EXEC mode and type the following command to save the modifications to the startup config.

R1#copy running-config startup-config

Now you should have a fully functional DHCP server ready to hand out IP addresses to clients.

Configuring DHCP static IP address assignment

If your network configuration doesn’t change very often you can allocate the same IP address to a DHCP client for indefinite time. Cisco offers the DHCP reservation feature which allows you to manually bind an IP address to a MAC address and thus a device will always receive the same IP address. To configure a manual binding, you need to create a host pool first, then specify the IP address and hardware address of the client or client identifier. Use the following sequence of commands beginning in global configuration mode:

R1(config)#ip dhcp pool wks1
R1(dhcp-config)#client-identifier 0100.2C4E.F176.41
R1(dhcp-config)#client-name Server1

Here the ‘host‘ statetement specifies the IP address ( and subnet mask of the client ( The subnet mask can also be specified using a prefix length (/24). The client identifier is the unique identification of the client in hexadecimal and is composed from a MAC address and the media type. Here the MAC address is 002C.4EF1.7641 and the media type is 01 meaning Ethernet. Optionally you can specify a client name to be assigned to the device (Server1 in my case).

Note!: You must perform these steps and allocate a separate DHCP pool for each static client you want to configure.

Monitoring DHCP status

After the DHCP server is configured and running you can use a series of commands to display information about it. In order to display the IP address bindings and their lease expiration times, use the following command:

R1#show ip dhcp binding
IP address        Hardware address        Lease expiration        Type      0100.21cf.375a.2f       Apr 14 2011 05:20 PM    Automatic      0100.2c4e.f176.41       Infinite                Manual      0100.0ffe.221c.a4       Apr 14 2011 05:26 PM    Automatic

From this output, you can see that the second client has the lease expiration time set to ‘Infinite‘ and the type of binding is ‘Manual‘ which means the client has IP address statically assigned by the DHCP server. Sometimes during the allocation of IP addresses by the DHCP server, conflicts can appear between 2 clients. You can display these conflicts using the show ip dhcp conflict command in user EXEC or privileged EXEC mode:

R1#show ip dhcp conflict
IP address     Detection Method     Detection time   Ping                 Apr 15 2011 05:14 PM   Gratuitous ARP       Apr 17 2011 09:26 AM

If an address conflict is detected, the address is removed from the pool and the address is not assigned until an administrator resolves the conflict. You can display the statistics about a DHCP server using the show ip dhcp server statistics command:

R1#show ip dhcp server statistics

The output of this command will display a lot of information about the pools, memory usage, bindings, the messages sent and received. If you need to reset all counters to zero use the following command in privileged EXEC mode

R1#clear ip dhcp server statistics

Cisco also offers a very good command to troubleshoot DHCP issues. You can use the debug ip dhcp server packet command in privileged EXEC mode:

R1#debug ip dhcp server packet

This will turn on debugging for DHCP messages, and allows you to see the whole transaction between the client and the server for assigning an IP address.

Renewing and releasing IP addresses from a DHCP client

Now you must test the DHCP allocation from a client side. Assuming you have some workstations connected to the network which are set to obtain the IP dynamically you can open a command prompt and force an IP renewal. If you are using an Windows OS open the command prompt and type ipconfig /release to release the current IP and the ipconfig /renew to obtain a new IP address from the DHCP pool. In case of a Linux system you can simply run the following command:

Linux#dhclient eth0

This will force the client to obtain a new IP address for the first physical Ethernet interface. You can replace eth0 with the name of the interface you wish to assign a new IP address.


The Cisco DHCP server offers many more features like the possibility to relay DHCP requests to other subnets, storing the DHCP information on a remote database, and many other options which can be sent to clients. For more information please consult the online documentation

Leave a Reply

Your email address will not be published.