Step by Step to Configure Cisco Router as DHCP server in GNS3

Saifudheen SidheeqLatest PostsLeave a Comment

I know how does DHCP works, but what if I want to configure my router as a DHCP server as well, is it possible? the answer is YES!, You can configure the Cisco router as the DCHP server and this blog we are going to cover the same.

In the last blog, I covered how we can configure the Cisco router as a DNS server that way you could use them in small offices and POC’s and labs.

In this blog, we are going to use the similar network topology that we had used previously for our DNS lab, but little different. We are going to configure DHCP on one of the cisco DNS servers, which again is a router.

And to simulate the end user’s machine, we are going to use Webterm as a DHCP client that way it acts as the real end-user machine. I explained in this article on how you can configure the Webterm in gns3.

Prerequisite for this lab

  • Gns3 or any emulation software.
  • Cisco Router image, Can use IOS, IOU, VIOS from virl, or CSR1000v.
  • If your GNS3 doesn’t have internet connectivity and unable to use Webterm as a DHCP client you may use the router as a DHCP client and make sure you disabled the IP routing by typing the command no IP routing.
    wanted to connect GNS3 to the internet? then you may check out the article here.

Here is the topology that we are going to use and we are going to work on the DHCP configuration for the LAN segment 10.1.1.0/24 and 10.100.1.0/24 which means two DHCP scopes.

configure cisco router as dhcp server topology

Design the Network topology as above.

Once you have the network up and running let’s go ahead and configure the DHCP on our cisco router.

Configuration of DHCP Server on the Cisco router

Step1. Define the pool, The name of the pool I have given is pool-01-10.1.1.0/24 for the subnet 10.1.1.0/24

DHCP1(dhcp-config)#ip dhcp pool pool-01-10.1.1.0/24

Step2. Add the subnet that you are going to use.

DHCP1(dhcp-config)#network 10.1.1.0 /24

Step3. Configure the default gateway for this subnet.

DHCP1(dhcp-config)#default-router 10.1.1.1

Step4. In case if you have an internal DNS server add them as below, In my case I had already configured DNS service in the same DHCP Server also another DNS secondary server, hence I am going to point the same.

  • If you don’t have any DNS server you may skip this step.
  • If you have internet connectivity to the lab and wanted to use a public DNS server you can use them as well.
DHCP1(dhcp-config)#dns-server 192.168.1.5 192.168.1.6

Step5. Configure the DNS domain name, if you are not using DNS you may skip this step as well. I am adding my internal DNS domain as below.

DHCP1(dhcp-config)#domain getlabsdone.local

Step6. We would keep the first ’10’ IP for manual reservations from each subnet.
For example, if we are planning to add any printers or servers in the location we could use the static IP configuration from those 10 IPs later.

For this purpose, we can use something called excluded-address, exit out of the DHCP configuration and come to the global config and enter the command as below.

DHCP1(dhcp-config)#exit 
DHCP1(config)#ip dhcp excluded-address 10.1.1.0 10.1.1.10

We just completed the DHCP configuration for the subnet 10.1.1.0/24

The second DHCP subnet configuration is as below.

DHCP1#configure terminal 
Enter configuration commands, one per line.  End with CNTL/Z.
DHCP1(config)#DHCP1(config)#ip dhcp pool pool-02-10.100.1.0/24
DHCP1(dhcp-config)#network 10.100.1.0 /24
DHCP1(dhcp-config)#default-router 10.100.1.1
DHCP1(dhcp-config)#dns-server 192.168.1.5 192.168.1.6
DHCP1(dhcp-config)#domain-name getlabsdone.local
DHCP1(dhcp-config)#exit
DHCP1(config)#ip dhcp excluded-address 10.100.1.0 10.100.1.10
DHCP1(config)#exit

Verification of the DHCP configuration on the CISCO router.

To verify the DHCP configuration that you have made on the cisco router you can enter the command show ip dhcp pool, which will show the properties of each scope that you have.

DHCP1#show ip dhcp pool

Pool pool-01-10.1.1.0/24 :
 Utilization mark (high/low)    : 100 / 0
 Subnet size (first/next)       : 0 / 0 
 Total addresses                : 254
 Leased addresses               : 0
 Pending event                  : none
 1 subnet is currently in the pool :
 Current index        IP address range                    Leased addresses
 10.1.1.11            10.1.1.1         - 10.1.1.254        0

Pool pool-02-10.100.1.0/24 :
 Utilization mark (high/low)    : 100 / 0
 Subnet size (first/next)       : 0 / 0 
 Total addresses                : 254
 Leased addresses               : 0
 Pending event                  : none
 1 subnet is currently in the pool :
 Current index        IP address range                    Leased addresses
 10.100.1.11          10.100.1.1       - 10.100.1.254      0
DHCP1#

