DHCP协议分析实验

一、 实验原理

1、DHCP(dynamic host configuration protocol)
DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)是一个局域网的网络协议,使用UDP协议工作, 主要有两个用途:给内部网络或网络服务供应商自动分配IP地址,给用户或者内部网络管理员作为对所有计算机作中央管理的手段。
2、DHCP的分配方式

  • 自动分配

一旦DHCP客户端第一次成功的从DHCP伺服器端租用到IP位址之后,就永远使用这个位址。

  • 动态分配

当DHCP第一次从HDCP伺服器端租用到IP位址之后,并非永久的使用该位址,只要租约到期﹐客户端就得释放(release)这个IP位址,以给其它工作站使用。当然,客户端可以比其它主机更优先的延续(renew)租约,或是租用其它的IP位址。

  • 手动分配

由DHCP服务器管理员专门指定IP地址使用。
3、DHCP租约过程分四个步骤
1.客户机请求IP
2.服务器响应
3.客户机选择IP
4.服务器确定租约
4、更新租约
IP地址的租期达到50%后,须重新更新租期,客户端直接向服务器单播发送DHCP Request请求包。
5、使用DHCP的好处
1.减少管理员的工作量
2.避免输入错误的可能
3.避免IP冲突
4.提供了IP地址的利用率(最重要的)
5.方便客户端的配置
6、DHCP报文类型

报文类型 含义
DHCP DISCOVER 客户端用来寻找DHCP服务器
DHCP OFFER DHCP服务器用来响应DHCP DISCOVER报文
DHCP REQUEST 客户端请求配置确认,或者续借租期
DHCP ACK 服务器对REQUEST报文的确认响应
DHCP NAK 服务器对REQUEST报文的拒绝响应
DHCP RELEASE 客户端要释放地址时用来通知服务器

7、 地址池分类
DHCP服务器的地址池是用来定义分配给主机的IP地址范围。

1.接口地址池为连接到同一网段的主机或终端分配IP地址。可以在服务器的接口下执行dhcp select interface命令,配置DHCP服务器采用接口地址池的DHCP服务器模式为客户端分配IP地址。

2.全局地址池为所有连接到DHCP服务器的终端分配IP地址。可以在服务器的接口下执行dhcp select global命令,配置DHCP服务器采用全局地址池的DHCP服务器模式为客户端分配IP地址。

3.接口地址池的优先级比全局地址池高。配置了全局地址池后,如果又在接口上配置了地址池,客户端将会从接口地址池中获取IP地址。在X7系列交换机上,只能在VLANIF逻辑接口上配置接口地址池。

二、实验配置

1、实验拓扑图
在这里插入图片描述
2、 实验步骤

  1. 将各主机的IPv4地址配置为DHCP;
  2. 配置路由器R1为DHCP服务器;
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname R1
[R1]undo info enable
Info: Information center is disabled.
[R1]int e0/0/0
[R1-Ethernet0/0/0]ip add 192.168.12.1 24
[R1-Ethernet0/0/0]q
[R1]int e0/0/1
[R1-Ethernet0/0/1]ip add 192.168.11.1 24
[R1-Ethernet0/0/1]q
[R1]dhcp enable
[R1]ip pool pool1
Info:It's successful to create an IP address pool.
[R1-ip-pool-pool1]network 192.168.11.0 mask 255.255.255.0
[R1-ip-pool-pool1]gateway-list 192.168.11.1
[R1-ip-pool-pool1]quit
[R1]ip pool pool2
Info:It's successful to create an IP address pool.
[R1-ip-pool-pool2]network 192.168.22.0 mask 255.255.255.0
[R1-ip-pool-pool2]gateway-list 192.168.22.1
[R1-ip-pool-pool2]quit
[R1]ip pool pool3
Info:It's successful to create an IP address pool.
[R1-ip-pool-pool3]network 192.168.33.0 mask 255.255.255.0
[R1-ip-pool-pool3]gateway-list 192.168.33.1
[R1-ip-pool-pool3]quit
[R1]int e0/0/0
[R1-Ethernet0/0/0]dhcp select global
[R1-Ethernet0/0/0]q
dhcp select global命令用来使能接口的DHCP服务器功能。
[R1]int e0/0/1
[R1-Ethernet0/0/1]dhcp select global
[R1-Ethernet0/0/1]q
[R1]ip pool pool1
[R1-ip-pool-pool1]dns-list 1.1.1.1
[R1-ip-pool-pool1]lease day 10
[R1-ip-pool-pool1]q
[R1]ip pool pool2
[R1-ip-pool-pool2]dns-list 1.1.1.1
[R1-ip-pool-pool2]lease day 10
[R1-ip-pool-pool2]q
[R1]ip pool pool3
[R1-ip-pool-pool3]dns-list 1.1.1.1
[R1-ip-pool-pool3]lease day 10
[R1-ip-pool-pool3]q
[R1]rip
[R1-rip-1]version 2
[R1-rip-1]network 192.168.11.0
[R1-rip-1]network 192.168.22.0
[R1-rip-1]network 192.168.33.0
[R1-rip-1]q
[R1]q
<R1>save

3.查看R1地址池:
在这里插入图片描述
4. 配置R2和R3;
R2配置如下(R3同理):

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname R2
[R2]undo info enable
Info: Information center is disabled.
[R2]int e0/0/0
[R2-Ethernet0/0/0]ip add 192.168.12.2 24
[R2-Ethernet0/0/0]quit
[R2]int e0/0/1
[R2-Ethernet0/0/1]ip add 192.168.24.1 24
[R2-Ethernet0/0/1]quit
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ip add 192.168.22.1 24
[R2-GigabitEthernet0/0/0]quit
[R2]rip
[R2-rip-1]version 2
[R2-rip-1]network 192.168.12.0
[R2-rip-1]network 192.168.24.0
[R2-rip-1]network 192.168.22.0
[R2-rip-1]q
[R2]int e0/0/0
[R2]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[R2]int e0/0/0
[R2-Ethernet0/0/0]dhcp select relay
[R2-Ethernet0/0/0]dhcp relay server-ip 192.168.12.1
[R2-Ethernet0/0/0]q
[R2]int e0/0/1
[R2-Ethernet0/0/1]dhcp select relay
[R2-Ethernet0/0/1]dhcp relay server-ip 192.168.12.1
[R2-Ethernet0/0/1]q
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]dhcp select relay
[R2-GigabitEthernet0/0/0]dhcp relay server-ip 192.168.12.1
[R2-GigabitEthernet0/0/0]q
[R2]q
<R2>save
  1. 查看各主机是否被分配到不同子网的IP地址;
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    各主机均被分配到IP地址,实验配置成功。

猜你喜欢

转载自blog.csdn.net/weixin_44366125/article/details/105873667