DHCP Server for multiple VLANs

DHCP Server for multiple VLANs

Topology

In our topology, we have:

  • One DHCP server (configured on the router) in which two DHCP Pools are defined: one for the VLAN10 subnet and another one for VLAN 20 subnet.
  • 2 Clients: client 1 in VLAN 10 and client 2 in VLAN 20.


DHCP Configuration

Below is the basic configuration on the DHCP server (router):

  • We define 2 sub-interface that serve as gateways for the Vlans
  • 2 DHCP pools: VLAN_10 and VLAN_20
  • We excluded the gateway addresses to avoid overlap with the DHCP Pool range.
interface Ethernet0/0.10
 encapsulation dot1Q 10
 ip address 192.168.10.254 255.255.255.0
!
interface Ethernet0/0.20
 encapsulation dot1Q 20
 ip address 192.168.20.254 255.255.255.0

ip dhcp pool VLAN_10
 network 192.168.10.0 255.255.255.0
!
ip dhcp pool VLAN_20
 network 192.168.20.0 255.255.255.0

ip dhcp excluded-address 192.168.10.254
ip dhcp excluded-address 192.168.20.254

The switch is L2 where VLAN 10 and VLAN 20 are defined:

interface Ethernet0/0
 switchport trunk encapsulation dot1q
 switchport mode trunk
 duplex auto
!
interface Ethernet0/1
 switchport access vlan 10
 switchport mode access
 duplex auto
!
interface Ethernet0/2
 switchport access vlan 20
 switchport mode access
 duplex auto


DHCP Debug and Verification


Now, we will configure Client_VLAN10 for DHCP, meanwhile, DHCP debug is running on the DHCP Server (router):

*Oct 22 21:21:35.227: DHCPD: client's VPN is .
*Oct 22 21:21:35.232: DHCPD: No option 125
*Oct 22 21:21:35.233: DHCPD: Sending notification of DISCOVER:
*Oct 22 21:21:35.233:   DHCPD: htype 1 chaddr aabb.cc01.b000
*Oct 22 21:21:35.233:   DHCPD: remote id 020a0000c0a80afe0000000a
*Oct 22 21:21:35.233:   DHCPD: circuit id 00000000
*Oct 22 21:21:35.235: DHCPD: DHCPDISCOVER received from client 0063.6973.636f on interface Ethernet0/0.10.
*Oct 22 21:21:35.235: DHCPD: Seeing if there is an internally specified pool class:
*Oct 22 21:21:35.235:   DHCPD: htype 1 chaddr aabb.cc01.b000
Router#
*Oct 22 21:21:35.235:   DHCPD: remote id 020a0000c0a80afe0000000a
*Oct 22 21:21:35.235:   DHCPD: circuit id 00000000
*Oct 22 21:21:35.237: DHCPD: Allocate an address without class information (192.168.10.0)
*Oct 22 21:21:35.239: DHCPD: Allocated binding C54A04A8
*Oct 22 21:21:35.239: DHCPD: Adding binding to radix tree (192.168.10.3)
*Oct 22 21:21:35.239: DHCPD: Adding binding to hash tree
*Oct 22 21:21:35.239: DHCPD: assigned IP address 192.168.10.3 to client 0063.6973.636f
*Oct 22 21:21:35.239: DHCPD: Saving workspace (ID=0xA5000008)

*Oct 22 21:21:37.253: DHCPD: Sending DHCPOFFER to client 0063.6973.636f (192.168.10.3).
DHCPD: Setting only requested parameters

*Oct 22 21:21:37.254: DHCPD: child  pool: 192.168.10.0 / 255.255.255.0 (VLAN_10)
*Oct 22 21:21:37.254: DHCPD: pool VLAN_10 has no parent.

*Oct 22 21:21:37.255: DHCPD: broadcasting BOOTREPLY to client aabb.cc01.b000.
*Oct 22 21:21:37.262: DHCPD: New packet workspace 0xC651E8C0 (ID=0x20000009)

*Oct 22 21:21:37.262: DHCPD: DHCPREQUEST received from client 0063.6973.636f
*Oct 22 21:21:37.262: DHCPD: Sending notification of ASSIGNMENT:
*Oct 22 21:21:37.262:  DHCPD: address 192.168.10.3 mask 255.255.255.0
*Oct 22 21:21:37.262:   DHCPD: htype 1 chaddr aabb.cc01.b000
*Oct 22 21:21:37.262:   DHCPD: lease time remaining (secs) = 86400
*Oct 22 21:21:37.263: DHCPD: No default domain to append - abort update
*Oct 22 21:21:37.263: DHCPD: Sending DHCPACK to client 0063.6973.636f (192.168.10.3).
DHCPD: Setting only requested parameters

We can verify that the Client_VLAN10 has received an IP address from the correct pool:

Client_VLAN10#show ip int brief
Interface                  IP-Address      OK? Method Status                Protocol
Ethernet0/0                192.168.10.3    YES DHCP   up                    up


