目录

DHCP中继实验

DHCP中继实验

DHCP中继实验

DHCP 中继实验简介

DHCP 中继(DHCP Relay) 用于跨子网或跨 VLAN 的环境中,帮助客户端通过路由器或三层交换机将 DHCP 请求转发到远程 DHCP 服务器。

实验目标 :验证 DHCP 中继代理的功能,实现不同子网间的动态 IP 分配。


实验原理

核心问题
  • DHCP 请求(Discover/Request)以 广播形式 发送,但广播包默认无法跨越路由器或三层设备。
  • 中继代理 的作用是将客户端的广播请求转换为 单播 ,并转发至指定 DHCP 服务器。
工作流程
  1. 客户端发送广播请求
    • 客户端在子网 A(如 192.168.1.0/24 )广播 DHCP Discover
  2. 中继代理接收并转发
    • 中继代理(配置在路由器或三层交换机上)捕获广播包,将其封装为单播报文:
      • 修改目标 IP 为 DHCP 服务器地址(如 10.0.0.100 )。
      • 在报文头插入中继代理的 IP 地址( giaddr 字段),供服务器识别客户端所在子网。
  3. 服务器响应
    • 服务器根据 giaddr 判断客户端子网,从对应地址池分配 IP,通过单播返回 DHCP Offer 给中继代理。
  4. 中继代理转发响应
    • 中继代理将响应报文广播回客户端子网,完成地址分配。

实验拓扑

https://i-blog.csdnimg.cn/direct/46591db78d3148f1bfe290387932053a.png

实验需求

  1. 按照图示配置IP地址
  2. 配置DHCP_server路由器为DHCP服务器,能够跨网段为 192.168.2.0/24 网段自动分配IP地址。要求分配DNS地址为 202.103.24.68202.103.0.117
  3. PC3获取IP地址后,能够访问到 192.168.1.1

实验步骤

1.给DHCP_server和中继路由器配置IP地址
在DHCP_server上
<H3C>system-view 
System View: return to User View with Ctrl+Z.
[H3C]sysname DHCP_server
[DHCP_server]int g0/0
[DHCP_server-GigabitEthernet0/0]ip address 192.168.1.1 24
[DHCP_server-GigabitEthernet0/0]display ip interface brief
*down: administratively down
(s): spoofing  (l): loopback
Interface           Physical Protocol IP address/Mask    VPN instance Description  
GE0/0               up       up       192.168.1.1/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     --                 --           --
[DHCP_server-GigabitEthernet0/0]
在中继路由器上
<H3C>system-view 
System View: return to User View with Ctrl+Z.
[H3C]sysname 中继路由器
[中继路由器]int g0/0
[中继路由器-GigabitEthernet0/0]ip address 192.168.1.2 24
[中继路由器-GigabitEthernet0/0]int g0/1
[中继路由器-GigabitEthernet0/1]ip address 192.168.2.254 24
[中继路由器-GigabitEthernet0/1]display ip interface brief
*down: administratively down
(s): spoofing  (l): loopback
Interface           Physical Protocol IP address/Mask    VPN instance Description  
GE0/0               up       up       192.168.1.2/24     --           --
GE0/1               down     down     192.168.2.254/24   --           --
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     --                 --           --
[中继路由器-GigabitEthernet0/1]
2. 配置R1为DHCP服务器,能够跨网段为192.168.2.0/24网段自动分配IP地址
注:默认情况下,DHCP只能为和本机处于同一网段的PC客户端分配IP地址。而我们现在却要求去跨网段给pc机分配IP地址,就需要配置DHCP中继来实现,在DHCP_server上创建的地址池必须要宣告192.168.2.0/24网段。DHCP分配的网关地址应该是192.168.2.0/24网段的真实网关,那根据上述拓扑可知,网关就是中继路由器的g0/1接口,IP地址为192.168.2.254,DHCP的IP地址请求和应答报文都是广播形式发送,默认情况下,是无法穿越路由器的,所以需要在中继路由器上开启DHCP中继功能,使DHCP报文能够跨网段转发,另外,192.168.2.0/24网段对DHCP_server来说,是非直连网段,要使DHCP_server和PC3连通,DHCP_server上必须具有到达192.168.2.0/24网段的路由信息
在DHCP_server
[DHCP_server]dhcp enable 
[DHCP_server]dhcp server ip-pool 1
[DHCP_server-dhcp-pool-1]network 192.168.2.0 mask 255.255.255.0
[DHCP_server-dhcp-pool-1]gateway-list 192.168.2.254
[DHCP_server-dhcp-pool-1]dns-list 202.103.24.68 202.103.0.117
[DHCP_server-dhcp-pool-1]
3. 在中继路由器上开启DHCP功能,并在连接客户端的接口(g0/1)上开启DHCP中继功能,并指定DHCP服务器的IP地址
[中继路由器]dhcp enable 
[中继路由器]interface g0/1
[中继路由器-GigabitEthernet0/1]dhcp select relay 
[中继路由器-GigabitEthernet0/1]dhcp relay server-address 192.168.1.1
[中继路由器-GigabitEthernet0/1]
4. 在R1上配置默认路由,使R1的DHCP协议报文能够到达PC3
在DHCP_server上
[DHCP_server]ip route-static 0.0.0.0 0 192.168.1.2   //配置默认路由
[DHCP_server]
5. 在PC3上Ping 192.168.1.1,确认可以Ping通
在pc3上
<H3C>ping 192.168.1.1
Ping 192.168.1.1 (192.168.1.1): 56 data bytes, press CTRL_C to break
56 bytes from 192.168.1.1: icmp_seq=0 ttl=254 time=0.703 ms
56 bytes from 192.168.1.1: icmp_seq=1 ttl=254 time=0.678 ms
56 bytes from 192.168.1.1: icmp_seq=2 ttl=254 time=0.556 ms
56 bytes from 192.168.1.1: icmp_seq=3 ttl=254 time=0.733 ms
56 bytes from 192.168.1.1: icmp_seq=4 ttl=254 time=0.633 ms

--- Ping statistics for 192.168.1.1 ---
5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss
round-trip min/avg/max/std-dev = 0.556/0.661/0.733/0.062 ms
<H3C>%Mar 14 16:55:09:206 2025 H3C PING/6/PING_STATISTICS: Ping statistics for 192.168.1.1: 5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss, round-trip min/avg/max/std-dev = 0.556/0.661/0.733/0.062 ms.