动态主机配置协议是一个局域网的网络协议。指的是由服务器控制一段IP地址范围,客户机登录服务器时就可以自动获得服务器分配的IP地址和子网掩码。
工作过程:
首先客户端会以广播的方式来寻找DHCP服务器,如果DHCP服务器接收到了,DHCP服气会响应客户端,以单播形式发个客户端,之后客户端相应DHCP服务器,请求租用ip,以广播形式响应DHCP服务器,之后服务器确认请以单播为客户端分配IP地址
。
DHCP服务器工作原理
数据包
discover 寻找 寻找DHCP服务器 广播
offer 回应 告诉客户端我是DHCP服务器 单播
request 请求 请求租用IP地址 广播
ack 确认 为客户端分配IP地址 单播
1、当客户机重新启动或者租约时间达到50%租约期的时候就需要重新更新租约,客户机直接向提供租约的服务器发送DHCP Request报文,要求更新现有的IP地址租约的时间。
2、如果DHCP服务器接收到请求,则将发送DHCP确认信息给客户机,更新客户机租约。
3、如果客户机无法与DHCP服务器联系,则在客户机一直等到租期达到87.5%时,再次发送DHCP Request报文。
4、如果客户机仍然无法联系到当初的DHCP服务器,就会联系其他服务器;如果仍无法联系到,将会停用其原来租约的IP地址。
单臂路由+DHCP全局模式:
第一个ip地址池
[Huawei]sys R1
[R1]dhcp enable //启动DHCP服务
Info: The operation may take a few seconds. Please wait for a moment.done.
[R1]ip pool p1 //创建地址池
Info: It's successful to create an IP address pool.
[R1-ip-pool-p1]network 192.168.10.0 mask 24 //指定网段
[R1-ip-pool-p1]gateway-list 192.168.10.2 //指定网关
[R1-ip-pool-p1]dns-list 1.1.1.1 //指定DNS服务器地址
[R1-ip-pool-p1]lease day 999 //指定租约
[R1-ip-pool-p1]int g0/0/0.1 //进入子接口
[R1-GigabitEthernet0/0/0.1]dot1q termination vid 10 //讲接口加入vlan
[R1-GigabitEthernet0/0/0.1]ip address 192.168.10.1 24 //添加接口网关
[R1-GigabitEthernet0/0/0.1]arp broadcast enable //启动接口
[R1-GigabitEthernet0/0/0.1]dhcp select global //指定接口为全局模式
[Huawei]vlan batch 10 20 //创建vlan
Info: This operation may take a few seconds. Please wait for a moment...done.
[Huawei]int e0/0/1 //进接口
[Huawei-Ethernet0/0/1]port link-type access //设置模式access模式
[Huawei-Ethernet0/0/1]port default vlan 10 //允许那个vlan通过
[Huawei-Ethernet0/0/1]int e0/0/2
[Huawei-Ethernet0/0/2]port link-type access
[Huawei-Ethernet0/0/2]port default vlan 20
[Huawei-Ethernet0/0/2]int e0/0/3
[Huawei-Ethernet0/0/3]port link-type trunk //设置模式trunk 模式
[Huawei-Ethernet0/0/3]port trunk allow-pass vlan all //允许所有vlan通过
将计算机选为DHCP模式
不在同一个vlan所以现在有一台获取不到
ip pool p2
Info: It's successful to create an IP address pool.
[R1-ip-pool-p2]network 192.168.20.0 mask 24
[R1-ip-pool-p2]gateway-list 192.168.20.1
[R1-ip-pool-p2]dns-list 2.2.2.2
[R1-ip-pool-p2]excluded-ip-address 192.168.20.100 192.168.20.254 //排查一些ip
[R1-ip-pool-p2]int g0/0/0.2
[R1-GigabitEthernet0/0/0.2]dot1q termination vid 20
[R1-GigabitEthernet0/0/0.2]ip address 192.168.20.2 24
[R1-GigabitEthernet0/0/0.2]arp broadcast enable
[R1-GigabitEthernet0/0/0.2]arp broadcast enable
[R1-GigabitEthernet0/0/0.2]dhcp select global
接口模式
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[Huawei]sys r1
[r1]int g0/0/0 //进接口
[r1-GigabitEthernet0/0/0]ip address 192.168.2.1 24 //接口设置地址
[r1-GigabitEthernet0/0/0]dhcp select interface //设置接口为DHCP的接口模式
[r1-GigabitEthernet0/0/0]dhcp server dns-list 1.1.1.1 //是指DNS服务器的地址
[r1-GigabitEthernet0/0/0]dhcp server excluded-ip-address 192.168.2.50 192.168.2.254 //不让客户端使用到某些IP地址
//无法排除某些IP可能是某些客户端正在使用这ip需要在客户端取消命下面,需要先释放:
ipconfig /release
所有课换端释放完了之后在执行
[r1-GigabitEthernet0/0/0]dhcp server excluded-ip-address 192.168.2.50 192.168.2.
254
Warning:Some of addresses not be excluded are not idle,or not in the pool.
修改某些配置就
[r1-GigabitEthernet0/0/0]undo dhcp server dns-list 1.1.1.1
[r1-GigabitEthernet0/0/0] dhcp server dns-list 2.2.2.2
客户端上查询打
ipconfig /renew //更新用户信息
客户机的命令:
ipconfig / /查看ip
ipconfig /renew //更新租约
ipconfig /release //释放ip
接口模式加接口模式
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]vlan batch 10 20
[Huawei]int e0/0/1
[Huawei-Ethernet0/0/1]port link-type access
[Huawei-Ethernet0/0/1]port default vlan 10
[Huawei-Ethernet0/0/1]int e0/0/2
[Huawei-Ethernet0/0/2]port link-type access
[Huawei-Ethernet0/0/2]port default vlan 20
[Huawei-Ethernet0/0/2]int e0/0/3
[Huawei-Ethernet0/0/3]port link-type trunk
[Huawei-Ethernet0/0/3]port trunk allow-pass vlan all
u t m
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R1
[R1]dhcp en
[R1]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[R1]int g0/0/0.1
[R1-GigabitEthernet0/0/0.1]dot1q termination vid 10
[R1-GigabitEthernet0/0/0.1]ip address 192.168.10.1 24
[R1-GigabitEthernet0/0/0.1]arp broadcast enable
[R1-GigabitEthernet0/0/0.1]dhcp select interface
[R1-GigabitEthernet0/0/0.1]dhcp server dns-list 1.1.1.1
[R1-GigabitEthernet0/0/0.1]dhcp server lease day 999
^
Warning:Some of addresses not be excluded are not idle,or not in the pool.
[R1-GigabitEthernet0/0/0.1]
[R1-GigabitEthernet0/0/0.1]int g0/0/0.2
[R1-GigabitEthernet0/0/0.2]dot1q termination vid 20
[R1-GigabitEthernet0/0/0.2]ip address 192.168.20.1 24
[R1-GigabitEthernet0/0/0.2]arp broadcast enable
[R1-GigabitEthernet0/0/0.2]dhcp select interface
[R1-GigabitEthernet0/0/0.2]dhcp server dns-list 2.2.2.2
[R1-GigabitEthernet0/0/0.2]dhcp server excluded-ip-address 192.168.20.50 192.168.20.254
Warning:Some of addresses not be excluded are not idle,or not in the pool.
中继代理模式
G0/0/0接口设置IP和设置DHCP接口模式代理
<Huawei>u t m
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei] sys R1
[R1]dhcp enable //启动dhcp服务
Info: The operation may take a few seconds. Please wait for a moment.done.
[R1]int g0/0/0 //进入0接口口
[R1-GigabitEthernet0/0/0]ip address 192.168.1.1 24 //设置网关
[R1-GigabitEthernet0/0/0]dhcp select interface //设置为接口模式
G0/0/0接口设置IP和设置DHCP接口模式代理
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]q
[R1]ip pool p3 //创建ip池子
Info: It's successful to create an IP address pool.
[R1-ip-pool-p3]network 192.168.3.0 mask 24 //设置3网段ip
[R1-ip-pool-p3]gateway-list 192.168.3.1 //设置网关
[R1-ip-pool-p3]int g0/0/1
[R1-GigabitEthernet0/0/1]dhcp select global //设置接口为全局模式
R1]ip route-static 192.168.3.0 24 192.168.2.2 //设置静态地址
<R1>sys
Enter system view, return user view with Ctrl+Z.
[R1]int g0/0/1
[R1-GigabitEthernet0/0/1]ip address 192.168.2.1 24 //添加地址1接口
设置R2为中继代理
<Huawei>u t m
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R2
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ip address 192.168.2.2 24
[R2-GigabitEthernet0/0/0]int g0/0/1
[R2-GigabitEthernet0/0/1]ip address 192.168.3.1 24
[R2-GigabitEthernet0/0/1]q
[R2]ip route-static 192.168.1.0 24 192.168.2.1 //设置静态路由
[R2]dhcp enable //启动服务
Info: The operation may take a few seconds. Please wait for a moment.done.
[R2]int g0/0/1
[R2-GigabitEthernet0/0/1]ip address 192.168.3.1 24 //设置地址
[R2-GigabitEthernet0/0/1]dhcp select relay //启用中继代模式
[R2-GigabitEthernet0/0/1]dhcp relay server-ip 192.168.2.1 //指定DHCP服务器地址
接口模式:
优点:设置灵活方便。
缺点: 但不能改接口的IP地址只要改变全部设置讲被初始话。
全局模式的:
优点:可以设置多个网段ip池可以提供给多个网段的电脑使用。
缺点:设置比较复杂。
中继代理:
帮助本网段的客户向其它网段的DHCP服务器申请IP地址的路由器。