DHCP中继配置:
拓扑:
需求
1.PC自动获取IP地址
思路
1.配置DHCP客户端 2.配置DHCP服务器(基础配置/接口IP/开启DHCP功能/创建地址池/接口指定DHCP模式为global) 3.配置DHCP中继 4.配置DHCP客户端和中继之间的交换网络 5.配置DHCP中继和DHCP服务器之间的路由网络 6.验证与测试
配置
-- 配置 DHCP 客户端 ---
-- 配置 DHCP 服务器 --
undo terminal monitor
system-view
sysname DHCP
interface gi0/0/0
ip address 10.10.10.1 24
quit
dhcp enable
ip pool HEIHEI
network 192.168.1.0 mask 255.255.255.0
gateway-list 192.168.1.254
dns-list 8.8.8.8
quit
interface gi0/0/0
dhcp select global
quit
--- 配置 DHCP 中继(网关接口) ----
R4:
undo terminal monitor
system-view
sysname R4
interface gi0/0/1
ip address 192.168.1.254 24
quit
dhcp enable
interface gi0/0/1
dhcp select relay -> 设置该端口在接收到 DHCP 报文以后,进行“中转 -- relay”
dhcp relay server-ip 10.10.10.1 -> 将收到的DHCP报文,“中转给”服务器 : 10.10.10.1
--- 配置 DHCP 客户端和 中继 之间的交换网络 ---
SW1:
undo terminal monitor
system-view
sysname SW1
vlan 10
quit
interface gi0/0/1
port link-type access
port default vlan 10
quit
interface gi0/0/2
port link-type access
port default vlan 10
quit
--- 配置 DHCP 中继 和 服务器 之间的路由网络 ---
DHCP中继- R4:
interface gi0/0/0
ip address 10.10.10.2 24
quit
此时,配置了上面的接口IP地址以后,
虽然,R4上面有了去往 DHCP 服务器的直连路由。
但是,DHCP中继(R4-Gi0/0/1)依然和 DHCP 服务器无法互通。
因为,DHCP服务器上,没有返回到 DHCP 中继(接口)的 路由条目
所以,我们应该在 DHCP 服务器上,添加如下路由:
DHCP:
ip route-static 192.168.1.0 24 10.10.10.2
注意:
如果想要在R4上测试“DHCP中继和DHCP服务器是否互通”,应该使用下面的测试命令:
R4:
ping -a 192.168.1.254 10.10.10.1
即,使用源IP地址 192.168.1.254 去 ping 10.10.10.1 。
如果不用参数 -a ,那么该命令的源IP地址,默认是:数据包的出接口的IP地址。