DHCP中继实验
中继的功能
解决跨网段分配 IP 地址的问题,使 DHCP 客户端与服务器位于不同子网时仍能获取 IP。
工作原理
一 实验拓扑图
二 设备命名与IP地址规划
设备名 | 接口编号 | IP地址规划 |
---|---|---|
R1 | GE0/0 | 192.168.1.1/24 |
R2 | GE0/0 | 192.168.1.2/24 |
GE0/1 | 192.168.2.254/24 | |
R3 | GE0/0 | DHCP获取 |
三 实验步骤
按照图示连接好线缆
配置DHCP,R1为DHCP服务器,需要跨越网段为R3分配IP地址
由于192.168.2.1~192.168.2.9已经被其他设备固定使用,所以需要排除该地址段
1 配置ip地址
在DHCP Server
[DHCP Server]int g0/0
[DHCP Server-GigabitEthernet0/0]ip ad 192.168.1.1 24
在DHCP Relay
[DHCP Relay]int g0/0
[DHCP Relay-GigabitEthernet0/0]ip ad 192.168.1.2 24
[DHCP Relay-GigabitEthernet0/0]int g0/1
[DHCP Relay-GigabitEthernet0/1]ip ad 192.168.2.254 24
2 在DHCP Server上使能DHCP功能
[DHCP Server]dhcp enable
3 配置dhcp的地址池
[DHCP Server]dhcp server ip-pool 1
[DHCP Server-dhcp-pool-1]network 192.168.2.0 24
[DHCP Server-dhcp-pool-1]gateway-list 192.168.2.254
[DHCP Server-dhcp-pool-1]dns-list 114.114.114.114
[DHCP Server-dhcp-pool-1]expired day 1
[DHCP Server-dhcp-pool-1]qu
[DHCP Server]dhcp server forbidden-ip 192.168.2.1 192.168.2.9 //排除IP地址
4 配置DHCP中继
[DHCP Relay]dhcp enable
[DHCP Relay]int g0/1
[DHCP Relay-GigabitEthernet0/1]dhcp select relay // 设置GE0/1接口为DHCP中继接口
[DHCP Relay-GigabitEthernet0/1]dhcp relay server-address 192.168.1.1 告诉中继接口,DHCP服务器的IP地址为192.168.1.1
[DHCP Relay-GigabitEthernet0/1]
5 查看DHCP Client分配效果
[DHCP Client]int g0/0
[DHCP Client-GigabitEthernet0/0]ip ad dhcp-a
[DHCP Client-GigabitEthernet0/0]ip ad dhcp-alloc
6 查看DHCP Client客户端地址获取情况
[DHCP Client-GigabitEthernet0/0]dis ip int brief
*down: administratively down
(s): spoofing (l): loopback
Interface Physical Protocol IP address/Mask VPN instance Description
GE0/0 up up 169.254.3.0/16 -- --
GE0/1 down down -- -- --
GE0/2 down down -- -- --
GE5/0 down down -- -- --
GE5/1 down down -- -- --
GE6/0 down down -- -- --
GE6/1 down down -- -- --
Ser1/0 down down -- -- --
Ser2/0 down down -- -- --
Ser3/0 down down -- -- --
Ser4/0 down down -- -- --
7 在DHCP Server上配置一条去往DHCP Client的路由,使其网络互通
[DHCP Server]ip route-static 192.168.2.0 24 192.168.1.2 //手动配置IP路由目标网络为192.168.2.0/24,下一跳为192.168.1.2
8 重启DHCP Client接口
[DHCP Client-GigabitEthernet0/0]shutdown //关闭接口
%Jul 7 20:14:21:540 2025 DHCP Client IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet0/0 changed to down.
%Jul 7 20:14:21:540 2025 DHCP Client IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet0/0 changed to down.
[DHCP Client-GigabitEthernet0/0]undo shutdown // 取消接口
[DHCP Client-GigabitEthernet0/0]%Jul 7 20:14:32:490 2025 DHCP Client IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet0/0 changed to up.
%Jul 7 20:14:32:492 2025 DHCP Client IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet0/0 changed to up
9 再次查看DHCP Client客户端地址获取情况
[DHCP Client-GigabitEthernet0/0]dis ip int brief
*down: administratively down
(s): spoofing (l): loopback
Interface Physical Protocol IP address/Mask VPN instance Description
GE0/0 up up 192.168.2.10/24 -- --
GE0/1 down down -- -- --
GE0/2 down down -- -- --
GE5/0 down down -- -- --
GE5/1 down down -- -- --
GE6/0 down down -- -- --
GE6/1 down down -- -- --
Ser1/0 down down -- -- --
Ser2/0 down down -- -- --
Ser3/0 down down -- -- --
Ser4/0 down down -- -- --