In this article I will talk about a well known service that can be configured on Cisco devices, DHCP or Dynamic Host Control Protocol. This is a network service that automatically configures any device that uses the Internet Protocol, with all the elements needed to communicate inside a network. DHCP is a transparent process (to the user) that has helped a lot network administrators with managing IP addresses. Before this service became available, every device would required static entries that would bind a physical device to a unique IP address. Imagine how hard it was for network administrators to maintain all changes of locations and IPs for all devices. DHCP offers an easy way to manage and troubleshoot IP allocation and also provides a scalable service meaning that is not affected by network growth. Beside the workstation IP address, DHCP can automatically assign the network mask, default gateway, DNS servers and much more.
As an IP allocation mechanism, DHCP provides three methods of assigning an IP to a physical host:
manual – network administrators manually assign one IP address to a single device. The DHCP service is used only to maintain that particular binding.
automatic – a single IP address is allocated permanently to a host and the DHCP server will always allocate the same IP to that particular host.
dynamic – DHCP will allocate IPs from a pool of usable addresses. IP addresses are leased for a defined period of time and if a device does not renew its lease, the IP is automatically returned to the address pool and can be used again by another device.
DHCP works in a client/server model. The host requests an IP address to the closest DHCP server and the server responds with a new IP allocation or renew of the leased IP. The host must contact the DHCP server periodically to renew its lease. If the host doesn’t contact the server for a period of time, the IP address is returned to the address pool. When a device wants to obtain IP allocation from a DHCP server, the following messages are exchanged:
1. the host sends a DHCPDISCOVER message which is a broadcast message send to all devices in the network. It will use the layer 2 and layer 3 broadcast addresses (FFFF-FFFF-FFFF-FFFF and 255.255.255.255).
2. the DHCP server will receive the message and will create an entry in the ARP table that will contain the host’s MAC address and the leased IP address. This information will then be sent in a DHCPOFFER message. The response is sent unicast directly to the host by using it’s MAC address.
3. the host will then check the received DHCPOFFER message and will then reply with a broadcast DHCPREQUEST message informing all devices (and the DHCP server) that he accepted this configuration.
4. the server will finally reply with a DHCPACK message and the host will have access to network resources.
The following image displays the DHCP allocation mechanism:
DHCP had a predecessor, the BOOTP(Bootstrap Protocol) which was used primarily for configuring devices that did not had an operating system nor a hard drive. These two protocols are somehow similar because both use the client/server model. The main difference between DHCP and BOOTP is that BOOTP uses manually configured tables in which bindings between IP and MAC addresses are stored. DHCP builds entries automatically according to network changes. Another aspect of BOOTP is that this protocol uses permanent assigned IP addresses (the same IP address is allocated to one device permanently). BOOTP supports only four configuration parameters (IP address, subnet mask, gateway address and DNS server’s IP address) while DHCP supports over 20 parameters. Check the following link from IANA for more information: http://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xml.
Next, we will talk about configuring DHCP on Cisco devices. Remember that you will have to be careful when doing this on a production environment so I suggest you test your configurations first. When configuring DHCP, we will first have to set IPs that will be reserved for special purposes and will not be included in the DHCP pool. Remember that servers, routers or printers require static IP addresses so it’s best that you include all these devices in the excluded IP pool. To configure these excluded addresses, use the ip dhcp excluded-address [ip address or ip pool] command. The following image displays an example of such a pool:
In this case, the IPs from 172.16.1.0 to 172.16.1.100 will not be leased to clients.
Next, we will need to configure the DHCP pool and the default-router address. To achieve this, use the commands displayed in the following image:
Optionally, you can configure domain name, dns server, duration of dhcp lease, etc. To view these options type ? from the dhcp configuration mode:
These are the options emulated in my Cisco Packet Tracer version. If you use GNS3 tool, all DHCP commands will be available:
To verify your configuration, use the show running-config, show ip dhcp binding, show ip dhcp server statistics and show ip dhcp pool commands. Run these commands one by one to view their output. The following image displays the show running-config command:
To troubleshoot your DHCP configuration, use the show ip dhcp conflict (this command is used when an IP allocation conflict exists).
Remember that DHCP clients use broadcast messages when first trying to obtain IP configuration. We already know that broadcasts are not forwarded by routers by default, so what would happen if your DHCP server is a couple of routers away from your client computer? Well, on the closest router to the client’s workstation, you’ll have to specify the DHCP server IP address by using the ip helper-address [IP address] command from the interface configuration mode. By issuing this command, the router will accept DHCP broadcasts and will then forward the request unicast to the specified IP address:
This mechanism is also known as DHCP Relay.
On the client side, if you use Cisco devices that will obtain their IP configuration from the DHCP server, use the ip address dhcp command from the interface configuration mode:
I think that’s about it for this post folks. Remember to rate/share/comment if you’ve enjoyed this article. Have a wonderful day and stay tuned for more articles to come.