目录
一 : DHCP协议
1.1 DHCP简述
1.2 DHCP的作用
1.2.1 DHCP的好处
1.2.2 DHCP的三种机制分配ip
1.2.3 windows中获得释放地址命令
二:DHCP协议中的报文
三:实验————DHCP中继实验过程
一:DHCP协议
1.1 DHCP简述
DHCP(Dynamic Host Configuration Protocol),动态主机配置协议)是一种局域网的协议。主要是集中的管理,分配IP地址,使网络环境中的主机动态的获得IP地址。基于udp协议,端口号67&68
1.2 DHCP的作用
1.2.1 DHCP的好处
1.能够避免ip地址冲突
2.能够集中管理,减少管理员的工作量
3.能够提高ip地址的利用率
1.2.2 DHCP的三种机制分配ip
手工分配,由管理员对每台具体的计算机指定一个地址
自动分配,服务器为第一次连接网络的计算机分配一个永久地址
动态分配,在一定的期限内将地址租给计算机,租期结束后客户必须续租或者停用该地址,而对于路由器,经常使用的地址分配方式是动态配置。
1.2.3 windows中获得释放地址命令
命令ipconfig/release 释放ip地址
命令ipconfig/renew 重新获取ip地址
二:DHCP协议中的报文
1.DHCP DISCOVER :客户端开始DHCP过程发送的包,是DHCP协议的开始。
2.DHCP OFFER :服务器接收到DHCP DISCOVER之后做出的响应,它包括了给予客户端的
IP(yiaddr)、客户端的MAC地址、租约过期时间、服务器的识别符以及其他信息。
3.DHCP REQUEST :客户端对于服务器发出的DHCP OFFER所做出的响应。在续约租期的时候同样会使用。
4.DHCP ACK :服务器在接收到客户端发来的DHCP REQUEST之后发出的成功确认的报文。在建立连接的时候,客户端在接收到这个报文之后才会确认分配给它的IP和其他信息可以被允许使用。
三:实验————DHCP中继实验过程
DHCP中继实验拓扑图
交换机命令
un t m 关闭弹出信息(undo terminal monitor)
un t m
Info: Current terminal monitor is off.
sys
system-view 进入系统视图
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname SW1 命名
[SW1]user-
[SW1]user-in
[SW1]user-interface con
[SW1]user-interface console 0
[SW1-ui-console0]idle-t
[SW1-ui-console0]idle-timeout 0 0
[SW1-ui-console0]q
[SW1]v b 10 20 创建vlan
Info: This operation may take a few seconds. Please wait for a moment…done.
[SW1]int e0/0/1 进入接口敲命令
[SW1-Ethernet0/0/1]port link
[SW1-Ethernet0/0/1]port link-t
[SW1-Ethernet0/0/1]port link-type acc
[SW1-Ethernet0/0/1]port link-type access
[SW1-Ethernet0/0/1]port de
[SW1-Ethernet0/0/1]port de
[SW1-Ethernet0/0/1]port default vlan 10
[SW1-Ethernet0/0/1]un sh
Info: Interface Ethernet0/0/1 is not shutdown.
[SW1-Ethernet0/0/1]int e0/0/2
[SW1-Ethernet0/0/2]port lin
[SW1-Ethernet0/0/2]port link-t
[SW1-Ethernet0/0/2]port link-type acc
[SW1-Ethernet0/0/2]port de
[SW1-Ethernet0/0/2]port default vlan 20
[SW1-Ethernet0/0/2]un sh
Info: Interface Ethernet0/0/2 is not shutdown.
[SW1-Ethernet0/0/2]int e0/0/3
[SW1-Ethernet0/0/3]port link
[SW1-Ethernet0/0/3]port link-t
[SW1-Ethernet0/0/3]port link-type acc
[SW1-Ethernet0/0/3]port de
[SW1-Ethernet0/0/3]port default vlan 10
[SW1-Ethernet0/0/3]un sh
Info: Interface Ethernet0/0/3 is not shutdown.
[SW1-Ethernet0/0/3]int e0/0/4
[SW1-Ethernet0/0/4]p l a
[SW1-Ethernet0/0/4]p d v 20
[SW1-Ethernet0/0/4]un sh
Info: Interface Ethernet0/0/4 is not shutdown.
[SW1-Ethernet0/0/4]q
[SW1]int g0/0/1
[SW1-GigabitEthernet0/0/1]p l t
[SW1-GigabitEthernet0/0/1]p t a vlan 10 20
[SW1-GigabitEthernet0/0/1]un sh
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[SW1-GigabitEthernet0/0/1]
[SW1-GigabitEthernet0/0/1]q
R2路由命令
u t m
Info: Current terminal monitor is off.
sys
system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname R2
[R2]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[R2]int g0/0/1.10
[R2-GigabitEthernet0/0/1.10]dhcp en
[R2-GigabitEthernet0/0/1.10]dhcp enab
[R2-GigabitEthernet0/0/1.10]dhcp enable
[R2]int g0/0/1.10
[R2-GigabitEthernet0/0/1.10]dhcp s
[R2-GigabitEthernet0/0/1.10]dhcp select r
[R2-GigabitEthernet0/0/1.10]dhcp select relay
[R2-GigabitEthernet0/0/1.10]dhcp r
[R2-GigabitEthernet0/0/1.10]dhcp relay s
[R2-GigabitEthernet0/0/1.10]dhcp relay server-ip 14.0.0.2
[R2-GigabitEthernet0/0/1.10]int g0/0/1.20
[R2-GigabitEthernet0/0/1.20]dhcp s
[R2-GigabitEthernet0/0/1.20]dhcp sel
[R2-GigabitEthernet0/0/1.20]dhcp select r
[R2-GigabitEthernet0/0/1.20]dhcp select relay
[R2-GigabitEthernet0/0/1.20]dhcp r
[R2-GigabitEthernet0/0/1.20]dhcp relay s
[R2-GigabitEthernet0/0/1.20]dhcp relay server-ip 14.0.0.2
[R2-GigabitEthernet0/0/1.20]un sh
Info: Interface GigabitEthernet0/0/1.20 is not shutdown.
[R2-GigabitEthernet0/0/1.20]dis t
[R2-GigabitEthernet0/0/1.20]dis this
[V200R003C00]
interface GigabitEthernet0/0/1.20
dhcp select relay
dhcp relay server-ip 14.0.0.2
return
[R2-GigabitEthernet0/0/1.20]int g0/0/1
[R2-GigabitEthernet0/0/1]int g0/0/1.10
[R2-GigabitEthernet0/0/1.10]dis this
[V200R003C00]
interface GigabitEthernet0/0/1.10
dhcp select relay
dhcp relay server-ip 14.0.0.2
return
[R2-GigabitEthernet0/0/1.10]q
[R2]int g0/0/2
[R2-GigabitEthernet0/0/2]ip add 14.0.0.1 24
[R2-GigabitEthernet0/0/2]un sh
Info: Interface GigabitEthernet0/0/2 is not shutdown.
[R2-GigabitEthernet0/0/2]int g0/0/0
[R2-GigabitEthernet0/0/0]ip add 12.0.0.1 24
[R2-GigabitEthernet0/0/0]un sh
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R2-GigabitEthernet0/0/0]
Please check whether system data has been changed, and save data in time
Configuration console time out, please press any key to log on
sys
Enter system view, return user view with Ctrl+Z.
[R2]int g0/0/1.10
[R2-GigabitEthernet0/0/1.10]arp b
[R2-GigabitEthernet0/0/1.10]arp broadcast en
[R2-GigabitEthernet0/0/1.10]arp broadcast enable
Error: This interface is not a termination interface.
[R2-GigabitEthernet0/0/1.10]arp broadcast enable
Error: This interface is not a termination interface.
[R2-GigabitEthernet0/0/1.10]
sys
Enter system view, return user view with Ctrl+Z.
[R2]int g0/0/1.10
[R2-GigabitEthernet0/0/1.10]do
[R2-GigabitEthernet0/0/1.10]dot1q t
[R2-GigabitEthernet0/0/1.10]dot1q termination v
[R2-GigabitEthernet0/0/1.10]dot1q termination vid 10
[R2-GigabitEthernet0/0/1.10]arp b
[R2-GigabitEthernet0/0/1.10]arp broadcast en
[R2-GigabitEthernet0/0/1.10]arp broadcast enable
[R2-GigabitEthernet0/0/1.10]ip add 192.168.10.1 24
Jun 29 2020 10:12:01-08:00 R2 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/1.10 has entered the UP state.
[R2-GigabitEthernet0/0/1.10]un sh
Info: Interface GigabitEthernet0/0/1.10 is not shutdown.
[R2-GigabitEthernet0/0/1.10]q
[R2]int g0/0/1.20
[R2-GigabitEthernet0/0/1.20]dot
[R2-GigabitEthernet0/0/1.20]dot1q t
[R2-GigabitEthernet0/0/1.20]dot1q termination vla
[R2-GigabitEthernet0/0/1.20]dot1q termination vl
[R2-GigabitEthernet0/0/1.20]dot1q termination vi
[R2-GigabitEthernet0/0/1.20]dot1q termination vid 20
[R2-GigabitEthernet0/0/1.20]ip add 192.168.20.1 24
Jun 29 2020 10:13:54-08:00 R2 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
on the interface GigabitEthernet0/0/1.20 has entered the UP state.
[R2-GigabitEthernet0/0/1.20]un sh
Info: Interface GigabitEthernet0/0/1.20 is not shutdown.
[R2-GigabitEthernet0/0/1.20]di th
[R2-GigabitEthernet0/0/1.20]dis th
[R2-GigabitEthernet0/0/1.20]dis th
[V200R003C00]
interface GigabitEthernet0/0/1.20
dot1q termination vid 20
ip address 192.168.20.1 255.255.255.0
dhcp select relay
dhcp relay server-ip 14.0.0.2
return
[R2-GigabitEthernet0/0/1.20]
[R2-GigabitEthernet0/0/1.20]q
[R2]ip rou
[R2]ip route-
[R2]ip route-static 15.0.0.0 24 12.0.0.2
The device is running!
R1路由命令
u t m
Info: Current terminal monitor is off.
sys
system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname R1
[R1]
sys
Enter system view, return user view with Ctrl+Z.
[R1]sysname 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
[R1-GigabitEthernet0/0/0]ip add 14.0.0.2 24
[R1-GigabitEthernet0/0/0]
Jun 29 2020 10:18:45-08:00 R1 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
[R1-GigabitEthernet0/0/0]dhcp se
[R1-GigabitEthernet0/0/0]dhcp select g
[R1-GigabitEthernet0/0/0]dhcp select global
[R1-GigabitEthernet0/0/0]un sh
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R1-GigabitEthernet0/0/0]
[R1-GigabitEthernet0/0/0]q
[R1]ip pool dhcp15
Info: It’s successful to create an IP address pool.
[R1-ip-pool-dhcp15]netw
[R1-ip-pool-dhcp15]network 15.0.0.0 mask 24
[R1-ip-pool-dhcp15]ga
[R1-ip-pool-dhcp15]gateway-list 8.8.8.8 2.2.2.2
Error:The network section should be within the subnet of the pool.
[R1-ip-pool-dhcp15]gateway-list 15.0.0.1
[R1-ip-pool-dhcp15]dns
[R1-ip-pool-dhcp15]dns-list 8.8.8.8 2.2.2.2
[R1-ip-pool-dhcp15]exc
[R1-ip-pool-dhcp15]excluded-ip-address 15.0.0.100 15.0.0.254
[R1-ip-pool-dhcp15]st
[R1-ip-pool-dhcp15]static-bind ip-
[R1-ip-pool-dhcp15]static-bind ip-address 15.0.0.88 mac-
[R1-ip-pool-dhcp15]static-bind ip-address 15.0.0.88 mac-address 5489-9889-048
A
[R1-ip-pool-dhcp15]q
[R1]ip pool dhcpvlan10
Info: It’s successful to create an IP address pool.
[R1-ip-pool-dhcpvlan10]network 192.168.10.0 mask 24
[R1-ip-pool-dhcpvlan10]gate
[R1-ip-pool-dhcpvlan10]gateway-list 192.168.10.1
[R1-ip-pool-dhcpvlan10]dns
[R1-ip-pool-dhcpvlan10]dns-list 8.8.8.8 2.2.2.2
[R1-ip-pool-dhcpvlan10]q
[R1]ip pool dhcpvlan20
Info: It’s successful to create an IP address pool.
[R1-ip-pool-dhcpvlan20]net
[R1-ip-pool-dhcpvlan20]netw
[R1-ip-pool-dhcpvlan20]network 192.168.20.1 mask 24
[R1-ip-pool-dhcpvlan20]geate
[R1-ip-pool-dhcpvlan20]ga
[R1-ip-pool-dhcpvlan20]gateway-list 192.168.20.1
[R1-ip-pool-dhcpvlan20]dns
[R1-ip-pool-dhcpvlan20]dns-list 8.8.8.8
[R1-ip-pool-dhcpvlan20]q
[R1]ip rou
[R1]ip route-
[R1]ip route-static 0.0.0.0 0.0.0.0 14.0.0.1
R3路由命令
The device is running!
u t m
Info: Current terminal monitor is off.
sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname R3
[R3]int g0/0/0
[R3-GigabitEthernet0/0/0]ip add 12.0.0.2 24
[R3-GigabitEthernet0/0/0]un sh
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R3-GigabitEthernet0/0/0]q
[R3]dhcp en
[R3]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[R3]int g0/0/1
[R3-GigabitEthernet0/0/1]ip add 15.0.0.1 24
[R3-GigabitEthernet0/0/1]dhcp se
[R3-GigabitEthernet0/0/1]dhcp select r
[R3-GigabitEthernet0/0/1]dhcp select relay
[R3-GigabitEthernet0/0/1]dhcp r
[R3-GigabitEthernet0/0/1]dhcp relay ser
[R3-GigabitEthernet0/0/1]dhcp relay server-ip 14.0.0.2
[R3-GigabitEthernet0/0/1]un sh
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[R3-GigabitEthernet0/0/1]dis th
[R3-GigabitEthernet0/0/1]dis th
[V200R003C00]
interface GigabitEthernet0/0/1
ip address 15.0.0.1 255.255.255.0
dhcp select relay
dhcp relay server-ip 14.0.0.2
return
[R3-GigabitEthernet0/0/1]
sys
Enter system view, return user view with Ctrl+Z.
[R3]ip rou
[R3]ip route-
[R3]ip route-static 0.0.0.0 0.0.0.0 12.0.0.1
所有的pc都调成DHCP
命令行ipconfig查看ip地址,ping pc5的ip15.0.0.88,显示ping通