DHCP服务器设置

以三层交换机作为DHCP服务器

所有设备均用交换机代替

配置过程

  • 开启dhcp服务
  • 创建ip池
  • 设置网段和掩码
  • 设置网关
  • 在相应端口开启全局dhcp服务
  • 主机动态获取ip

对DHCP服务器进行设置

<Huawei>sys #进入系统模式
Enter system view, return user view with Ctrl+Z.
[Huawei]undo inf e #关闭变更信息显示
Info: Information center is disabled.
[Huawei]sys DHCP	#改名
[DHCP]dhcp en	#开启dhcp服务
[DHCP]ip pool vlan100	#创建dhcp池
[DHCP-ip-pool-vlan100]network 192.168.1.0 mask 24	#指定网段
[DHCP-ip-pool-vlan100]gateway-list 192.168.1.1	#指定网关
[PC]int vlanif1	 #进入交换机默认接口,所有交换机接口默认属于vlan 1
[PC-Vlanif1]ip add 192.168.1.1 24	#给接口设置ip
[PC-Vlanif1]dhcp select global	#在接口上开启全局dhcp分配

SW可不设置

对PC机设置

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]undo inf e
Info: Information center is disabled.
[Huawei]sys PC
[PC]dhcp en	#开启dhcp服务
[PC]int vlanif1
[PC-Vlanif1]ip ad dhcp-alloc	#动态获取ip
[PC-Vlanif1]dis ip int br	#查看ip信息
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 2
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 2
The number of interface that is DOWN in Protocol is 1

Interface                         IP Address/Mask      Physical   Protocol
MEth0/0/1                         unassigned           down       down
NULL0                             unassigned           up         up(s)
Vlanif1                           192.168.1.254/24     up         up
#这就是dhcp服务器分配给主机的IP地址

wireshark抓包分析

DHCP获取IP的过程

|次序|客户机——DHCP|包|作用|
|--|--|--|--|--|
|1|——>|discover|发现DHCP服务器|
|2|<——|offer|告知客户机可以提供DHCP服务|
|3|——>|request|申请IP|
|4|<——|ACK|告知客户机同意该申请|

  1. 发现dhcp服务器

此时主机无ip地址,也不知道dhcp服务器的ip,
只能用0.0.0.0地址向255.255.255.255发送广播

 

2. 当dhcp服务器收到该广播时,如果能提供ip地址,便进行相应, 因为它不知到是谁发起的请求,所以只能进行广播,目的地址是255.255.255.255 里面包含了能给主机提供的ip信息

3. 主机收到offer后,(可能有多个offer),选择其中一个ip(首先确认是发向自己的offer),向dhcp进行申请该ip

4. 服务器收到请求后,同意该申请,将该ip分配给该主机,并通知该主机

 

路由器做DHCP

方法类似
只是路由器的每个连接的接口的ip地址都需要配置,然后在相应端口开启服务
如果主机是用的PC机而不是交换机
需在命令行输入 ipconfig

开启中继服务

当主机与dhcp服务器不在一个局域网内时,需要在路由器上开启中继服务

posted @ 2021-07-24 00:46  ly探长  阅读(576)  评论(0)    收藏  举报