How To Configure DHCP Server On Cisco Switches
How To Configure DHCP Server On Cisco Switches
Switches
This tutorial explains how to configure the DHCP service on a Cisco switch through a
packet tracer example. Learn how to use a Cisco switch to act as the DHCP server.
The DHCP service allows hosts to automatically obtain their IP configuration from
the DHCP server. The DHCP service is available on Cisco switches. This means, if
you have a Cisco switch in your network, you can also use it as a DHCP server.
The following table lists the commands that are required to configure a switch to act
as a DHCP server.
Switch(config)#ip dhcp pool [pool name] To create a DHCP pool and enter
DHCP pool configuration mode.
This tutorial is the fourth part of the article 'DHCP (Dynamic Host Configuration
Protocol) basic concepts, configurations, functions, and options
Explained'. Other parts of this tutorial are the following.
Objective
Configure the switch to act as the DHCP server.
Configuring DHCP service on the switch
Access the command prompt of the switch and run the following commands.
Switch>enable
Switch#configure terminal
Switch(config)#ip dhcp excluded-address 192.168.1.1
192.168.1.10
Switch(config)#ip dhcp pool test
Switch(dhcp-config)#network 192.168.1.0 255.255.255.0
Switch(dhcp-config)#default-router 192.168.1.1
Switch(dhcp-config)#dns-server 4.4.4.4
Switch(dhcp-config)#exit
Switch(config)#interface vlan 1
Switch(config-if)#ip address 192.168.1.5 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#exit
Switch#
The following image shows how to execute the above commands on the switch.
Let's understand the above configuration.
First, we created a range of reserved IP addresses (192.168.1.1 - 192.168.1.10). We
use reserved addresses for the resources that need a static IP configuration such as
routers, servers, and printers, etc.
After this, we created the pool named test and defined a range of all available IP
addresses (192.168.1.0 255.255.255.0). This IP range also includes the reserved IP
addresses that we excluded in the first step.
When the DHCP server provides IP addresses, it automatically excludes the
reserved IP addresses from all available IP addresses.
Then, we set the default gateway and DNS server IP addresses.
Finally, we assigned an IP address from the reserved IP address to the Vlan 1 and
enabled the Vlan 1.
DHCP uses the source IP address to determine the pool from which it should offer
the IP address. Since a DHCP client does not have an IP address, DHCP uses the
client's Vlan IP address to determine the IP pool for it.
The client's Vlan is the Vlan that is configured on the switch port that is connected to
the client. For example, if a client is connected to the port F0/5 and Vlan 10 is
configured on the port F0/5, then the client's vlan will be Vlan 10.
By default, all switch ports belong to VLAN 1. This means, unless you create or
configure additional VLANs, DHCP will use VLAN1's IP address to determine the
pool.
Since we assigned an IP address to VLAN 1 from our configured pool and did not
create any additional VLAN, DHCP will use our pool to assign IP addresses to all
clients.
VLAN is a switch management feature. It allows us to manage switch remotely,
categorize connected hosts, and do a lot of extra stuff. To learn more about the
VLAN, you can check the following tutorial.
You can also use the 'ipconfig' command to view the IP address. To use the
'ipconfig' command, select the command prompt of the device and run this
command.
The following image shows how to use this command.
Viewing leased addresses and DHCP statistics
To view IP addresses leased by the DHCP server, use the 'show ip dhcp binding'
command in privileged-execution mode.
The following image shows the output of this command.
To view DHCP pool statistics and information, use the 'show ip dhcp pool
[pool-name]' command. The following image shows the output of this command.
Configured packet tracer lab
The following download link provides the configured packet tracer lab of the example
used in this tutorial.
Configured packet tracer lab of the example
That's all for this part. In the next part of this tutorial, we will understand how to
configure and use multiple DHCP pools to support VLANs. If you like this tutorial,
please don’t forget to share it with friends through your favorite social network.