DHCP or Dynamic Host Configuration Protocol is a software service that allows you to automate the IP configuration of your hosts in a computer network. In this blog you will learn how to set up and configure DHCP service in a Cisco Router.
How to configure DHCP server in a Cisco router
The above figure is our basic network that has a DHCP service. this lab is about how to configure DHCP router in cisco using packet tracer.
This explains an example of a network that has a DHCP server, configured in a Cisco Router. The Server is the Router 1 in the left. With this feature configured in Router 1, Now all hosts in network 192.168.1.0/24 can allocate IP Configuration from DHCP server.
In the other side we have configured Router 2 in the right as a Relay Agent, meaning if a host in Network 192.168.2.0/24 trie to allocate a Dynamic IP configuration, the Relay agent router will forward the requests to Router 1. Then the all shots in network 192.168.2.0/24 will able to allocate IP configuration even though they are not in the same network with the DHCP Server.
Commands to Configure DHCP service in Cisco Router
In this example we will configure two routers, the main one will be the DHCP server. While the second one will be the DHCP relay agent.
First to configure Cisco router as a DHCP server, Go to Router CLI interface, then access the Global configuration mode.
Router1> en Router1# conf t
Now you need to exclude a range of addresses that you don’t want the DHCP server to assign. This inlcude all the static IP addresses in your network, including The Router Interface IP address, and other server Addresses Like DNS, MAil, and Web Servers IP addresses. In short, whenever you want to configure A DHCP server even in a Linux Server or a Windows server you’ll always have to exclude a range of addresses.
In this case, let’s exclude addresses from 192.168.1.1 to 192.168.1.10. This means the DHCP server will assign addresses from 192.168.1.11 until 192.168.1.245
Router1(config)#ip dhcp excluded-address 192.168.1.1 192.168.1.10
Second step is to create a DHCP pool, that will be the allowed range of addresses for DHCP to assign to hosts. Something to remember is that whenever you want to enable DHCP service in a network you have to create a pool for that network. You need first to define a pool name, in this example, we named the pool for network 192.168.1.0/24 plan1.
Router1(config)# ip dhcp pool plan1 Router1(dhcp-config)# network 192.168.1.0 255.255.255.0
The third step is to add the default Gateway Address. The DHCP will assign an IP address for the host machine and the default gateway.
Router1(dhcp-config)# default-router 192.168.1.1
You can also make DHCP server assign DNS server address to your hosts if you have it in your network by this command. in this example, the DNS server address is 192.168.1.10
Router1(dhcp-config)# dns-server 192.168.1.10
How t configure Cisco router as a DHCP Relay Agent
A DHCP relay agent is any other router that is just relaying hosts in a network to the main DHCP router so that they can allocate IP address configuration. You can do this by entering the router interface that is connected to the target network and Add one command ip helper-address followed by the interface IP address of the main DHCP server router.
Like the first network, you have to exclude the addresses for 192.168.2.0/24. then create another DHCP pool. This configuration must be done in the Router1/DHCP server.
Router1(config)#ip dhcp excluded-address 192.168.2.1 192.168.2.10 Router1(config)# ip dhcp pool plan1 Router(dhcp-config)# network 192.168.2.0 255.255.255.0 Router1(dhcp-config)# default-router 192.168.2.1 Router1(dhcp-config)# dns-server 192.168.1.2
Now go to the LAN network you want to provide it with external DHCP service, then access the router interface that is directly connected to this network. In our case, we’ve configured Router 2 of the network 192.168.2.0/24.
Next step is to run the command IP helper-address then followed by the Ip address of DHCP server. for this lab the address is 10.0.0.1 because this is the path Router 2/relay agent can take to talk connect with Router 2/DHCP server.
Router2(config-if)# ip helper-address 192.168.2.1
configuring DHCP service in a router is a great thing t know as a network administrator. But it’s not always recommended to use a router as a DHCP server. That’s because Routers in fact are not performant like Computer servers. So as a best practice, you have to consider configuring DHCP service in a Linux server or Windows server. Even though in a small network it’s not a bad idea to enable DHCP service directly from the router.
NOTE: You must configure a routing protocol in your network. Otherwise, a DHCP relay agent will not be able to get a response from the DHCP server. in simple words, you need to connect all hosts in your networks. using Rip protocol or any other routing protocol. In this lab we have used RIP protocol.
router1(config)# router rip router1(config)# version 2 router1(config)# network 192.168.1.0 router1(config)# network 10.0.0.0
For th relay agent Router2:
router1(config)# router rip router1(config)# version 2 router1(config)# network 192.168.2.0 router1(config)# network 10.0.0.0
Video tutorial for configuring DHCP service Cisco router, and How to set up DHCP relay agent.
We hope this guide helps you. for more awesome IT topics consider checking our website categories.