What is DHCP?
DHCP is a service. It allows devices to acquire their IP configuration dynamically.
It works in the server/client model. Clients request their IP configurations, then
server offers and delivers the requested IP configurations.
DHCP Address Allocation Methods
To provide an IP configuration, a DHCP server can use three mechanisms. These
mechanisms are the following.
1. 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.
2. 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.
3. Automatic allocation: it does Same as dynamic method. 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.
How DHCP Works
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, using 0.0.0.0 as source address and 255.255.255.255
as destination address.
DHCP Offer
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. The DHCPOFFER
message contains IP configuration. An IP configuration typically includes the
following important information: the IP address for the client, the subnet mask
of the proposed IP address, the IP address of the default gateway, the DNS
server address or addresses, and the TFTP server address or addresses.
DHCP Request
• 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,
then tells the corresponding server with a DHCPREQUEST message that it wants
to use the offered IP configuration.
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.
DHCP Configuration Parameters and Settings
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.
DHCP 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.
Cont …
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.
Cont …
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.
Create this network topology as shown in
following figure
DHCP configuration for single broadcast domain
Configuring DHCP clients
To configure the host as a DHCP client, change the host's IP configuration option
from static to DHCP. For this, click the device and click the Desktop option and
click the IP configuration and select the DHCP option
Verifying DHCP Server
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.
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.
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
Configure DHCP Server for Multiple VLANs on the Switch
VLANs optimize networks by reducing the area of broadcast domain, 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.
Configure Multiple DHCP Pools on the DHCP Server
Create three VLANs and add 2 PCs to each VLAN.
Configure the DHCP server and create three DHCP pools.
Assign a DHCP pool to each VLAN.
Configure all PCs as DHCP clients.
Verify that all PCs receive their IP configuration from the DHCP server.
Create this network topology lab as shown in following figure
Create three VLANs and add PCs to each VLAN.
Assign the VLANs to the Switch Ports
Configure the DHCP server on the switch and create three DHCP pools.
For VLAN 10
Create DHCP pool For VLAN 10
Create DHCP pool For VLAN 20
Create DHCP pool For VLAN 30
Assigning IP Addresses to VLANs
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 [vlan name or number]
Switch(config-if)#ip address [ip address] [subnet mask]
Assign an IP address For VLAN 10
Assign an IP address For VLAN 20
Assign an IP address For VLAN 30
Verifying the DHCP server that we set up for several VLANs
• You can check the offerd IP address to each devices in each VLANs .
IP configuration for VLAN 10 PC0 from the v10pool DHCP pool
IP configuration for VLAN 20 PC1 from the v20pool DHCP pool
IP configuration for VLAN 30 PC2 from the v130pool DHCP pool
To Viewing leased addresses from different DHCP pool that we have created, use
the 'show ip dhcp binding' command from privileged-execution mode.