In this example, I'm using the Cisco 1921 router with IOS version 15 to configure a DHCP server. The same procedure applies to other models with IOS 12 and 15.
One of the first steps when configuring a router is assigning an IP address to the physical interfaces. The Cisco 1921 router has two GigabitEthernet interfaces; in this example, I will only configure one interface, the one on our LAN network. Let's assume the network we want to configure is 192.168.1.0/24, and we want to use Google’s DNS address 8.8.8.8.
I’ll only abbreviate interface names; commands will be written in full.
The following commands assign an IP address to the g0/0 interface and power it up.
Router> enable
Router# configure terminal
Router(config)# interface g0/0
Router(config-if)# ip address 192.168.1.1 255.255.255.0
Router(config-if)# no shutdown
Router(config-if)# exit
Router(config)#
Now let's get into the core part: the DHCP server.
The following commands define an IP address pool named HOMENET that the DHCP server will lease to devices connecting to the 192.168.1.0/24 network, excluding the address assigned to the router’s physical interface.
Router(config)# ip dhcp excluded-address 192.168.1.1
Router(config)# ip dhcp pool HOMENET
Router(dhcp-config)# network 192.168.1.0 255.255.255.0
Router(dhcp-config)# default-router 192.168.1.1
Router(dhcp-config)# dns-server 8.8.8.8
Router(dhcp-config)# exit
Router(config)#
To exclude a range of IP addresses, write it like this:
ip dhcp excluded-address 192.168.1.1 192.168.10
To verify our DHCP server configuration and see which devices have been assigned IP addresses, we can use the following commands:
Router(config)# end
Router# show running-config | section dhcp
Router# show ip dhcp binding
The following command is used to enable or disable the DHCP service.
Router(config)# no service dhcp
Router(config)# service dhcp
In the case of VLANs, only the default-router
changes for each pool since it must point to the IP address of the VLAN gateway.
In this scenario, VLAN gateways are the router’s sub-interfaces, and their addresses will be used. Let’s take a topology with two VLANs as an example: vlan 10 for network 192.168.10.0/24 and vlan 20 for network 192.168.20.0/24, and their router sub-interfaces are named g0/0.10 with IP 192.168.10.1 and g0/0.20 with IP 192.168.20.1
Router(config)# ip dhcp excluded-address 192.168.10.1
Router(config)# ip dhcp excluded-address 192.168.20.1
Router(config)# ip dhcp pool POOL10
Router(dhcp-config)# network 192.168.10.0 255.255.255.0
Router(dhcp-config)# default-router 192.168.10.1
Router(dhcp-config)# dns-server 8.8.8.8
Router(dhcp-config)# exit
Router(config)# ip dhcp pool POOL20
Router(dhcp-config)# network 192.168.20.0 255.255.255.0
Router(dhcp-config)# default-router 192.168.20.1
Router(dhcp-config)# dns-server 8.8.8.8
Router(dhcp-config)# exit
Router(config)#
Here, we use a Layer 3 switch (multilayer switch) to perform inter-VLAN routing. DHCP server configuration is exactly the same as in the previous case. The only difference is that the interfaces acting as VLAN gateways are SVI (Switch Virtual Interfaces), configured on the switch. In such topologies, the Layer 3 switch typically acts as the DHCP server.
In some topologies, the router acting as the DHCP server is not the same as the gateway router for the LAN. In this case, we must inform the gateway router where to forward DHCP requests by specifying the IP address of the DHCP server.
Let’s reuse our previous network example and assume that our router 192.168.1.1, which we'll call R1, is not a DHCP server, and the DHCP server is configured on a second router, R2, connected to R1 via an interface with IP address 172.16.1.1
We need to inform R1 to forward DHCP requests to R2. R1’s g0/0 interface is the one facing our LAN and will receive the DHCP requests first, so we’ll configure the redirection on that interface using the ip helper-address
command.
Router(config)# interface g0/0
Router(config-if)# ip helper-address 172.16.1.1
When we have a topology with VLANs, the ip-helper
command is used on the router’s sub-interfaces, not the main interface. If we have a Layer 3 switch, the command is applied on the VLAN interfaces.
Router(config)# interface g0/0.10
Router(config-if)# ip helper-address 192.168.10.1
Router(config-if)#exit
Router(config)# interface g0/0.20
Router(config-if)# ip helper-address 192.168.20.1
Router(config)# interface vlan 10
Router(config-if)# ip helper-address 192.168.10.1
Router(config-if)#exit
Router(config)# interface vlan 20
Router(config-if)# ip helper-address 192.168.20.1