Skip to main content

How to Set Up a Cisco Router as a DHCP Server (Step-by-Step Guide)


Lab time! Want to build a DHCP server?  In this lab, I will show you how to build your own DHCP server on a router using Cisco Packet Tracer, as shown above. By the end of this post, you will be able to create your own DHCP server with a Cisco 2911 router, perhaps in a home lab setting, and prepare you to build your own on other hardware. 

Why a Router?

 A DHCP server is a centralized, automated service that assigns important network configuration details to devices on a network, such as IP addresses. Without it, we would have to create manual entries for our entire network, which can be time-consuming and lead to errors. Traditionally, there are dedicated servers to handle these functions. There are many ways to implement a DHCP server in your topology, including a dedicated physical server, a virtual machine, cloud-based gateways, and firewalls. However, there are specific benefits to using a router as your DHCP server:

  • Reduced infrastructure: While having a dedicated server is useful, it adds an extra cost and complexity on your network. Using a router simplifies your setup.
  • Optimizing Performance:  Reduces the need for additional devices, minimizing network hops and potential latency.
  • VLAN Compatibility: This lab will especially show the ease of routing between VLANs and providing DHCP services for each VLAN. Instead of having different servers for different floors or VLANs, the router can handle these services.
  • High Availability and Reliability: Without the router, you cannot exit your local network, meaning the router always has to be operating. If it is always operating, then DHCP can be operating.

Things to Keep in Mind

  • Using a router for a DHCP server can be most effective in small- to medium-sized networks. However, if your business or network begins to expand, that means using more powerful hardware or a dedicated server.
  • A router's main objective is to route your packets. Implementing a DHCP server on a router can increase its workload. 
  • This lab utilizes a small topology, but you will see the commands and how you can implement it in a SOHO environment, whether it is a home lab or your business.

Let's Get Building

This topology uses:

  • 3 VLANS: Main, Guest, IoT
  • 1 Cisco 2960 IOS15 Switch
  • 1 Cisco 2911 Router

Step-by-Step Configuration for Each Device

Switch Configuration

Let's start by configuring the switches in the network. Repeat these steps for every switch you are configuring on your network.
  1. Enable the switch
    • To enter privileged exec mode type 
      enable 
      conf t
  2. Create your VLANs
    • There are three VLANs in this topology: Main, Guest, and IoT.
    • On the switch, create each VLAN:
      vlan {number} 
      name {VLAN name}
    • For example, to create the Main VLAN:
      vlan 10 
      name Main
  3. Assign VLANs to access ports
    • To assign VLANs to ports, you can use the int range command to configure multiple ports at once:
      int range {interface} 
      switchport mode access
      switchport access vlan {VLAN_ID}
    • To assign FastEthernet 0/1-0/5 to VLAN 10, use these commands:
      int range fa0/1-5 
      switchport mode access
      switchport access vlan 10
  4. Configure trunking to the router.
    • Trunking is used to group and send all VLAN traffic over a single link. Without it, specific VLAN traffic or perhaps none at all can be transferred between devices. 
    • Choose the interface that will connect to the router. This will serve as your trunk line.
    • Use the command:
      switchport mode trunk 
      exit
    • If you have certain VLANs you want to add to a trunk, use the command:
      switchport trunk allowed vlan add {VLAN number}
    • If you want to remove VLANs from a trunk, use the command:
      switchport trunk allowed vlan remove {VLAN number}

Router Configuration

