Example for Configuring the Device as a DHCP Relay (Relay and Server Are Located on the Same Network)
Networking Requirements
As shown in Figure 3-15, the DHCP server is deployed on the core device of an enterprise, and is not located on the same network segment with the enterprise's terminals. The enterprise requires that this DHCP server should dynamically allocate IP addresses for the terminals.
Configuration Roadmap
- Configure the DHCP relay function on the aggregation device RouterA (user gateway) so that the device functions as the DHCP relay to forward the DHCP messages between the terminals and DHCP server.
- On the core device RouterB, configure the DHCP server based on the global address pool so that the DHCP server allocates the IP addresses from the global address pool to the terminals.
A RouterIndustrial Switch Router is used as an example of the DHCP server (RouterB).
Configure the interface link type and VLANs on the LSW to implement Layer 2 communication.
Procedure
- Configure the DHCP relay function on RouterA.
# Add interfaces to VLANs.
<Huawei> system-view [Huawei] sysname RouterA [RouterA] vlan batch 100 200 [RouterA] interface ethernet 2/0/1 [RouterA-Ethernet2/0/1] port link-type access [RouterA-Ethernet2/0/1] port default vlan 100 [RouterA-Ethernet2/0/1] quit [RouterA] interface ethernet 2/0/0 [RouterA-Ethernet2/0/0] port link-type trunk [RouterA-Ethernet2/0/0] port trunk allow-pass vlan 200 [RouterA-Ethernet2/0/0] quit [RouterA] interface vlanif 200 [RouterA-Vlanif200] ip address 10.10.20.1 24 [RouterA-Vlanif200] quit
# Enable the DHCP relay function on the interface.
[RouterA] dhcp enable [RouterA] interface vlanif 100 [RouterA-Vlanif100] ip address 10.20.20.1 24 [RouterA-Vlanif100] dhcp select relay [RouterA-Vlanif100] dhcp relay server-ip 10.10.20.2 [RouterA-Vlanif100] quit
- Configure the default route on RouterA.
[RouterA] ip route-static 0.0.0.0 0.0.0.0 10.10.20.2
- Configure the DHCP server function based on the global IP address pool on RouterB.
# Enable DHCP.
<Huawei> system-view [Huawei] sysname RouterB [RouterB] dhcp enable
# Configure VLANIF 200 to work in global address pool mode.
[RouterB] vlan 200 [RouterB-vlan200] quit [RouterB] interface ethernet 2/0/0 [RouterB-Ethernet2/0/0] port link-type trunk [RouterB-Ethernet2/0/0] port trunk allow-pass vlan 200 [RouterB-Ethernet2/0/0] quit [RouterB] interface vlanif 200 [RouterB-Vlanif200] ip address 10.10.20.2 24 [RouterB-Vlanif200] dhcp select global [RouterB-Vlanif200] quit
# Create an address pool and set the attributes of the address pool.
[RouterB] ip pool pool1 [RouterB-ip-pool-pool1] network 10.20.20.0 mask 24 [RouterB-ip-pool-pool1] gateway-list 10.20.20.1 [RouterB-ip-pool-pool1] option121 ip-address 10.10.20.0 24 10.20.20.1 [RouterB-ip-pool-pool1] quit
- Configure the default route on RouterB.
[RouterB] ip route-static 0.0.0.0 0.0.0.0 10.10.20.1
- Verify the configuration.
# Run the display dhcp relay interface vlanif 100 command on RouterA to view the DHCP relay configuration.
[RouterA] display dhcp relay interface vlanif 100 DHCP relay agent running information of interface Vlanif100 : Server IP address [00] : 10.10.20.2 Gateway address in use : 10.20.20.1
# Run the display ip pool name pool1 command on RouterB to view the allocation of the address pool. The Used field indicates the number of allocated IP addresses.
[RouterB] display ip pool name pool1 Pool-name : pool1 Pool-No : 0 Lease : 1 Days 0 Hours 0 Minutes Domain-name : - Option-code : 121 Option-subcode : -- Option-type : hex Option-value : 180A0A140A141401 DNS-server0 : - NBNS-server0 : - Netbios-type : - Position : Local Status : Unlocked Gateway-0 : 10.20.20.1 Network : 10.20.20.0 Mask : 255.255.255.0 VPN instance : -- Logging : Disable Conflicted address recycle interval: - Address Statistic: Total :253 Used :1 Idle :252 Expired :0 Conflict :0 Disable :0 ------------------------------------------------------------------------------- Network section Start End Total Used Idle(Expired) Conflict Disabled ------------------------------------------------------------------------------- 10.20.20.1 10.20.20.254 253 1 252(0) 0 0 -------------------------------------------------------------------------------
Configuration Files
RouterA configuration file
# sysname RouterA # vlan batch 100 200 # dhcp enable # interface Vlanif100 ip address 10.20.20.1 255.255.255.0 dhcp select relay dhcp relay server-ip 10.10.20.2 # interface Vlanif200 ip address 10.10.20.1 255.255.255.0 # interface Ethernet2/0/0 port link-type trunk port trunk allow-pass vlan 200 # interface Ethernet2/0/1 port link-type access port default vlan 100 # ip route-static 0.0.0.0 0.0.0.0 10.10.20.2 # return
RouterB configuration file
# sysname RouterB # vlan batch 200 # dhcp enable # ip pool pool1 gateway-list 10.20.20.1 network 10.20.20.0 mask 255.255.255.0 option121 ip-address 10.10.20.0 24 10.20.20.1 # interface Vlanif200 ip address 10.10.20.2 255.255.255.0 dhcp select global # interface Ethernet2/0/0 port link-type trunk port trunk allow-pass vlan 200 # ip route-static 0.0.0.0 0.0.0.0 10.10.20.1 # return