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

Is MCP the TCP/IP for AI?

  The Internet runs on TCP/IP. We might as well include AI in the mix, but how about AI? TCP/IP allows devices, services, applications, and data to communicate with other devices, services, applications, and data. How does AI talk? This is why I love networking, and the thought of how AI communicates makes me hopeful that the field will survive extensive job replacements. Unless self-healing networks actually come.  I have been reading more into MCP. What exactly is it? Is it necessary for AI models and agents to communicate? Did you know AI agents have their own social media?? Biggest of all, is there any correlation between MCP and TCP/IP for model communication? Can MCP take notes from TCP/IP, or will it rewrite networking? This post explores Model Context Protocol through parallels with TCP/IP to understand how AI communication can become more structured, standardized, and consistent. What is MCP? To understand MCP, a good place to start is APIs. To understand APIs,...

IP in Practice: Public and Private IP Addresses

Do you speak another language? Personally, I love learning new languages, but one of the hardest parts is translation. When it comes to networking, it is something similar. Devices within our home and office networks do not directly go to the internet. There needs to be a "translator". What does this have to do with public and private IPv4 addresses? In this post, we will explore: IPv4 Addresses Private Ranges  The difference and teamwork between NAT and PAT Helpful troubleshooting commands such as ipconfig or ping A demo that puts it altogether.  (Link to topology here .) By the end of this post, you will see how public and private IP addresses work together in action.  IPv4 Address Private Ranges RFC1918 Private IP Address Ranges Class IANA Blocks Range Total Addresses A 10.0.0.0/8 10.0.0.0 - 10.255.255.255 16.7 million (16,777,216) ...

A Nesting Doll of Networks: Types of Networks

  PAN, WAN, MAN, LAN, CAN - what is up with all these rhyming words? As fun it us to relive kindergarten, these are acronyms for the types of networks that exist today. Think of them as digital nesting dolls: PANs can be found in LANs, LANs make up our WANs, and there is more in between. Let's take a closer look at these networking nesting dolls. Personal Area Networks (PANs) Have you ever grown frustrated at how your Bluetooth headphones seem to take forever to pair to your phone? Do you use a wired mouse or a wireless mouse with your desktop? Do you "tap to pay"? These are examples of personal area networks.  A personal area network connects devices close in range, from a few centimeters to a few meters. These types of networks can be wired or wireless.  A wired PAN may be a computer connected to a printer by a USB cable or Ethernet cable.  A wireless PAN may use communication methods, such as Bluetooth, infrared, or radio waves. Think of your wireless Bluetooth ea...