组网需求
某企业为办公终端规划了两个网段,网段10.1.1.0/24内PC为员工固定办公终端,网段10.1.2.0/24供企业出差人员临时接入网络。企业希望通过DHCP方式为员工固定办公终端和企业出差人员分配IP地址。其中,企业管理者的办公PC(Client_1)由于业务需要,希望使用固定IP地址为10.1.1.100/24。
配置思路
基于接口地址池的DHCP服务器的配置思路如下:
通过在网关设备Switch上配置DHCP服务器,实现为企业两个网段内的终端动态分配IP地址。其中,网段10.1.1.0/24内的PC为员工固定办公终端,IP地址租期配置为30天;网段10.1.2.0/24供企业出差人员临时接入网络,IP地址租期配置为1天。
二层交换机LSW_1和LSW_2上,需要配置接口的链路类型和加入的VLAN,实现二层互通。
操作步骤
- 使能DHCP服务,缺省未使能
<HUAWEI> system-view [HUAWEI] sysname Switch [Switch] dhcp enable
- 配置接口加入VLAN
# 配置GE0/0/1接口加入VLAN10。
[Switch] vlan batch 10 to 11 [Switch] interface gigabitethernet 0/0/1 [Switch-GigabitEthernet0/0/1] port link-type access [Switch-GigabitEthernet0/0/1] port default vlan 10 [Switch-GigabitEthernet0/0/1] quit
# 配置GE0/0/2加接口入VLAN11。
[Switch] interface gigabitethernet 0/0/2 [Switch-GigabitEthernet0/0/2] port link-type access [Switch-GigabitEthernet0/0/2] port default vlan 11 [Switch-GigabitEthernet0/0/2] quit
- 配置VLANIF接口IP地址
# 配置VLANIF10接口地址。
[Switch] interface vlanif 10 [Switch-Vlanif10] ip address 10.1.1.1 24 //企业为固定办公终端的网段 [Switch-Vlanif10] quit
# 配置VLANIF11接口地址。
[Switch] interface vlanif 11 [Switch-Vlanif11] ip address 10.1.2.1 24 //企业为出差人员分配的网段 [Switch-Vlanif11] quit
- 配置接口地址池
# 配置VLANIF10接口下的终端从接口地址池中获取IP地址。
[Switch] interface vlanif 10 [Switch-Vlanif10] dhcp select interface //使能接口采用接口地址池的DHCP服务器功能,缺省未使能 [Switch-Vlanif10] dhcp server lease day 30 //租期的缺省值为1天,修改租期为30天 [Switch-Vlanif10] dhcp server static-bind ip-address 10.1.1.100 mac-address 00e0-fc12-3456 //为Client_1分配固定的IP地址 [Switch-Vlanif10] quit
# 配置VLANIF11接口下的终端从接口地址池中获取IP地址。租期采用缺省值1天(不需配置)。
[Switch] interface vlanif 11 [Switch-Vlanif11] dhcp select interface //使能接口采用接口地址池的DHCP服务器功能,缺省未使能 [Switch-Vlanif11] quit
- 配置DHCP数据保存功能,设备发生故障时,可以在系统重启后,执行命令dhcp server database recover,从存储设备文件恢复DHCP数据。
[Switch] dhcp server database enable
- 配置各终端自动获取IP地址(以操作系统为Windows 7的PC为例)
- 右击桌面“网络”,单击“属性”,进入“网络和共享中心”窗口。
- 单击“本地连接”,进入“本地连接 状态”窗口。
- 单击“属性”,进入“本地链接 属性”窗口。
- 选择“Internet 协议版本 4(TCP/IPv4)”,点击“属性”,进入“Internet 协议版本 4(TCP/IPv4)属性”窗口,选择“自动获得 IP 地址”,单击“确定”。
- 验证配置结果
在Switch上执行命令display ip pool查看接口地址池VLANIF10和VLANIF11的配置信息。假设企业员工固定办公终端有100个,出差人员接入3个。
[Switch] display ip pool interface vlanif10 Pool-name : Vlanif10 Pool-No : 0 Lease : 30 Days 0 Hours 0 Minutes Domain-name : - DNS-server0 : - 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 Disable :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 : 1 Days 0 Hours 0 Minutes Domain-name : - DNS-server0 : - 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 Disable :0 ------------------------------------------------------------------------------- Network section Start End Total Used Idle(Expired) Conflict Disabled ------------------------------------------------------------------------------- 10.1.2.1 10.1.2.254 253 3 250(0) 0 0 -------------------------------------------------------------------------------
在Client_1(操作系统以Windows 7为例)上查看IP地址信息,可以看到Client_1已经获取到IP地址10.1.1.100/24。
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
在其他DHCP客户端(以10.1.1.0/24网段中操作系统为Windows 7的某终端为例)上查看IP地址信息,可以看到已经成功获取到IP地址。
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
配置文件
Switch的配置文件
# 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 static-bind ip-address 10.1.1.100 mac-address 00e0-fc12-3456 dhcp server lease day 30 hour 0 minute 0 # interface Vlanif11 ip address 10.1.2.1 255.255.255.0 dhcp select interface # interface GigabitEthernet0/0/1 port link-type access port default vlan 10 # interface GigabitEthernet0/0/2 port link-type access port default vlan 11 # return