ENSP 1.3 多网段 DHCP 中继配置:3个 VLAN 跨网段地址池实战
ENSP 1.3 多网段 DHCP 中继配置:3个 VLAN 跨网段地址池实战
在企业网络架构中,多VLAN环境下的IP地址分配一直是网络工程师需要掌握的核心技能。传统的手动配置方式在面对成百上千台终端设备时显得力不从心,而DHCP中继技术正是解决这一痛点的关键。本文将带您深入探索华为ENSP模拟器中如何为VLAN 2/3/4三个网段配置DHCP中继,实现跨网段自动地址分配的全流程。
1. 实验环境准备与拓扑构建
在开始配置前,我们需要先明确实验环境和网络拓扑。本次实验采用华为ENSP 1.3模拟器,主要设备包括:
- 1台三层交换机(作为DHCP中继设备)
- 1台路由器(作为DHCP服务器)
- 3台PC(分别属于VLAN 2/3/4)
- 必要的网线连接
拓扑结构说明:
[PC1-VLAN2] --- [SW2] --- [SW1] --- [R1(DHCP Server)] [PC2-VLAN3] --- | | [PC3-VLAN4] --- | |设备接口规划表:
| 设备 | 接口 | IP地址/配置 | 连接对象 |
|---|---|---|---|
| SW2 | Eth0/0/1 | VLAN 2 Access | PC1 |
| SW2 | Eth0/0/2 | VLAN 3 Access | PC2 |
| SW1 | Gig0/0/1 | VLAN 4 Access | PC3 |
| SW1 | Gig0/0/2 | Trunk (允许所有VLAN) | SW2 |
| SW1 | Vlanif2 | 192.168.2.254/24 | - |
| SW1 | Vlanif3 | 192.168.3.254/24 | - |
| SW1 | Vlanif4 | 192.168.4.254/24 | - |
| R1 | Gig0/0/0 | 192.168.4.253/24 | SW1 |
提示:在实际配置前,建议先在ENSP中绘制好拓扑图并标注各接口配置,这样可以避免后续配置时出现混淆。
2. 基础网络配置
2.1 交换机VLAN与接口配置
首先在SW2上创建VLAN并配置接入端口:
<Huawei> system-view [Huawei] sysname SW2 [SW2] vlan batch 2 3 4 [SW2] interface Ethernet0/0/1 [SW2-Ethernet0/0/1] port link-type access [SW2-Ethernet0/0/1] port default vlan 2 [SW2-Ethernet0/0/1] quit [SW2] interface Ethernet0/0/2 [SW2-Ethernet0/0/2] port link-type access [SW2-Ethernet0/0/2] port default vlan 3 [SW2-Ethernet0/0/2] quit接下来配置SW1的VLAN和接口:
<Huawei> system-view [Huawei] sysname SW1 [SW1] vlan batch 2 3 4 [SW1] interface GigabitEthernet0/0/1 [SW1-GigabitEthernet0/0/1] port link-type access [SW1-GigabitEthernet0/0/1] port default vlan 4 [SW1-GigabitEthernet0/0/1] quit [SW1] interface GigabitEthernet0/0/2 [SW1-GigabitEthernet0/0/2] port link-type trunk [SW1-GigabitEthernet0/0/2] port trunk allow-pass vlan all [SW1-GigabitEthernet0/0/2] quit2.2 三层接口IP配置
在SW1上配置各VLAN的接口IP,作为各网段的网关:
[SW1] interface Vlanif 2 [SW1-Vlanif2] ip address 192.168.2.254 24 [SW1-Vlanif2] quit [SW1] interface Vlanif 3 [SW1-Vlanif3] ip address 192.168.3.254 24 [SW1-Vlanif3] quit [SW1] interface Vlanif 4 [SW1-Vlanif4] ip address 192.168.4.254 24 [SW1-Vlanif4] quit路由器R1的基础配置:
<Huawei> system-view [Huawei] sysname R1 [R1] interface GigabitEthernet0/0/0 [R1-GigabitEthernet0/0/0] ip address 192.168.4.253 24 [R1-GigabitEthernet0/0/0] quit3. DHCP服务器与中继配置
3.1 DHCP服务器配置
在R1上配置DHCP服务并创建三个地址池:
[R1] dhcp enable [R1] ip pool vlan2 [R1-ip-pool-vlan2] network 192.168.2.0 mask 24 [R1-ip-pool-vlan2] gateway-list 192.168.2.254 [R1-ip-pool-vlan2] dns-list 114.114.114.114 [R1-ip-pool-vlan2] quit [R1] ip pool vlan3 [R1-ip-pool-vlan3] network 192.168.3.0 mask 24 [R1-ip-pool-vlan3] gateway-list 192.168.3.254 [R1-ip-pool-vlan3] dns-list 114.114.114.114 [R1-ip-pool-vlan3] quit [R1] ip pool vlan4 [R1-ip-pool-vlan4] network 192.168.4.0 mask 24 [R1-ip-pool-vlan4] gateway-list 192.168.4.254 [R1-ip-pool-vlan4] dns-list 114.114.114.114 [R1-ip-pool-vlan4] quit启用全局DHCP服务:
[R1] interface GigabitEthernet0/0/0 [R1-GigabitEthernet0/0/0] dhcp select global [R1-GigabitEthernet0/0/0] quit3.2 DHCP中继配置
在SW1上启用DHCP中继功能:
[SW1] dhcp enable [SW1] interface Vlanif 2 [SW1-Vlanif2] dhcp select relay [SW1-Vlanif2] dhcp relay server-ip 192.168.4.253 [SW1-Vlanif2] quit [SW1] interface Vlanif 3 [SW1-Vlanif3] dhcp select relay [SW1-Vlanif3] dhcp relay server-ip 192.168.4.253 [SW1-Vlanif3] quit [SW1] interface Vlanif 4 [SW1-Vlanif4] dhcp select relay [SW1-Vlanif4] dhcp relay server-ip 192.168.4.253 [SW1-Vlanif4] quit4. 验证与排错
4.1 PC端获取IP验证
在各PC上执行DHCP获取命令:
PC> ipconfig /renew查看获取的IP信息:
PC> ipconfig IPv4 address......................: 192.168.2.100 Subnet mask.......................: 255.255.255.0 Gateway...........................: 192.168.2.254 DNS server........................: 114.114.114.1144.2 设备端验证命令
在R1上查看地址池分配情况:
<R1> display ip pool name vlan2 used在SW1上查看DHCP中继状态:
<SW1> display dhcp relay statistics interface Vlanif 24.3 常见问题排查
问题1:PC无法获取IP地址
排查步骤:
- 检查物理连接和VLAN配置
- 验证DHCP中继配置是否正确
- 检查DHCP服务器地址池是否配置正确
- 使用
display dhcp relay statistics查看中继报文统计
问题2:获取的IP地址不在预期范围内
可能原因:
- 地址池配置错误
- 中继指向了错误的DHCP服务器
- 存在多个DHCP服务器干扰
5. 高级配置与优化
5.1 DHCP安全增强
为防止非法DHCP服务器干扰,可以启用DHCP Snooping:
[SW2] dhcp snooping enable [SW2] interface Ethernet0/0/1 [SW2-Ethernet0/0/1] dhcp snooping enable [SW2-Ethernet0/0/1] quit [SW2] interface Ethernet0/0/2 [SW2-Ethernet0/0/2] dhcp snooping enable [SW2-Ethernet0/0/2] quit5.2 地址租约管理
调整地址租约时间以适应不同场景:
[R1] ip pool vlan2 [R1-ip-pool-vlan2] lease day 0 hour 8 [R1-ip-pool-vlan2] quit5.3 保留地址配置
为特定设备分配固定IP:
[R1] ip pool vlan2 [R1-ip-pool-vlan2] static-bind ip-address 192.168.2.100 mac-address 5489-9851-036e [R1-ip-pool-vlan2] quit在实际项目部署中,我发现DHCP中继配置最容易出错的地方往往在于VLAN接口的IP地址与DHCP地址池的网关地址不一致。曾经在一个客户现场,因为SW1上Vlanif3的IP配置为192.168.3.254,而DHCP地址池中却误配为192.168.3.253,导致VLAN3的设备始终无法正常获取IP。通过display current-configuration interface Vlanif3和display ip pool name vlan3命令对比才发现了这个细微但关键的区别。