DHCP
DHCP
Each device in an IP network requires a valid IP configuration. If the network size is small,
an administrator can manually provide an IP configuration to each device. But if the
network size is large, assigning and managing the IP configuration on each device can be a
challenging task.
DHCP gives us a much easier way to manage the network by automatically providing IP
configuration to hosts than to configure IP configuration on each host manually.
No matter whether you have a tiny network or a huge network, DHCP works well in all
sizes of networks. You can use DHCP in your home network or can use it in your office or
business network.
What is DHCP?
The Dynamic Host Configuration Protocol (DHCP) is a service. It allows devices to acquire
their IP configuration dynamically. It is defined in RFC 2131 and 2939. It works in the
server/client model. The server offers and delivers IP configurations. Clients request and
acquire their IP configurations.
Static allocation
In this method, the administrator configures an allocation table on the DHCP server. In this
table, the administrator fills the MAC addresses of all clients and assigns an IP
configuration to each client.
The DHCP server uses the allocation table to provide IP configurations. When a client
requests an IP configuration, the DHCP server checks the table and finds a match. If the
DHCP server finds a match, the DHCP server offers the IP configuration that is associated
with the MAC address of the client in the match.
Dynamic allocation
In this method, the administrator configures a range of IP addresses on the DHCP server.
The DHCP server assigns an IP configuration from the configured range to each client that
requests an IP configuration.
In this method, the DHCP offers the IP configuration only for a specific time. This specific
time is known as the lease. The IP configuration remains valid until the lease duration is
over. Once the lease duration is over, the client is required to obtain a new IP
configuration from the server.
Automatic allocation
Same as the dynamic method, in this method, the administrator also configures a range of
IP addresses on the DHCP server and the DHCP server assigns an IP configuration from the
configured range to each client that requests an IP configuration.
Unlike the dynamic method, in this method, the DHCP server assigns the IP configuration
permanently. To assigns an IP configuration permanently, the DHCP server sets the lease
duration to infinite. As a result, once the DHCP server chooses an IP configuration from the
pool and assigns the IP configuration to a client, the IP configuration remains with that
same client indefinitely.
When a host (DHCP client) needs an IP configuration, it connects to a DHCP server and
requests for an IP configuration. A DHCP server contains several pre-configured IP
configurations. When it receives a DHCP request from a DHCP client, it provides an IP
configuration to the client from all available IP configurations.
This entire process goes through the four steps: Discover, Offer, Request, and
Acknowledgment. In this tutorial, we will understand these four steps in detail.
The following image shows all four steps of DHCP communication.
DHCP discovery
When we start a device, it checks whether a valid IP configuration is available or not. If the
valid IP configuration is not available, the device generates a special message known as
the DHCPDISCOVER message and broadcasts this message on the local LAN segment.
The 0.0.0.0 and 255.255.255.255 are two special addresses. Any device, whether it has a
valid IP configuration or not, can use these addresses to send local broadcast messages.
From these addresses, the 0.0.0.0 is used as the source address. If a device does not
have the source address, it can use this address to send broadcast
messages. 255.255.255.255 is the local broadcast address. Any message sent on this
address is received by all hosts of the local network.
DHCP offer
Since the client sends the DHCPDISCOVER message to the local broadcast address, if a
DHCP server is configured on the local network, it will also receive the message. If
multiple DHCP servers are configured on the local network, they all will receive
the DHCPDISCOVER message.
If multiple DHCP servers are available, based on their configuration, one of them or all of
them can reply to the DHCPDISCOVER message. In reply to
the DHCPDISCOVER message, a DHCP server sends a DHCPOFFER message to the client.
Since the client does not have an IP address, the DHCP server cannot send
the DHCPOFFER message directly to the client. Because of this, the server sets the
destination address to 255.255.255.255. In other words, the server also broadcasts
the DHCPOFFER message to the local network.
Apart from these, the DHCPOFFER message also contains other protocol-specific
information such as the lease duration and client ID. This information is required by the
core functions of DHCP.
DHCP request
All hosts in the local network receive the DHCPOFFER message. The host that sent
the DHCPDISCOVER message accepts the DHCPOFFER message. Except the original
host, all other hosts ignore the DHCPOFFER.
How does a host know whether the broadcasted DHCPOFFER message is for it or not?
The DHCPDISCOVER message contains the host's MAC address. When a DHCP server
broadcasts a DHCPOFFER message, it also includes the host's MAC address in a
parameter known as the client ID. When hosts receive the DHCPOFFER message, they
check the client ID field in the message. If a host sees its MAC address in the client ID field,
the host knows that the message is meant for it. If a host sees the MAC address of another
host in the client ID field, the host knows that the message is not intended for it.
If only one DHCP server is available and the provided IP configuration conflicts with the
client’s configuration, the client can respond with a DHCPDECLINE message. In this
situation, the DHCP server offers another IP configuration.
When DHCP servers receive the DHCPREQUEST message, besides the server whose
offer has been accepted, all other servers withdraw any offers that they might have made
to the client and return the offered address to the pool of available addresses.
The DHCPREQUEST message contains a Transaction ID field. Just like hosts use the client
ID field of the DHCPOFFER message to know whether the message is intended for them
or not, DHCP servers use the Transaction ID field of the DHCPREQUEST message to
know whether their offer has been accepted or not.
DHCP acknowledgment
When the DHCP server receives a DHCPREQUEST message from the client, the
configuration process enters its final stage. In this stage, the server sends
a DHCPACK message to the client.
The DHCPACK message is an acknowledgment to the client indicating that the DHCP
server has received the DHCPREQUEST message of the client, and the client can use the
offered IP configuration.
In some cases, the server may also respond with a DHCPNACK message.
The DHCPNACK message tells the client that the offer is no longer valid and the client
needs to request an IP configuration again. Typically, this occurs when the client takes
too long to respond with a DHCPREQUEST message after receiving
a DHCOFFER message from the server. In such a case, the client can make a new
request for another IP configuration.
Discover The DHCP client broadcasts this message to find a DHCP server.
Offer The DHCP server broadcasts this message to lease an IP configuration
to the DHCP client.
Request The DHCP client uses this message to notify the DHCP server
whether it accepts the proposed IP configuration or not.
Acknowledgmen The DHCP server uses this message to confirm the DHCP client that
t it can use the offered IP configuration.
DHCP Configuration Parameters and Settings
Explained
This tutorial explains the Cisco specific DHCP configuration parameters and settings in
detail. Learn the configuration parameters and settings that you need to configure a Cisco
device (router or switch) to act as the DHCP server.
To configure a Cisco router or switch as a DHCP server, we have to create and configure a
DHCP pool on it. A DHCP pool is a collection of IP configurations that we want to assign to
DHCP clients. Each IP configuration contains a unique IP address and a few common
network settings and addresses such as the default gateway IP, DNS servers' IP addresses,
and TFTP server's IP addresses.
This is a range of IP addresses that we want to assign to clients. In each range, the first
address and the last address have special meanings. The first address is known as
the network ID (or address). The last address is known as the local broadcast ID (or
address).
DHCP clients use the network address and broadcast address to request an IP
configuration from DHCP servers, while the DHCP servers use the same addresses to offer
the IP configuration to the DHCP clients. To learn how this process work in detail, please
check the second part of this article.
To define a range, we use the network ID and the subnet mask. For example, to define a
range of IP addresses from 192.168.1.0 to 192.168.1.255, we would set the network ID to
192.168.1.0 and the subnet mask to 255.255.255.0.
The network ID 192.168.1.0 and the subnet mask 255.255.255.0 represent a range of IP
addresses from 192.168.1.0 to 192.168.1.255. In this range, the network
address is 192.168.1.0 and the local broadcast address is 192.168.1.255.
DHCP servers do not lease the network ID and broadcast ID. Except the network ID and
broadcast ID, all addresses of the defined IP range can be leased to clients.
Reserved/excluded addresses
If you don't want to assign a few addresses from the range, you can configure them
as excluded addresses. DHCP servers do not assign the excluded addresses. This feature
allows us to configure static IP addresses on critical network resources such as servers,
printers, and routers.
The default gateway IP address
If a local host wants to send a data packet to a host that is not available in the local
network, it sends the data packet to the default gateway. This option allows us to set a
default gateway IP address for hosts. Typically, this is the IP address of the router's
interface that is directly connected to the local network.
DNS servers allow hosts to access network resources by using their names instead of their
IP addresses. If a DNS server is configured, you can set its IP address in this option. If you
have more than one DNS server, you can configure all of them on hosts through this
option.
A TFTP server allows hosts to download or store files. If a TFTP server is available in the
network, you can use this option to provide the IP address of the TFTP server to all hosts.
Lease duration
The lease duration defines the validity of the IP configuration. A DHCP client can use the
assigned IP configuration until its validity expires. Once the validity period is expired, the
client needs to obtain a new IP configuration from the server. By default, an IP
configuration remains valid for 24 hours. Depending on your requirement, you can
increase or decrease it.
The following image shows how multiple IP configurations are stored in a DHCP pool.
DHCP pool configuration mode
Cisco routers and switches include a special configuration mode known as DHCP pool
configuration mode. DHCP pool configuration mode allows us to create and configure
DHCP pools. Except the command that defines the list of excluded or reserved addresses,
all commands that are required to configure the DHCP server run in DHCP pool
configuration mode.
To configure a DHCP server on a Cisco router or switch, use the following configuration
steps.
● Create a list of addresses that you want to exclude or reserve. For this, use the
command 'ip dhcp excluded-address [first-address last-address]' in global
configuration mode.
● Create your DHCP pool using a unique name. To create a DHCP pool and to navigate to
DHCP pool configuration mode, use the command 'ip dhcp pool [name]' in global
configuration mode.
● Define the range of IP addresses that the DHCP server should provide to clients. Use
the 'network [subnet-ID mask] or network [subnet-ID prefix-length]' command in
DHCP pool configuration mode to define the range of IP addresses.
● Add the default gateway IP address. Use the 'default-router [ip-address]' command in
DHCP pool configuration mode to define the default gateway IP address.
● Provide the DNS server addresses. Use the dns-server [address1
address2...] command in DHCP pool configuration mode to define the list of DNS server
IP addresses used by clients in this pool.
● If you don’t want to use the default lease duration of 24 hours, set the lease duration. Use
the lease [days hours minutes] command in DHCP pool configuration mode to define
the length of the lease, in days, hours, and minutes.
● If you have a TFTP server in your network, set the IP address of it. Use the next-server
[ip-address] command in DHCP pool configuration mode to define the TFTP server IP
address.
That's all for this part. In the next part of this tutorial, we will take a packet tracer example
to understand how to use or execute the above-explained commands to configure a Cisco
switch to act as a DHCP server. If you like this tutorial, please don't forget to share it with
friends through your favorite social channel.
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.
Either download the following pre-created practice lab or create a packet tracer lab to
replicate the network explained below.
In a small network, a Cisco switch and a generic wireless access point are used to provide
connectivity between hosts. Wired hosts are directly connected to the switch. Wireless
hosts are connected to the access point and the access point is connected to the switch.
Objective
Configure the switch to act as the DHCP server.
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.
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.
To configure the host as a DHCP client, change the host's IP configuration option to DHCP.
For this, click the device and click the Desktop option and click the IP configuration and
select the DHCP option.
To verify that the switch is properly configured as a DHCP server, you can check the IP
configuration of any connected host.
To view the IP configuration of any host, click the host and click the Desktop option and
click the IP configuration option and check the obtained IP configuration.
To view IP addresses leased by the DHCP server, use the 'show ip dhcp
binding' command in privileged-execution mode.
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.
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.
Let's take a simple example to understand how VLAN controls broadcast messages.
A small network is built by using an 8 port switch. Until we configure a VLAN on it, it will
forward an incoming broadcast message from all ports except the port on which the
message came from.
Now, suppose we configure two VLANs on it and add the first four ports to the first VLAN
and the last four ports to the second VLAN. After this configuration, when the switch
receives a broadcast message on a port, it forwards the message only from the ports that
belong to the same VLAN.
For example, if the switch receives a broadcast message on port 2, it will forward that
message from ports 1, 3, and 4 only. Because, port 2 belongs to the first VLAN and other
ports that belong to the first VLAN are 1, 3, and 4. Since ports 5, 6, 7, and 8 don't belong to
the first VLAN, the switch will not forward the incoming broadcast message from these
ports.
VLANs optimize networks by reducing the area of broadcast messages, but they cause
problems for applications that rely on broadcast messages. For example, DHCP uses
broadcast messages to enable communication between DHCP clients and the DHCP
server.
If the DHCP server and clients are configured in different VLANs, clients will not receive IP
configuration from the server. To solve this issue, we have two options. Either configure a
DHCP server in each VLAN or configure multiple DHCP pools on the DHCP server and
assign a DHCP pool to each VLAN.
We have already discussed the first option in the previous part of this article. In this part,
we will learn how to create and configure multiple DHCP pools on the DHCP server and
assign a DHCP pool to each VLAN through a packet tracer example.
Either download the following pre-created packet tracer lab or create a packet tracer lab
as described below.
Add a switch, a router, and six PCs to the workspace. Connect PCs to the switch and the
switch to the router. The following image shows this lab.
Configure this lab to meet the following objectives.
● Configure the DHCP server on the switch and create three DHCP pools.
● Verify that all PCs receive their IP configuration from the DHCP server.
Switch>enable
Switch#configure terminal
Switch(config)#vlan 10
Switch(config-vlan)#exit
Switch(config)#vlan 20
Switch(config-vlan)#exit
Switch(config)#vlan 30
Switch(config-vlan)#exit
Switch(config)#
The following image shows how to execute the above commands on the packet tracer.
Assign VLAN 10 to Fa0/1 and Fa0/2, VLAN 20 to Fa0/3 and Fa0/4, and VLAN
30 to Fa0/5 and Fa0/6.
By default, all switch ports operate in access mode. In access mode, a switch port allows
traffic of a single VLAN only. To allow traffic from multiple VLANs, we have to configure
the port as the trunk port.
In our example, only the port that connects the switch and the router carries the traffic of
multiple VLANs. To configure this port as a trunk port, use the 'switchport mode
trunk' command in interface configuration mode.
By default, DHCP service is enabled on all supporting Cisco switches. To use this service,
we have to create and configure a DHCP pool on the switch.
The following table lists the steps that are required to create and configure a DHCP pool.
Create the DHCP pool To create a DHCP pool and enter DHCP pool configuration mode, use
the 'ip dhcp pool [pool name]' command.
Define IP range for lease use the 'network [network ID] [subnet mask]' command to define
the range of IP addresses. DHCP uses this range to provide IP
configuration to clients.
Set default gateway IP To set the default gateway IP address, use the 'default-router [IP
address of the default gateway]' command.
Set DNS server IP To set the DNS server IP address, use the 'dns-server [IP address of
the DNS server]' command.
Create three DHCP pools by using the above configuration steps.
DHCP uses the IP address of a VLAN to determine the pool from which it should provide
an IP configuration. To assign an IP address to the VLAN, use the following commands.
Switch(config)#interface vlan 20
Switch(config-if)#ip address 10.0.0.5 255.0.0.0
Switch(config-if)#exit
Switch(config)#interface vlan 20
Switch(config-if)#ip address 20.0.0.5 255.0.0.0
Switch(config-if)#exit
Switch(config)#interface vlan 30
Switch(config-if)#ip address 30.0.0.5 255.0.0.0
Switch(config-if)#exit
Switch(config)#
The following image shows the above configuration on the packet tracer.
Configuring the router's interface
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet 0/0
Router(config-if)#no ip address
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#interface FastEthernet 0/0.10
Router(config-subif)#encapsulation dot1Q 10
Router(config-subif)#ip address 10.0.0.1 255.0.0.0
Router(config-subif)#exit
Router(config)#interface FastEthernet 0/0.20
Router(config-subif)#encapsulation dot1Q 20
Router(config-subif)#ip address 20.0.0.1 255.0.0.0
Router(config-subif)#exit
Router(config)#interface FastEthernet 0/0.30
Router(config-subif)#encapsulation dot1Q 30
Router(config-subif)#ip address 30.0.0.1 255.0.0.0
Router(config-subif)#exit
Router(config)#
The following image shows the above configuration on the packet tracer.
To learn how different VLANs communicate through the router in detail, you can check
the following tutorial. It explains how to configure and use VLANs in detail.
VLAN Configuration Commands Step by Step Explained
The following image shows how to use this command to test connectivity between PC1
and PC6. Since PC1 and PC6 belong to VLAN 10 and VLAN 30, respectively, a
successful ping response verifies that both VLANs have proper connectivity.
Configured packet tracer lab
To download the configured lab of this example, use the following download link.
That's all for this part. In the next part of this tutorial, we will understand how to configure
a DHCP server on a Cisco router. If you like this tutorial, please don't forget to share it with
friends through your favorite social channel.
For this tutorial, I assume that you know what DHCP is and how it works. To learn basic
concepts and configurations of DHCP, please check the previous parts of this tutorial.
Either download the following pre-created LAB or create a packet tracer lab as shown in
the following image.
In our example, since the Left_Network and Right_Network are respectively connected
to the Fast Ethernet 0/0 and 0/1 interfaces of the router, both networks will use the IP
addresses of their respective interfaces as the default gateway IPs.
In simple terms, Fast Ethernet 0/0 and Fast Ethernet 0/1 of the router are the default
gateways of the Left_Network and Right_Network respectively. Before configuring the
router to act as a DHCP server, we have to configure and enable these interfaces.
To configure and enable these interfaces, access the command prompt of the router, and
execute the following commands.
Router>enable
Router# configure terminal
Router(config)# interface FastEthernet 0/0
Router(config-if)# ip address 192.168.1.1 255.255.255.0
Router(config-if)# no shutdown
Router(config-if)#exit
Router(config)# interface FastEthernet 0/1
Router(config-if)# ip address 192.168.2.1 255.255.255.0
Router(config-if)# no shutdown
Router(config-if)#exit
The following image shows the above commands on the packet tracer.
For each network that will obtain IP configuration from the DHCP server, we have to
create and configure a DHCP pool on the router. In our example, we have two networks,
so we have to create two DHCP pools, one for each network.
Use the following commands to create and configure a DHCP pool for the Left_Network.
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#ip dhcp excluded-address 192.168.1.0 192.168.1.10
Router(config)#ip dhcp pool Left_Network
Router(dhcp-config)#default-router 192.168.1.1
Router(dhcp-config)#dns-server 192.168.1.2
Router(dhcp-config)#option 150 ip 192.168.1.3
Router(dhcp-config)#network 192.168.1.0 255.255.255.0
Router(dhcp-config)#exit
The following table describes the above commands.
Command Description
ip dhcp excluded-address 192.168.1.0 This command tells the DHCP server not to assign the
192.168.1.10 addresses from 192.168.1.0 to 192.168.1.10 to DHCP
clients.
dns-server 192.168.1.2 This command sets a primary DNS server for the clients.
option 150 ip 192.168.1.3 This command provides the IP address of the TFTP server
to the clients.
network 192.168.1.0 255.255.255.0 This command specifies the range of IP addresses for the
pool.
Create and configure a DHCP pool for the Right_Network using the same commands as
shown below.
To verify that the client has obtained IP configuration from the DHCP server, you can
check the IP configuration option of the client again. For example, the following image
shows how to verify this on a host of the Left_Network.
The following image shows how to verify this on a host of the Right_Network.
To view detailed information about a specific DHCP pool, use the following command.
That's all for this part. In the next part of this tutorial, we will understand what a DHCP
relay agent is and how to configure it on Cisco routers. If you like this tutorial, please don't
forget to share it with friends through your favorite social channel.
DHCP clients use local broadcast messages to obtain IP addresses from the DHCP server.
By default, routers do not forward local broadcast messages. This means, if the DHCP
server is configured on another network or a router is configured between the DHCP
server and DHCP clients, the DHCP clients will not receive IP addresses from the DHCP
server.
In such a situation, a network administrator has two choices either configure a DHCP
server in each subnet or configure the router as a DHCP relay agent that connect the
subnet to the DHCP server. A DHCP relay agent sits between a DHCP server and DHCP
clients and allows the DHCP clients to obtain IP addresses from the DHCP server that is
not configured on the same LAN.
In this tutorial, we will understand how configure Cisco routers as DHCP relay agents
trough a packet tracer example. If you want to learn how to use Cisco routers' interfaces
to configure a DHCP server on each subnet or how a DHCP server works, please check the
previous parts of this article.
If the interface is not configured as the DHCP relay, it will discard the message
immediately. But if it is configured as the DHCP relay it will forward that message to the
DHCP server.
Since a router's interface forwards only unicast messages and a DHCP message is a
broadcast message, the router's interface wraps the broadcast message in a new unicast
message and forwards it to the DHCP server.
When the DHCP server receives a DHCP request in the unicast message, it realizes that the
request is made by a DHCP relay instead of a DHCP client. Because a DHCP client never
uses a unicast address to send a DHCP request.
The DHCP server uses the source address of the incoming unicast message to determine
the subnet of the client. For example, if the source address of an incoming message is
10.0.0.1/8, then the DHCP server realizes that the client belong to a subnet which default
gateway IP must be 10.0.0.1/8.
Once the default gateway IP is determined, the DHCP server checks its pools and finds the
pool that uses the same default gateway. In this case, it finds the pool that is configured
with the default gateway IP 10.0.0.1/8.
After determining the pool, the DHCP server picks an available IP configuration from the
pool and wraps it in a unicast message and sends it back to the DHCP relay.
When the DHCP relay receives a unicast message from the DHCP server, it converts that
unicast message in local broadcast message and sends it in local subnet. The original client
receives the DHCP offer message as a local broadcast message.
The following image shows how a client of the subnet 10.0.0.1/8 receives IP configuration
from the server.
In nutshell, a DHCP relay agent converts the local DHCP broadcast message in a unicast
message by using its IP address as the source IP address and sends the unicast message to
the DHCP server. When the DHCP server replies, it converts the received unicast replay in
local broadcast message and sends it to the local network.
That's all for this tutorial. In the next part of this tutorial, we will understand how to
configure DHCP relay agents on Cisco routers. If you like this tutorial, please don't forget to
share it friends through your favorite social channel.
Configuring a router's interface as a DHCP relay agent is much easier than you might think.
To configure a router's interface as a DHCP relay agent, use the following command in
interface configuration mode.
● Configure the hosts of the first four subnets to obtain IP addresses from the DHCP server
that is available in the fifth subnet.
● On the DHCP server, create four DHCP pools and assign one pool to each subnet.
Let's configure this lab and complete all the above-listed objectives step by step.
Assigning IP configuration
The following table lists all necessary commands to assign IP configuration on a router's
interface.
Router(config-if)#clock rate 64000 To set the clock rate to 64000. (Use only if the
interface is serial DCE)
If you want to learn more about the above commands, you can check the following
tutorial.
RIP Protocol configuration Guide with Examples
This tutorial explains how to enable a Cisco router's interface and how to configure RIP
routing on Cisco routers in detail.
Access the command prompt of each router and configure its interfaces as shown below.
Router0 IP configuration
Router>enable
Router#configure terminal
Router(config)#interface fastethernet 0/0
Router(config-if)#ip address 50.0.0.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#interface serial 0/0/0
Router(config-if)#ip address 192.168.1.2 255.255.255.252
Router(config-if)#clock rate 64000
Router(config-if)#bandwidth 64
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#interface serial 0/0/1
Router(config-if)#ip address 192.168.1.6 255.255.255.252
Router(config-if)#clock rate 64000
Router(config-if)#bandwidth 64
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#
The following image shows the above configuration on the packet tracer.
Router1 IP configuration
Router>enable
Router#configure terminal
Router(config)#interface fastethernet 0/0
Router(config-if)#ip address 10.0.0.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#interface fastethernet 0/1
Router(config-if)#ip address 20.0.0.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#interface serial 0/0/0
Router(config-if)#ip address 192.168.1.1 255.255.255.252
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#
The following image shows the above configuration on the packet tracer.
Router2 IP configuration
Router>enable
Router#configure terminal
Router(config)#interface fastethernet 0/0
Router(config-if)#ip address 30.0.0.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#interface fastethernet 0/1
Router(config-if)#ip address 40.0.0.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#interface serial 0/0/1
Router(config-if)#ip address 192.168.1.5 255.255.255.252
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#
The following image shows the above configuration on the packet tracer.
Configuring RIP routing
The following table lists all necessary commands to configure RIP routing on a router.
Access the CLI prompt of each router and configure RIP routing as shown below.
Router0
Router>enable
Router#configure terminal
Router(config)#router rip
Router(config-router)#network 50.0.0.0
Router(config-router)#network 192.168.1.0
Router(config-router)#network 192.168.4.0
Router(config-router)#version 2
Router(config-router)#no auto-summary
Router(config-router)#exit
Router(config)#
The following image shows the above configuration on the packet tracer.
Router1
Router>enable
Router#configure terminal
Router(config)#router rip
Router(config-router)#network 10.0.0.0
Router(config-router)#network 20.0.0.0
Router(config-router)#network 192.168.1.0
Router(config-router)#version 2
Router(config-router)#no auto-summary
Router(config-router)#exit
Router(config)#
The following image shows the above configuration on the packet tracer.
Router2
Router>enable
Router#configure terminal
Router(config)#router rip
Router(config-router)#network 30.0.0.0
Router(config-router)#network 40.0.0.0
Router(config-router)#network 192.168.1.4
Router(config-router)#version 2
Router(config-router)#no auto-summary
Router(config-router)#exit
Router(config)#
The following image shows the above configuration on packet tracer.
Since the server is connected to the network through the Router0's FastEthernet
0/0 interface, we will set the IP address of Router0's FastEthernet 0/0 interface as the
default gateway IP address on the server.
To set default gateway IP, click the Settings button in the left pane and choose
the Static option in the IP configuration section of the right pane and set the IP address of
the default gateway.
To enable DHCP service on the Server, click Server and click Services. In the left pane
click DHCP and in the right pane select the 'On' option. This will enable the DHCP service.
DHCP service uses DHCP pools to provide IP addresses. A DHCP pool is a group of IP
configurations that the DHCP server assigns to a specific subnet. We have to create pools
equal to subnets. In our network, since we have four subnets, we have to create four
pools.
If you don't know the DHCP pool and its options, please take a pause here and check the
previous part of this article. For this tutorial, I assume that you know the DHCP pool and
its options.
To create and add a pool, fill entries and click the Add button. Make sure that you add the
correct default gateway IP in each pool. DHCP service uses the default gateway IP to
identify the subnet.
The following image shows the entries for the first pool.
The following image shows the entries for the second pool.
The following image shows the entries for the third pool.
The following image shows the entries for the fourth pool.
The following image shows all the pools configured.
The following image shows how to set the DHCP option in the IP configuration section.
Set all PCs as DHCP clients by following the steps described above.
We configure a DHCP relay agent only on the interface that is directly connected to a local
subnet. In this network, four interfaces are directly connected to the local subnets. These
interfaces are the following.
To configure the above-listed interfaces as DHCP relay agents, use the 'ip helper-
address' command as shown below.
Router1
Router>enable
Router#configure terminal
Router(config)#interface fastethernet 0/0
Router(config-if)#ip helper-address 50.0.0.10
Router(config-if)#exit
Router(config)#interface fastethernet 0/1
Router(config-if)#ip helper-address 50.0.0.10
Router(config-if)#exit
Router(config)#
The following image shows the above configuration.
Router2
Router>enable
Router#configure terminal
Router(config)#interface fastethernet 0/0
Router(config-if)#ip helper-address 50.0.0.10
Router(config-if)#exit
Router(config)#interface fastethernet 0/1
Router(config-if)#ip helper-address 50.0.0.10
Router(config-if)#exit
Router(config)#
The following image shows the above configuration.
To verify that all DHCP relays are configured properly, check the IP configuration of their
connected devices. To check the IP configuration of a client device, click the device and
click the Desktop option and click the IP configuration. If the device shows the correct IP
configuration, the DHCP relay is configured properly.
If you prefer the command prompt, you can use the 'ipconfig' command to view the
received IP configuration. The following image shows how to view IP configuration on PC2
at the command prompt.
Configured practice lab
The following download link provides the configured LAB of this example.
That's all for this part. In the next part of this tutorial, we will understand what the DHCP
snooping is and how it works. If you like this tutorial, please don't forget to share it with
friends through your favorite social channel.
DHCP Snooping is a switch only feature. It means DHCP snooping only works on switches.
It does not work on other devices such as routers and servers. Typically all switches,
whether it is a layer 2 switch or a multilayer switch, support DHCP snooping.
DHCP snooping works on a per-VLAN basis. It means, you can enable and configure
DHCP snooping on your desired VLANs. For example, if you configure DHCP snooping on
VLAN-2, then it will work only on the ports that belong to VLAN-2. By default, DHCP
snooping is disabled on all VLANs.
DHCP snooping acts like a firewall. It inspects all incoming messages on the port. If an
incoming message is not related to DHCP, the DHCP snooping lets it in. If an incoming
message is related to DHCP, the DHCP snooping uses its logic. Based on its configuration,
DHCP snooping either let the message in or discard the message.
In such an attack, an attacker configures a replicated DHCP server on his device and
connects that device to the local network. When a DHCP client sends a local broadcast
message to obtain an IP configuration, the attacker's device receives this message and
lease a modified IP configuration to the client.
The modified IP configuration contains all addresses the same except the gateway IP
address. This configuration contains the gateway IP address of the attacker's device
instead of the original gateway. When the client uses this modified configuration, all
packets sent by the client to the default gateway reach the attacker device. The attacker
device reroutes them to the original gateway.
Since all packets sent by the client reach the default gateway through the attacker device,
the attacker can make a copy of all packets or can steal the sensitive information from the
packets. This attack is known as the man-in-middle attack on the DHCP server.
The following image shows an example network. In this network, the client receives an IP
configuration from the DHCP server and uses the received IP configuration to connect to
the remote network.
The following image shows the same example network. But this time, the client receives IP
configuration from the attacker's DHCP server.
The following image shows how data flows between the client and the default gateway
after a man-in-middle attack.
How does DHCP snooping protect the network from the man-in-middle attack?
DHCP uses four different types of messages: Discover, Offer, Request, and ACK. From
these messages, DHCP clients use Discover and Request messages while DHCP servers
use Offer and ACK messages.
Since a DHCP client never uses the Offer and ACK messages, DHCP snooping can be
configured to filter these messages on ports that are connected to DHCP clients. This
configuration will mitigate the threat of the man-in-middle attack on DHCP servers.
In our example, the DHCP server is connected to the port Fa0/11. So we will configure
DHCP snooping to allow Offer/ACK messages only on port Fa0/11.
Once DHCP snooping is configured, the switch will accept Offer/ACK messages only on
the ports that are configured as the allowed (trusted) ports. If it
receives Offer/ACK messages on the ports that are not configured as the allowed ports, it
immediately discards those messages.
The following image shows how DHCP snooping protects our example network from
the man-in-middle attack.
In this example, when the attacker tries to lease an IP configuration to the client, the
switch blocks the attacker's offer. After this configuration, the client receives IP
configuration only from the authenticated DHCP server.
In DHCP snooping configuration, a trusted port is a port that can accept all four types of
messages and an untrusted port is a port that can accept only two types of messages: the
Discover and Request.
On untrusted ports DHCP snooping does not accept the messages that a DHCP server
needs to provide IP configuration to clients. These messages are the Offer and ACK. In
simple words, until a DHCP server can send these messages to the client, it can't lease the
IP configuration to the client.
Since on untrusted ports DHCP snooping does not allow the messages that the DHCP
server requires to function, a DHCP server connected on an untrusted port can't lease IP
configuration to clients.
The following image shows how DHCP snooping blocks and allows DHCP messages.
DHCP binding table
DHCP binding table is the next level of security that the DHCP snooping provides. DHCP
snooping maintains a record of all offered/leased IP addresses in the DHCP binding table.
DHCP snooping uses this record to block DoS attacks.
Let's understand how a DoS attack works and how DHCP snooping uses the DHCP
binding table to block this attack.
When a client broadcasts a DHCP Discovery message, the client also includes its MAC
address in the message. The DHCP server uses the client's MAC address to provide the IP
configuration to the client.
Since a client uses a local broadcast address to send the DHCP Discovery message, if an
attacker's device is connected to the local network, it also receives the broadcast
message. From the broadcast message, it learns the client MAC address and uses it to
make fake DHCP requests.
The following image shows a DHCP snooping enabled network. In this network, the client
sends a local DHCP Discovery broadcast message. Both original and fake DHCP servers
offer IP configuration to the client. DHCP snooping filters and blocks the fake DHCP
server's offer and allows the offer of the original DHCP server. The client receives IP
configuration only from the genuine DHCP server.
The attacker device fails to provide IP configuration to the client but it knows the MAC
address of the client. So it uses the client's MAC address to generate a lot of fake DHCP
requests.
Since DHCP snooping does not block Discovery/Request messages, all these messages
reach the genuine DHCP server and the DHCP server provides an IP configuration for each
request. The following image shows this process.
Soon the attacker leases all IP addresses from the DHCP server, leaving no IP addresses
for the actual clients. Once all IP addresses are leased, the DHCP server can't provide IP
addresses to the clients that are configured to obtain their IP addresses from the DHCP
server. Since clients can't receive IP addresses from the DHCP server, they lose
connectivity from the network.
This attack is known as the DoS attack on the DHCP server. To minimize this attack, DHCP
snooping keeps a record of each successful assignment in the DHCP binding table. When
it receives a Discovery/Request message on an untrusted port, it reads the MAC address
of the message and finds that address in the DHCP binding table. If it finds an entry in the
DHCP binding table, it discards the message.
DHCP Snooping is a security feature of Layer 2 switches. It allows us to filter and block
certain types of DHCP traffic. By using this feature, we can mitigate several security risks
caused by rogue DHCP servers and attackers.
DHCP snooping works on a per-VLAN basis. By default, this feature is not enabled. To use
this feature, first, we have to enable it. After enabling, we can configure it on some VLANs
or all VLANs. Once configured, it actively monitors incoming traffic on all ports of the
configured VLAN. If it detects any DHCP packet, based on its configuration either it allows
the packet or drops the packet.
To learn how this process works in detail, you can check the previous parts of this tutorial.
In this part, we will understand how to configure DHCP snooping on Cisco switches.
Packet Tracer lab setup
Create a packet tracer lab as shown in the following image.
● Configure the Fa0/0 interface of the router to forward all DHCP requests to the Server0.
● Configure a DHCP pool for the local network connected to the Switch0.
Access the CLI prompt of the router and run the following commands.
Router>enable
Router#configure terminal
Router(config)#interface fastethernet 0/0
Router(config-if)#ip address 10.0.0.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#interface fastethernet 0/1
Router(config-if)#ip address 20.0.0.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#interface fastethernet 0/0
Router(config-if)#ip helper-address 20.0.0.10
Router(config-if)#exit
Router(config)#
The following table explains the commands used in the above configuration.
Command Description
Router(config-if)#ip address [IP address] [subnet mask] Assign an IP address to the interface.
Router(config-if)#ip helper-address [IP address of the DHCP server] Configure the interface to forward DHCP
To assign a static IP address to the Server0, click Server0 and click the IP
configuration option of the Desktop menu. In the IP configuration option, select
the Static option and set the static configuration.
To configure PCs as DHCP clients, click the PC and click the IP configuration option from
the Desktop menu item and select the DHCP option. The following image shows this
procedure.
Verifying DHCP Server
If the DHCP server is configured properly, DHCP clients get IP addresses automatically as
soon as they change their IP configuration to DHCP. The following image shows the IP
configuration of the PC2 that it gets from the DHCP server.
Adding the attacker's DHCP server
To understand how DHCP snooping protects the network from a rogue DHCP server, let's
add an attacker's DHCP server to our network. The following image shows our example
network after adding the attacker's DHCP server.
The following image shows the static IP configuration of the attacker DHCP server.
Add a DHCP pool that replicates the DHCP pool of the original DHCP server. In this pool,
change the default gateway IP to the IP address that you assigned to this server. The
following image shows how to do this.
By default, the server contains a default pool and the packet tracer does not allow us to
delete it. If multiple pools are configured, DHCP uses the source address to determine the
correct pool. Since DHCP clients use the 0.0.0.0 address as the source address and the
default pool also uses this address as the default gateway and DNS server addresses,
DHCP provides the IP configuration from the default pool instead of our pool. To force
DHCP to use our pool, change the default gateway IP to the IP address of the server in
the default pool.
The attacker's DHCP server is available in the local network. It receives DHCP requests
from clients before the original DHCP server. Since the attacker's DHCP server receives
the request first, it also reacts first and the client gets an IP configuration from the
attacker's DHCP server.
To verify this, click a PC from the local network and change its IP configuration
to Static and back to DHCP.
The following image shows how PC2 obtains a new IP configuration from the attacker's
DHCP server instead of the original DHCP server upon requesting a new IP configuration.
If DHCP clients use the IP configuration provided by the attacker's DHCP server, the
attacker can misuse their data without knowing them. This is known as the man-in-
middle attack.
To learn this attack in more detail, please check the previous part of this tutorial. The
previous part of this tutorial explains the man-in-middle attack in detail with an
example.
● By default, DHCP snooping is disabled on Cisco switches. To use this feature, first, we have
to enable it.
● DHCP snooping works a per-VLAN basic. Once DHCP snooping is enabled, we have to
specify the VLAN on which we want to apply this. You can specify a single VLAN or
multiple VLANs. To configure a single VLAN, enter a single VLAN number. To configure a
range of VLANs, enter a beginning and an ending VLAN number or a dash and range of
VLANs.
● DHCP snooping treats all ports of the specified VLAN as the untrusted ports. An untrusted
port is a port that does not accept DHCP server messages. In other words, if a device is
connected to an untrusted port, it can obtain IP configuration from the DHCP server but it
cannot offer an IP configuration.
● If a DHCP server is connected to the port, we have to configure that port as the trusted
port. A trusted port is a port that accepts DHCP server messages. In other words, a DHCP
server can provide IP configuration only if it is connected to a trusted port.
The following table lists the commands that are used to configure and verify DHCP
snooping on Cisco switches.
Command Description
Switch(config)# ip dhcp snooping To enable DHCP snooping globally.
Switch(config)# ip dhcp snooping vlan To enable DHCP snooping on the specified VLAN.
number [number]
Switch(config-if)# ip dhcp snooping limit To limit the number of DHCP packets that the
rate [rate] interface can receive in a second.
Switch# show ip dhcp snooping To view DHCP snooping configuration and status
Switch# debug ip dhcp snooping packet To view DHCP messages and packets.
The following commands configure DHCP snooping on the switch of our example
network.
Switch>enable
Switch#configure terminal
Switch(config)#ip dhcp snooping
Switch(config)#ip dhcp snooping vlan 1
Switch(config)#interface fa0/4
Switch(config-if)#ip dhcp snooping trust
Switch(config-if)#exit
Switch(config)#exit
Switch#
The following image shows the above commands on the packet tracer.
Let's understand the above configuration in detail.
We used the first and second commands to enter global configuration mode. We used the
third command to enable the DHCP snooping.
VLAN 1 is the default VLAN on Cisco switches. By default, all ports belong to this VLAN.
Since DHCP snooping works on VLANs and we did not create any VLAN in our example,
we implemented DHCP snooping on the default VLAN using the fourth command.
In our example, the original DHCP is connected to the interface Fa0/4. We used the fifth
command to enter the interface configuration mode of the Fa0/4 interface. In interface
configuration mode, we used the sixth command to configure the interface as the trusted
interface.
Once DHCP snooping is enabled, only the DHCP server that is connected to the trusted
interface can provide IP configuration. To verify this, let's obtain a new IP configuration on
a PC of the local network.
The following image shows how PC2 obtains a new IP configuration from the original
DHCP server.
Viewing DHCP snooping configuration
To view DHCP snooping configuration and statistics, use the 'show ip dhcp
snooping' command in privileged-exec mode.
By default, DHCP snooping does not limit the number of DHCP packets that an interface
can receive. Since untrusted interfaces connect to DHCP clients, to enhance the security
you can limit the number of DHCP packets on these interfaces.
The recommended rate limit for each untrusted port is 15 packets per second. Generally,
the rate limit is applied to untrusted interfaces. But if required, you can also configure it on
a trusted interface.
To configure DHCP snooping rate limit on an interface, use the 'ip dhcp snooping limit
rate [number]' command in interface configuration mode of the interface.
The following image shows how to set the rate limit on the Fa0/1 interface and verifies the
same.
To debug DHCP snooping events and packets, use the 'debug ip dhcp snooping
event' and 'debug ip dhcp snooping packet' commands in privileged-exec mode. To
disable debugging, use the keyword 'no' before the same commands.
The following image shows how to enable and disable the debugging of DHCP snooping.
Downloading the practice lab used in this tutorial
If you want to download the practice lab used in this tutorial, you can download it from
the following links. Each link provides the practice lab in a different stage.
This lab does not contain any configuration. Use this lab, if you want to configure the lab
from the starting as explained in this tutorial.
In this lab, the DHCP server, router, and DHCP clients are configured but, the attacker's
DHCP server is not connected to the network. Use this lab, if you want to practice by
adding and configuring an attacker's DHCP server.
In this lab, both the original and attacker's DHCP servers are configured but DHCP
snooping on the switch is not configured. Use this lab, if you only want to practice of the
DHCP snooping.
This lab contain all configuration. Use this lab for your references or to cross-check your
configuration.
If you download and use the lab used in this tutorial, wait for a minute after loading the
lab on the packet tracer. Switches take about 45 - 50 seconds to initialize. Due to this
reason, all DHCP requests that were made before the switch initialized fail. If you see a
DHCP fail message, it means PC tried to obtain a new IP configuration when the switch
was initialing. To get a new IP configuration, change IP configuration to static and back
to DHCP. This will force the PC to obtain a new IP configuration.
That's all for this tutorial. If you like this tutorial, please don't forget to share it with friends
through your favorite social network.