Configure Webterm (End-user machine) as DHCP client

  • Right-click on the machine and click on configure
  • On the Network configuration, tab click on Edit
DHCP client configuration in gns3
  • Configure the network as below as you can see I have uncommented the DHCP configuration field.
DHCP client configuration in gns3

DHCP client not getting an IP address from DHCP server

Login to the machine again and check the IP address configuration by typing the command IP addr, as you can see there is no DHCP IP address assignment from the Cisco router DHCP server.

DHCP client configuration in gns3

There got to be something wrong! do you know what has happened?

How do we troubleshoot DHCP clients unable to get the IP addresses?

The DHCP discover message which the end-user machine sends is broadcast since it is broadcast the router will not send that discover packet any of its interfaces, it just drops the broadcast packet.

You can use something called IP helper-address which will relay this discover message to the DHCP server as unicast.

  • To prove this I already ran packet capture from the end-user machine as well on the DHCP router end, as you can see the DHCP discover traffic is broadcast from the end-user machine but there is no response for the same.
DHCP discover broadcast

Configuring the IP helper-address on the router.

  • Log in to the gateway router and get into the gateway IP interface and add the IP helper configuration.
Gateway(config)#int g3/0
Gateway(config-if)#ip helper-address 192.168.1.5
  • As soon as I did that you can see the packet capture from the end-user machine which shows the DHCP Offer, Request and ACK exchange happened between the server and the client and it handed over the IP from the DHCP server.
DHCP discover broadcast
  • You can also see that the Same broadcast DHCP discover a message from the end-user machine now sending as unicast from the gateway IP 10.1.1.1 where we have configured DHCP IP helper.
DHCP discover unicast
  • As you can see below that the webterm DHCP client has received the first IP from the DHCP pool.
[email protected]:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
12: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
    link/ether e2:b1:49:54:5c:15 brd ff:ff:ff:ff:ff:ff
    inet 10.1.1.11/24 scope global eth0
       valid_lft forever preferred_lft forever
[email protected]:~# 

  • I also enabled the DHCP on all the machine and now when I checked the DHCP binding on my cisco router I could see as below, there are two IPs allocated for the end-user in 10.1.1.0/24 subnet.
DHCP1#show ip  dhcp binding 
Bindings from all pools not associated with VRF:
IP address          Client-ID/              Lease expiration        Type
                    Hardware address/
                    User name
10.1.1.11           01e2.b149.545c.15       Dec 18 2019 06:28 PM    Automatic
10.1.1.14           01e2.2a06.f679.4c       Dec 18 2019 06:33 PM    Automatic
DHCP1#

But where is the rest of the IP’s, its because we haven’t pointed the IP helper for the other subnet.

Configuration of IP helper-address for the second subnet

  • log in to the gateway and add IP helper-address on the second subnet interface gateway.
Gateway(config-if)#int g2/0
Gateway(config-if)#ip helper-address 192.168.1.5
  • When I check the status of the DCHP now, I can see all the end-user machine has got the DHCP IP address from all the scope as expected.
DHCP1#show ip  dhcp binding         
Bindings from all pools not associated with VRF:
IP address          Client-ID/              Lease expiration        Type
                    Hardware address/
                    User name
10.1.1.11           01e2.b149.545c.15       Dec 18 2019 06:28 PM    Automatic
10.1.1.14           01e2.2a06.f679.4c       Dec 18 2019 06:33 PM    Automatic
10.100.1.11         014a.ec31.9476.5f       Dec 18 2019 06:36 PM    Automatic
10.100.1.12         015e.28f4.95d1.80       Dec 18 2019 06:36 PM    Automatic
DHCP1#
DHCP1#

Note: I can use static IP 10.100.1.6 and 10.100.1.2 for ftp1 and the web servers respectively from the DHCP excluded-address.

Final verification

To make sure everything is working as expected I decided to add one more end-user machine to the subnet 10.1.1.0/24 subnet. This time I tried with a router and disabled IP routing.

adding cisco router as dhcp client
user-5(config)#no ip routing    
user-5(config)#int g0/0
user-5(config-if)#ip address dhcp

After a couple of seconds, you would get a message which says below.

 %DHCP-6-ADDRESS_ASSIGN: Interface GigabitEthernet0/0 assigned DHCP address 10.1.1.13, mask 255.255.255.0, hostname user-5

You can also check the interface to see the assigned IP address.

user-5#sh ip int brief
Interface                  IP-Address      OK? Method Status                Protocol
GigabitEthernet0/0         10.1.1.13       YES DHCP   up                    up     

Awesome! everything is working as expected, You can add up to 244 machines to each subnet except those 10 IP’s that we had excluded from the list.


Learn About This Author

Saifudheen Sidheeq

Saifudheen is in the Computer networking and technology field for about a decade now. He loves technology and new ideas, and in his spare time, he loves to write about them.