In Figure 1, Switch_1 functions as a DHCP client and needs to dynamically obtain an IP address, DNS server address, and gateway address from a DHCP server (Switch_2).
# Create VLAN 10 and add GE0/0/1 to VLAN 10.
<HUAWEI> system-view [HUAWEI] sysname Switch_1 [Switch_1] vlan 10 [Switch_1-vlan10] quit [Switch_1] interface gigabitethernet 0/0/1 [Switch_1-GigabitEthernet0/0/1] port link-type trunk [Switch_1-GigabitEthernet0/0/1] port trunk allow-pass vlan 10 [Switch_1-GigabitEthernet0/0/1] quit
# Enable the DHCP client function on VLANIF 10.
[Switch_1] interface vlanif 10 [Switch_1-Vlanif10] ip address dhcp-alloc [Switch_1-Vlanif10] quit
# Run the display this command on VLANIF 10 of Switch_1 to view the DHCP client configuration.
[Switch_1] interface vlanif 10 [Switch_1-Vlanif10] display this # interface Vlanif10 ip address dhcp-alloc # return
# After VLANIF 10 obtains an IP address, run the display dhcp client command on Switch_1 to view the status of the DHCP client on VLANIF 10.
[Switch_1] display dhcp client DHCP client lease information on interface Vlanif10 : Current machine state : Bound Internet address assigned via : DHCP Physical address : 0025-9efb-be55 IP address : 192.168.1.254 Subnet mask : 255.255.255.0 Gateway ip address : 192.168.1.126 DHCP server : 192.168.1.1 Lease obtained at : 2014-09-10 20:30:39 Lease expires at : 2014-09-11 20:30:39 Lease renews at : 2014-09-11 08:30:39 Lease rebinds at : 2014-09-11 17:30:39 DNS : 192.168.1.2
# On Switch_2, 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.
[Switch_2] display ip pool name pool1 Pool-name : pool1 Pool-No : 0 Lease : 1 Days 0 Hours 0 Minutes Domain-name : - DNS-server0 : 192.168.1.2 NBNS-server0 : - Netbios-type : - Position : Local Status : Unlocked Gateway-0 : 192.168.1.126 Network : 192.168.1.0 Mask : 255.255.255.0 VPN instance : -- Logging : Disable Conflicted address recycle interval: - Address Statistic: Total :253 Used :1 Idle :251 Expired :0 Conflict :0 Disabled :1 ------------------------------------------------------------------------------- Network section Start End Total Used Idle(Expired) Conflict Disabled ------------------------------------------------------------------------------- 192.168.1.1 192.168.1.254 253 1 251(0) 0 1 -------------------------------------------------------------------------------
Switch_1 configuration file
#
sysname Switch_1
#
vlan batch 10
#
interface Vlanif10
ip address dhcp-alloc
#
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 10
#
return
Switch_2 configuration file
#
sysname Switch_2
#
vlan batch 10
#
dhcp enable
#
ip pool pool1
gateway-list 192.168.1.126
network 192.168.1.0 mask 255.255.255.0
excluded-ip-address 192.168.1.2
dns-list 192.168.1.2
#
interface Vlanif10
ip address 192.168.1.1 255.255.255.0
dhcp select global
#
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 10
#
return