We will do the same with the VLAN20 client, we configure it to receive the address via DHCP and turn on debug on the DHCP server:

*Oct 23 19:22:27.482: DHCPD: Sending notification of DISCOVER:
*Oct 23 19:22:27.482:   DHCPD: htype 1 chaddr aabb.cc01.a000
*Oct 23 19:22:27.482:   DHCPD: remote id 020a0000c0a814fe00000014
*Oct 23 19:22:27.482:   DHCPD: circuit id 00000000
*Oct 23 19:22:27.483: DHCPD: DHCPDISCOVER received from client 0063.6973.636f. on interface Ethernet0/0.20.
*Oct 23 19:22:27.483: DHCPD: Seeing if there is an internally specified pool class:
*Oct 23 19:22:27.483:   DHCPD: htype 1 chaddr aabb.cc01.a000

*Oct 23 19:22:27.484: DHCPD: Allocate an address without class information (192.168.20.0)
*Oct 23 19:22:27.486: DHCPD: Allocated binding C5DAEE20
*Oct 23 19:22:27.486: DHCPD: Adding binding to radix tree (192.168.20.6)
*Oct 23 19:22:27.486: DHCPD: Adding binding to hash tree
*Oct 23 19:22:27.486: DHCPD: assigned IP address 192.168.20.6 to client 0063.6973.636f
*Oct 23 19:22:27.486: DHCPD: Saving workspace (ID=0x20000009)

*Oct 23 19:22:29.508: DHCPD: Sending DHCPOFFER to client 0063.6973.636f (192.168.20.6).DHCPD: Setting only requested parameters
*Oct 23 19:22:29.509: DHCPD: child  pool: 192.168.20.0 / 255.255.255.0 (VLAN_20)
*Oct 23 19:22:29.509: DHCPD: pool VLAN_20 has no parent.

*Oct 23 19:22:29.510: DHCPD: broadcasting BOOTREPLY to client aabb.cc01.a000.
*Oct 23 19:22:29.515: DHCPD: New packet workspace 0xC651E8C0 (ID=0x6500000A)

*Oct 23 19:22:29.515: DHCPD: DHCPREQUEST received from client 0063.6973.636f
*Oct 23 19:22:29.515: DHCPD: Sending notification of ASSIGNMENT:
*Oct 23 19:22:29.515:  DHCPD: address 192.168.20.6 mask 255.255.255.0
*Oct 23 19:22:29.515:   DHCPD: htype 1 chaddr aabb.cc01.a000
*Oct 23 19:22:29.515:   DHCPD: lease time remaining (secs) = 86400
*Oct 23 19:22:29.516: DHCPD: No default domain to append - abort update
*Oct 23 19:22:29.516: DHCPD: Sending DHCPACK to client 0063.6973.636f (192.168.20.6).DHCPD: Setting only requested parameters

*Oct 23 19:22:32.540: %DHCP-6-ADDRESS_ASSIGN: Interface Ethernet0/0 assigned DHCP 
address 192.168.20.6, mask 255.255.255.0, hostname

Client_VLAN20#sh ip int brief
Interface                  IP-Address      OK? Method Status                Protocol
Ethernet0/0                192.168.20.6    YES DHCP   up                    up


How Vlans are assigned an IP address from the correct DHCP Pool


So, you may be asking how each Vlan is assigned to the correct DHCP Pool, we will answer this according to the DHCP Debug:

First of all, The DHCP client (VLAN 10 or VLAN 20) broadcasts a DHCP Discover and DHCP Request for an IP address and additional configuration parameters on its local LAN: Client_VLAN10 broadcasts in VLAN 10, and Client_VLAN20 broadcasts in VLAN 20

When the DHCP server (router in our case, also can be a switch or dedicated server) receive the request on its sub-interfaces, the DHCP Server will know from what DHCP Pool it should use to assign an address to the client.

As an example, when VLAN 10 sends a DHCP Discover, it will be broadcasted on VLAN 10, and as a result, it will be received on the sub-interface Ethernet0/0.10 of the DHCP server. The sub-interface Ethernet0/0.10 has an IP Address of 192.168.10.254/24.

The DHCP server will check the DHCP pool that matches the subnet of the interface on which DHCP Discover was received and finds pool VLAN_10 with a matching network 192.168.10.0/24. Finally, it will assign the client an available IP address from the Pool and send it in the DHCP OFFER (along with other parameters of the DHCP pool).


Note

The same process will happen if the DHCP server is an L3 switch (by matching the interface VLAN subnet) or on a dedicated Server. It will match the IP address subnet of the interface on which the Request was received.


DHCP server on a different network?

In this post, we have discussed the case when the DHCP server resides on the L2 segment (same broadcast domain) of the DHCP client. When the DHCP server is in a different network, a Relay Agent is needed.

Please refer to the following post for the DHCP Relay use case.

Bilel

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x