Example for Configuring a DHCP Server (Based on an Interface Address Pool)
Networking Requirements
In Figure 3-10, an enterprise plans two network segments for office terminals: 10.1.1.0/24 for fixed terminals and 10.1.2.0/24 for terminals used by staff on business trips. To facilitate unified management, the enterprise requires terminals to automatically obtain IP addresses and the DNS server IP address from the Switch (if users access the Internet using domain names, a DNS server must be specified). A PC (DHCP Client_1) requires fixed IP address 10.1.1.100/24 to meet service requirements.
Configuration Roadmap
The configuration roadmap is as follows:
- Configure the switch as a DHCP server to dynamically allocate IP addresses on the two network segments and the DNS server IP address to enterprise terminals.
- Allocate IP addresses on 10.1.1.0/24 to fixed terminals and set the lease time of these IP addresses to 30 days.
- Statically allocate the fixed IP address 10.1.1.100/24 to DHCP Client_1.
- Allocate IP addresses on 10.1.2.0/24 to terminals used by staff on business trips and set the lease time of these IP addresses to two days.
Procedure
- Enable DHCP.
<HUAWEI> system-view [HUAWEI] sysname Switch [Switch] dhcp enable
- Add interfaces to VLANs.
# Add GE1/0/1 to VLAN 10.
[Switch] vlan batch 10 to 11 [Switch] interface gigabitethernet 1/0/1 [Switch-GigabitEthernet1/0/1] port link-type hybrid [Switch-GigabitEthernet1/0/1] port hybrid pvid vlan 10 [Switch-GigabitEthernet1/0/1] port hybrid untagged vlan 10 [Switch-GigabitEthernet1/0/1] quit
# Add GE1/0/2 to VLAN 11.
[Switch] interface gigabitethernet 1/0/2 [Switch-GigabitEthernet1/0/2] port link-type hybrid [Switch-GigabitEthernet1/0/2] port hybrid pvid vlan 11 [Switch-GigabitEthernet1/0/2] port hybrid untagged vlan 11 [Switch-GigabitEthernet1/0/2] quit
- Configure IP addresses for VLANIF interfaces.
# Configure an IP address for VLANIF 10.
[Switch] interface vlanif 10 [Switch-Vlanif10] ip address 10.1.1.1 24 [Switch-Vlanif10] quit
# Configure an IP address for VLANIF 11.
[Switch] interface vlanif 11 [Switch-Vlanif11] ip address 10.1.2.1 24 [Switch-Vlanif11] quit
- Configure interface address pools.
# Configure the clients connected to VLANIF 10 to obtain IP addresses and other network parameters from the address pool on VLANIF 10.
[Switch] interface vlanif 10 [Switch-Vlanif10] dhcp select interface [Switch-Vlanif10] dhcp server gateway-list 10.1.1.1 [Switch-Vlanif10] dhcp server lease day 30 [Switch-Vlanif10] dhcp server domain-name example.com [Switch-Vlanif10] dhcp server dns-list 10.1.3.1 [Switch-Vlanif10] dhcp server static-bind ip-address 10.1.1.100 mac-address 00e0-fc12-3456 [Switch-Vlanif10] quit
# Configure the clients connected to VLANIF 11 to obtain IP addresses and other network parameters from the address pool on VLANIF 11.
[Switch] interface vlanif 11 [Switch-Vlanif11] dhcp select interface [Switch-Vlanif11] dhcp server gateway-list 10.1.2.1 [Switch-Vlanif11] dhcp server lease day 2 [Switch-Vlanif11] dhcp server domain-name example.com [Switch-Vlanif11] dhcp server dns-list 10.1.3.1 [Switch-Vlanif11] quit
- Enable the device to save DHCP data to the storage device. If a fault occurs on the device, you can run the dhcp server database recover command after the system restarts to restore DHCP data from files on the storage device.
[Switch] dhcp server database enable
- Verify the configuration.
# On the switch, run the display ip pool command to view IP address allocation in address pools. The Used field displays the number of used IP addresses in the address pool. For example, the enterprise has 100 employees with fixed office terminals and 3 employees on business trips.
[Switch] display ip pool interface vlanif10 Pool-name : Vlanif10 Pool-No : 0 Lease : 30 Days 0 Hours 0 Minutes Domain-name : example.com DNS-server0 : 10.1.3.1 NBNS-server0 : - Netbios-type : - Position : Interface Status : Unlocked Gateway-0 : 10.1.1.1 Network : 10.1.1.0 Mask : 255.255.255.0 VPN instance : -- Logging : Disable Conflicted address recycle interval: - Address Statistic: Total :253 Used :100 Idle :153 Expired :0 Conflict :0 Disabled :0 ------------------------------------------------------------------------------- Network section Start End Total Used Idle(Expired) Conflict Disabled ------------------------------------------------------------------------------- 10.1.1.1 10.1.1.254 253 100 153(0) 0 0 -------------------------------------------------------------------------------
[Switch] display ip pool interface vlanif11 Pool-name : Vlanif11 Pool-No : 1 Lease : 2 Days 0 Hours 0 Minutes Domain-name : example.com DNS-server0 : 10.1.3.1 NBNS-server0 : - Netbios-type : - Position : Interface Status : Unlocked Gateway-0 : 10.1.2.1 Network : 10.1.2.0 Mask : 255.255.255.0 VPN instance : -- Logging : Disable Conflicted address recycle interval: - Address Statistic: Total :253 Used :3 Idle :250 Expired :0 Conflict :0 Disabled :0 ------------------------------------------------------------------------------- Network section Start End Total Used Idle(Expired) Conflict Disabled ------------------------------------------------------------------------------- 10.1.1.1 10.1.1.254 253 3 250(0) 0 0 -------------------------------------------------------------------------------
Check IP address information on Client_1 (using Windows 7 operating system). The IP address 10.1.1.100/24 has been assigned to Client_1.
C:\Documents and Settings\Administrator>ipconfig Windows IP Configuration Ethernet adapter Local Area Connection 2: Connection-specific DNS Suffix . : IPv4 Address. . . . . . . . . . . : 10.1.1.100 Subnet Mask . . . . . . . . . . . : 255.255.254.0 Default Gateway . . . . . . . . . : 10.1.1.1
Check IP address information another DHCP client (for example, a terminal belonging to the network segment 10.1.1.0/24 and using Windows 7 operating system). An IP address has been assigned.
C:\Documents and Settings\Administrator>ipconfig Windows IP Configuration Ethernet adapter Local Area Connection 2: Connection-specific DNS Suffix . : IPv4 Address. . . . . . . . . . . : 10.1.1.51 Subnet Mask . . . . . . . . . . . : 255.255.254.0 Default Gateway . . . . . . . . . : 10.1.1.1
Configuration Files
Switch configuration file
# sysname Switch # vlan batch 10 to 11 # dhcp enable # dhcp server database enable # interface Vlanif10 ip address 10.1.1.1 255.255.255.0 dhcp select interface dhcp server gateway-list 10.1.1.1 dhcp server static-bind ip-address 10.1.1.100 mac-address 00e0-fc12-3456 dhcp server lease day 30 hour 0 minute 0 dhcp server dns-list 10.1.3.1 dhcp server domain-name example.com # interface Vlanif11 ip address 10.1.2.1 255.255.255.0 dhcp select interface dhcp server gateway-list 10.1.2.1 dhcp server lease day 2 hour 0 minute 0 dhcp server dns-list 10.1.3.1 dhcp server domain-name example.com # interface GigabitEthernet1/0/1 port link-type hybrid port hybrid pvid vlan 10 port hybrid untagged vlan 10 # interface GigabitEthernet1/0/2 port link-type hybrid port hybrid pvid vlan 11 port hybrid untagged vlan 11 # return