< Home

Example for Configuring a DHCP Relay Agent (DHCP Relay Agent and DHCP Server on the Same Network)

Networking Requirements

In Figure 1, SwitchB functions as a DHCP server and resides on a different network segment from DHCP clients. In this networking example, the enterprise wants the DHCP server to dynamically allocate IP addresses to its clients.

Figure 1 Networking diagram for configuring a device as a DHCP relay agent

Configuration Roadmap

The configuration roadmap is as follows:

Configure SwitchA as a DHCP relay agent to forward DHCP messages between the DHCP server and clients.

Procedure

  1. Configure DHCP relay on SwitchA.

    # Add interfaces to VLANs.

    <HUAWEI> system-view
    [HUAWEI] sysname SwitchA
    [SwitchA] vlan batch 100 200
    [SwitchA] interface gigabitethernet 0/0/2
    [SwitchA-GigabitEthernet0/0/2] port link-type hybrid
    [SwitchA-GigabitEthernet0/0/2] port hybrid pvid vlan 100
    [SwitchA-GigabitEthernet0/0/2] port hybrid untagged vlan 100
    [SwitchA-GigabitEthernet0/0/2] quit
    [SwitchA] interface gigabitethernet 0/0/1
    [SwitchA-GigabitEthernet0/0/1] port link-type hybrid
    [SwitchA-GigabitEthernet0/0/1] port hybrid pvid vlan 200
    [SwitchA-GigabitEthernet0/0/1] port hybrid untagged vlan 200
    [SwitchA-GigabitEthernet0/0/1] quit
    [SwitchA] interface vlanif 200 
    [SwitchA-Vlanif200] ip address 10.10.20.1 24
    [SwitchA-Vlanif200] quit
    

    # Enable the DHCP relay function on VLANIF 100.

    [SwitchA] dhcp enable
    [SwitchA] interface vlanif 100
    [SwitchA-Vlanif100] ip address 10.20.20.1 24
    [SwitchA-Vlanif100] dhcp select relay 
    [SwitchA-Vlanif100] dhcp relay server-ip 10.10.20.2
    [SwitchA-Vlanif100] quit

  2. Configure a default route on SwitchA.

    [SwitchA] ip route-static 0.0.0.0 0.0.0.0 10.10.20.2
    

  3. Configure SwitchB as the DHCP server based on the global address pool.

    # Enable DHCP.

    <HUAWEI> system-view
    [HUAWEI] sysname SwitchB
    [SwitchB] dhcp enable

    # Configure VLANIF 200 to work in global address pool mode.

    [SwitchB] vlan 200 
    [SwitchB-vlan200] quit
    [SwitchB] interface gigabitethernet 0/0/1
    [SwitchB-GigabitEthernet0/0/1] port link-type hybrid
    [SwitchB-GigabitEthernet0/0/1] port hybrid pvid vlan 200
    [SwitchB-GigabitEthernet0/0/1] port hybrid untagged vlan 200
    [SwitchB-GigabitEthernet0/0/1] quit
    [SwitchB] interface vlanif 200 
    [SwitchB-Vlanif200] ip address 10.10.20.2 24
    [SwitchB-Vlanif200] dhcp select global
    [SwitchB-Vlanif200] quit

    # Create an address pool and set attributes for the address pool.

    [SwitchB] ip pool pool1
    [SwitchB-ip-pool-pool1] network 10.20.20.0 mask 24
    [SwitchB-ip-pool-pool1] gateway-list 10.20.20.1
    [SwitchB-ip-pool-pool1] option121 ip-address 10.10.20.0 24 10.20.20.1
    [SwitchB-ip-pool-pool1] quit

  4. Configure a static route on SwitchB.

    [SwitchB] ip route-static 10.20.20.0 255.255.255.0 10.10.20.1
    

  5. Verify the configuration.

    # On SwitchA, run the display dhcp relay interface vlanif 100 command to view the configuration of the DHCP relay agent.

    [SwitchA] 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
    

    # On SwitchB, run the display ip pool name pool1 command to view IP address allocation in the address pool. The Used field displays the number of used IP addresses in the address pool.

    [SwitchB] 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   : 18640A1414141401
      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        :2
                         Idle        :251       Expired     :0
                         Conflict    :0         Disabled     :0
                                                                                    
     -------------------------------------------------------------------------------
      Network section
             Start           End       Total    Used Idle(Expired) Conflict Disabled
     -------------------------------------------------------------------------------
          10.20.20.1    10.20.20.254     253       2        251(0)       0     0
     -------------------------------------------------------------------------------

Configuration Files

  • SwitchA configuration file

    #
    sysname SwitchA
    #
    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 GigabitEthernet0/0/1
     port link-type hybrid
     port hybrid pvid vlan 200
     port hybrid untagged vlan 200
    #
    interface GigabitEthernet0/0/2
     port link-type hybrid
     port hybrid pvid vlan 100
     port hybrid untagged vlan 100
    #
    ip route-static 0.0.0.0 0.0.0.0 10.10.20.2
    #
    return
  • SwitchB configuration file

    #
    sysname SwitchB
    #
    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 GigabitEthernet0/0/1
     port link-type hybrid
     port hybrid pvid vlan 200
     port hybrid untagged vlan 200
    #
    ip route-static 10.20.20.0 255.255.255.0 10.10.20.1
    #
    return
Copyright © Huawei Technologies Co., Ltd.
Copyright © Huawei Technologies Co., Ltd.
< Previous topic Next topic >