Now for the main event—configuring the router as a DHCP server!
  1. Enable the router
    • To enter privileged exec mode, type:
      enable
      conf t
  2. Create subinterfaces
    • A subinterface, configured on a router interface, allows you to create mini-doors to reach individual networks or subnets. The trunk line from the switch to the router is connected to an interface. On that port, you create subinterfaces for each VLAN created. To create subinterfaces, type:
      int {interface}.{VLAN_ID number}
      For example to create a subinterface for VLAN 10 on GigabitEthernet 0/0, use these commands:
      int gig0/0.10
  3. Configure encapsulation
    • Encapsulation (802.1q) ensures that VLAN-tagged traffic is properly identified and routed between different VLANs over trunk links.
    • Imagine being at a convention. There are so many people, but your nametag identifies who you are, such as which group you are affiliated with. In this scenario, everyone in that convention center would represent all the data transferred over a trunk line. Your name tag represents the VLAN tag, which ensures data is correctly delivered to the right department (VLAN) without confusion.
    • To configure encapsulation, use these commands:
      encapsulation dot1q {VLAN_ID number} 
      ip address {IP Address} {subnet mask}
      exit
    • The IP address used for subinterfaces will be used as the default gateway for the VLANs.  
  4. DHCP Configuration
    • To configure DHCP on a router,
      service dhcp 
      ip dhcp pool {title}
      network {IP_ADDR} {SUBNET MASK}
    • The ip dhcp pool command allows you to create an IP address range that the router will use to distribute IP addresses to devices on a VLAN.
    • The network identifies the network ID and subnet mask, which identifies the IP address range - the scope of possible IP addresses that can be given to devices on a subnet.
  5. Configure a default router
    • You can configure your default router IP address to the subinterface IP address. To configure the default router,
    • default-router {IP_ADDR}
  6. Verification
    • On the router,
    • To view information on DHCP pools given to each VLAN, type
      show ip dhcp pool
    • To view devices' IP address, lease time, and DHCP configuration, type
      show ip dhcp binding

Conclusion

A properly configured DHCP server is important to automated distribution of IP addresses and other network configuration information.  Using a router to implement a DHCP server is most beneficial for small- to medium-sized networks, maximizing performance and resources. 

The commands used in this virtual lab can be used in a physical topology. To expand on this, I linked my repository containing the full topology, as depicted in the opening picture. I will also create a video going through the process. Using this can allow you to create your own topology, troubleshoot, and apply these steps to extend it further, especially including security features, such as DHCP snooping. What is DHCP snooping, and what are security measures used within DHCP? How can you prepare for DHCP troubleshooting? Stay tuned.

Have you tried setting up a DHCP server using a router? Share your experiences or challenges in the comments!

Helpful Links:



Comments

Popular posts from this blog

IP in Practice: IPv4 Workarounds

IPv4 has been dealing with burnout since 2011. Yet we work it to the ground by finding workarounds. Why? The Internet as we know it still runs on it. IPv6 is not as pervasive or widely accepted as IPv4 and often requires adding new infrastructure or reworking what is already in place. So far, the alternatives have extended the use of IPv4 beyond its intended design.  How have we continued to stretch IPv4? If you are studying networking, building a home lab, or managing large-scale networks, these techniques should ring a bell. This post will revisit four current IPv4 workarounds.  Workaround #1 - Private IP Addresses Instead of every server, device, and client getting their own public IP address and taking up space, private IP addresses provide reusable address spaces for local networks. These addresses are not directly accessible via the Internet. Routers will drop external traffic trying to directly access them.  To the outside world, only public IP addresses are...

IP in Practice: The Need for IPv6

 It is time for IPv6. Not just for our network infrastructure, but for this series. The IPv4 section has come to an end, and now it is time for a deep dive into IPv6. More than ever, it is time to consider systems that can handle heavier workloads, more devices, and fewer address limitations - AI agents, IoT devices, edge computing. This post will examine why we need IPv6 and why it is an important network solution.   Why do we need IPv6? We need more space. IPv6 literally increases the address space exponentially. The IPv6 address space is 2 128 total addresses, 3.4 followed by 38 zeroes. Technology is no longer limited to servers, office computers, and mobile devices. Today's systems integrate AI infrastructure, edge computing, IoT devices, cloud networking, virtual machines, and more. Simply, more devices mean more space.  We need more scalability. As more devices connect to systems, administrators need to consider not only the number but the distribution. System...

IP in Practice: Classless Addressing & Subnetting

 In the previous posts, we looked at what an IPv4 address is and how it is used.  Subnetting builds on that foundation and plays a major role in IP addressing, but many learners find it challenging at first.I was in the same boat at first. Now, it is a breeze. What has helped me, and how can you fly through subnetting? In this post, we will specifically focus on how classless addressing and variable length subnet masking is implemented within networks. If you would like to learn more about subnetting or need a refresher, see my other posts Subnets: Key to Network Organization   and Subnetting Tips .    Classful vs Classless What's the difference between these two addressing schemes? Let me ask you this: Have you ever tried on clothes and never could find the right size? It is too big or too small. The store doesn't have your size. What if you can get it tailor-made just for you?  Now imagine you could design a subnet the same way you design a custom sh...