在生产环境中,我们需要使用多个网段,如果在连接这些网段的路由中配置DHCP服务,会增加我们的维护成本,这时我们可以使用DHCP的中继功能,来实现跨网段IP分配。

DHCP 动态主机设置协议

作用:分配网络IP

优点:

  1. 使用方便
  2. 防止地址冲突
  3. 方便管理

项目拓扑

项目拓扑如图:

需求分析

PC0可以获取IP。
  配置路由设备可以使其具备DHCP的功能,但图中的DHCP服务端与客户端之间存在另外一台路由设备,而该设备没有配置DHCP的功能。

项目方案

通过DHCP中继路由器实现。
  客户端在向最近的路由器请求IP,而最近的路由器并非DHCP的服务端,但是它知道要找谁要IP,根据指向地址,中继将获取到的地址发给客户端。

方案步骤

Router0路由器:

1
2
3
4
5
6
7
8
9
10
11
12
13
1. Continue with configuration dialog? [yes/no]: no
2. Router>enable
3. Router#configure terminal
4. Router(config)#interface fastEthernet 0/0
5. Router(config-if)#ip address 192.168.1.1 255.255.255.0
6. Router(config-if)#no shutdown
7. Router(config-if)#exit
8. Router(config)#ip dhcp pool cjk
9. Router(dhcp-config)#network 192.168.2.0 255.255.255.0
10. Router(dhcp-config)#default-router 192.168.2.1
11. Router(dhcp-config)#dns-server 8.8.8.8
12. Router(dhcp-config)#exit
13. Router(config)#ip route 192.168.2.0 255.255.255.0 fastEthernet 0/0

Router1路由器:

1
2
3
4
5
6
7
8
9
10
11
1. Continue with configuration dialog? [yes/no]: no
2. Router>enable
3. Router#configure terminal
4. Router(config)#interface fastEthernet 0/1
5. Router(config-if)#ip address 192.168.1.2 255.255.255.0
6. Router(config-if)#no shutdown
7. Router(config-if)#exit
8. Router(config)#interface fastEthernet 0/0
9. Router(config-if)#ip address 192.168.2.1 255.255.255.0
10. Router(config-if)#ip helper-address 192.168.1.1
11. Router(config-if)#no shutdown

方案测试

测试结果如图:

注意事项

  1. 在配置IP地址池时,所设置的网关是否是目标网段的网关。
  2. DHCP中继端需要直接指向DHCP服务端,不可指向其它中继。

流程:

  1. 地址请求:客户端发布一个dhcp请求信息,该信息会发给网内所有主机,非dhcp服务器会丢失信息。
  2. 地址提供:而dhcp服务端收到该消息后,会从地址池内,挑选一个未被使用的地址返回给客户端(只提供ip地址信息)。
  3. 地址选择:如果网内有多个dhcp服务端,则客户端会收到多个地址,这时客户端必须选择一个地址(先到先选原则),并广播一条信息告知已选项。
  4. 地址确认:服务端收到客户端的广播信息后,会确认是否为自身提供的地址,如果不是,则不响应,否则继续提供其他信息。