DHCP原理及实验
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
DHCP原理及试验
DHCP支持3种IP地址分配机制:
1.自动分配Automatic allocation,dhcp 分配一个永久的IP地址给客户端
2.动态分类Dynamic allocation,DHCP分配一个有时间限制的IP 地址给库户端(或者直到客户端明确的放弃地址)
3.手工分配 Manual allocation 管理员分配IP地址给客户端,DHCP只是简单的将所分配的地址传递给客户端。
DHCP桢格式是基于BOOTP的,确保了和BOOTP的兼容性。
CISCO ios全面支持DHCP,支持管理分配,地址获取,如果一个DHCP 服务不能满足当前要求,它可以向其他DHCP发起请求。
DHCP交换过程
发送DHCPDISCOVER广播
Client---------------------------------------------------ÆServer
DHCPOFFER单播
Client<----------------------------------------------------- Serve
DHCPrequest广播
Client---------------------------------------------------ÆServer
DHCPACK单播
Client<----------------------------------------------------- Server
首先客户端发出一个DHCP的发现广播,所有DHCP服务器都会接
到这个请求,所有的DHCP服务器都回应一个OFFER单播,这个单播提供了具体的配置参数。
客户端会选择使用第一个收到的OFFER,并发送一个request广播。
这个广播会被所有刚才提供了OFFER的DHCP服务器接到,因此其他的未被使用的DHCP服务器可以收回自己刚才的OFFER。
正确的DHCP服务器返回一个ACK单播确认这次OFFER。
另:如果在DHCPSERVER提供的OFFER里参数有错误,那么客户端会发出一个DHCPdecline广播信息给DHCP服务器。
如果在协商期间发生错误或者客户端太长时间不响应服务器,那服务器会发出一个DHCPNAK的拒绝广播消息,表明刚才提供的OFFER 没有被分配。
DHCP如何选择正确的地址给客户端:
1.如果客户端不是直接相连(DHCP发现广播消息里的giaddr 字段非0),那么DHCP服务器会选择一个包含这个字段地址所在子网的地支池。
2.如果客户端是直接相连的,那么就会选择包含接收到DHCP 发现广播的接口所在子网的地址池,也就是会选一个和接收到请求的接口一样子网的地址池。
如果接口有辅助IP,那么仅当主IP 所在池被耗尽时才用它。
DHCP中继代理
某个主机起到一个代理作用,将一个物理网络的DHCP客户请求转发到其他非直连的DHCP服务器上,并将回应转发给客户端,这个过程是透明的。
DHCP的数据库是按照树状来组织的
根是一个网络
分支是一个子网
叶子是绑定给客户端的IP
下一级继承上一级的参数,因此像域名这样的参数应该配置在高层如网络或者子网络。
配置:
1.可以配置IOS让IOS使用代理数据库,DHCP代理数据库可以是一个FTP服务器,或者TFTP服务器或者RCP(remote copy protocol)服务器:
Router(config)# ip dhcp database url [timeout seconds | write-delay seconds]
The following example stores bindings on host 172.16.4.253. The file transfer protocol is FTP. The server should wait 2 minutes (120 seconds) before writing database changes.
ip dhcp database
ftp://user:password@172.16.4.253/router-dhcp write-delay 120 ip dhcp excluded-address 172.16.1.100 172.16.1.103
ip dhcp excluded-address 172.16.2.100 172.16.2.103
2.配置DHCP地址池,进入DHCP配置模式
2509rj(config)#ip dhcp pool test2
2509rj(dhcp-config)#
然后配置:
network 192.168.1.0 255.255.255.0 /配置可分配的网络地址段
dns-server 192.168.1.99 /DNS服务器的地址
default-router 192.168.1.98 /网关地址
netbios-name-server 192.168.1.97 /WINS服务器地址
netbios-node-type m-node /Netbios节点模式配置
lease 10./租期
由于一些IP地址已经被一些接口和主机使用,所以这些IP应该被排除在外,不能用于分配,在全局配置模式下执行:
ip dhcp excluded-address 192.168.1.90 192.168.1.100 /头尾的IP也属于被排除范围
输出结果看看:
2509rj#sh ip dhcp binding
Bindings from all pools not associated with VRF:
IP address Client-ID/ Lease expiration Type
Hardware address/
User name
192.168.1.11 0100.16d3.0d19.06 Mar 11 1993 12:23 AM Automatic
输出表明是自动分配的
3.手工绑定配置
手工绑定是不能在已经使用network命令的地址池中的:
2509rj(dhcp-config)#host 192.168.1.22 /24
% This command may not be used with network, origin or vrf pools.
也就是说要进行手工绑定,必须为每个地址都配一个地址池名:2509rj(config)#ip dhcp pool test2
2509rj(dhcp-config)#host 192.168.1.22 /24
下面需要指定客户端硬件地址或者客户端标志:
微软主机要求使用客户端标志命令来配置,不能用硬件地址来配置Client-identifier 参数是介质类型和MAC地址的组合,例如MAC为b7.0813.8811.66在以太网介质上则组合为01b7.0813.8811.66,前面的01是介质类型代码。
2509rj(dhcp-config)#client-identifier 0100.16d3.0d19.06
2509rj#sh ip dhcp binding
Bindings from all pools not associated with VRF:
IP address Client-ID/ Lease expiration Type
Hardware address/
User name
192.168.1.22 0100.16d3.0d19.06 Infinite Manual 输出显示了绑定生效,类型是手工,租期永久
如果改用hardware-address 0016.d30d.1906 ieee802来指定的话,测试发现windows系统不能正常获得指定的地址
4.DHCP继承性测试
假设有3个网络
192.168.0.0 /16
192.168.1.0/24
192.168.2.0/24
每个网络都配置成一个DHCP池,在最上层网络配置DNS,WINS,其他子网各自配置各自的网关。
ip dhcp pool mask16
network 192.168.0.0 255.255.0.0
dns-server 192.168.168.168
netbios-name-server 192.168.168.169
!
ip dhcp pool subnet1
network 192.168.1.0 255.255.255.0
default-router 192.168.1.254
lease 15
!
ip dhcp pool subnet2
network 192.168.2.0 255.255.255.0
default-router 192.168.2.254
lease 2
Ethernet adapter 本地连接:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Intel(R) PRO/100 VE Network Connecti
on
Physical Address. . . . . . . . . : 00-16-D3-0D-19-06
Dhcp Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 192.168.1.12
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.254
DHCP Server . . . . . . . . . . . : 192.168.1.100
DNS Servers . . . . . . . . . . . : 192.168.168.168
Primary WINS Server . . . . . . . : 192.168.168.169
Lease Obtained. . . . . . . . . . : 2006年11月15日 22:22:26
Lease Expires . . . . . . . . . . : 2006年11月30日 22:22:26
可以看出,网卡从192。
168。
1。
0/24网络获得了IP,而且DNS,WINS 等都是继承了上级配置。
5.Import导入配置
一个DHCP服务器可以把另一个DHCP服务器的配置参数导入过来。
让R1服务器将刚才2509的DHCP配置导入进来看看:
r1-2514(dhcp-config)#import all
注意导入只能导入诸如DNS,WINS这样的参数,具体的网络范围是不能导进来的,还需要单独配。
同时与上级DHCP通信的接口不能指定固定IP,必须用ip add dhcp的方式让其自动获取,否则将不会导入参数进来。
输出见下:
r1-2514#sh ip dhcp import
Address Pool Name: daoru
Domain Name Server(s): 192.168.168.168
NetBIOS Name Server(s): 192.168.168.169
6.Ip helper-address,该命令是让DHCP交互能跨越路由器。
拓扑:R2(SERVER)------R1-----PC
让R1将DHCP请求转发到R2上,测试PC是否能正常获得IP地址R2上配置:
ip dhcp excluded-address 172.16.1.1 172.16.1.10
!
ip dhcp pool test
network 172.16.1.0 255.255.255.0
dns-server 172.172.172.172
default-router 1.1.1.1
R1配置:
interface Ethernet1
ip address 172.16.1.1 255.255.255.0
ip helper-address 10.0.2.2 这个10。
0。
2。
2地址就是R1与R2相连的地址
看输出结果:
Ethernet adapter 本地连接:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Intel(R) PRO/100 VE Network Connect
on
Physical Address. . . . . . . . . : 00-16-D3-0D-19-06
Dhcp Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 172.16.1.11
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 1.1.1.1
DHCP Server . . . . . . . . . . . : 10.0.2.2
DNS Servers . . . . . . . . . . . : 172.172.172.172
Lease Obtained. . . . . . . . . . : 2006年11月15日 23:03:42
Lease Expires . . . . . . . . . . : 2006年11月16日 23:03:42
成功的跨越R1而获得IP.
R2上的调试信息:
r2-2514#
*Mar 1 00:11:52.719: DHCPD: DHCPDISCOVER received from client 0100.16d3.0d19.06 through relay 172.16.1.1.
*Mar 1 00:11:52.723: DHCPD: requested address 192.168.1.12 is not on subnet 172.16.1.0.
r2-2514#
*Mar 1 00:11:54.723: DHCPD: assigned IP address 172.16.1.11 to client 0100.16d3.0d19.06.
*Mar 1 00:11:54.723: DHCPD: Sending DHCPOFFER to client 0100.16d3.0d19.06 (172.16.1.11).
*Mar 1 00:11:54.727: DHCPD: unicasting BOOTREPLY for client 0016.d30d.1906 to relay 172.16.1.1.
*Mar 1 00:11:55.323: DHCPD: DHCPREQUEST received from client 0100.16d3.0d19.06.
*Mar 1 00:11:55.327: DHCPD: Sending DHCPACK to client 0100.16d3.0d19.06 (172.16.1.11).
*Mar 1 00:11:55.331: DHCPD: unicasting BOOTREPLY for client 0016.d30d.1906 to relay 172.16.1.1.
r2-2514#
*Mar 1 00:12:01.367: DHCPD: DHCPREQUEST received from client 0100.16d3.0d19.06.
*Mar 1 00:12:01.367: DHCPD: Sending DHCPACK to client 0100.16d3.0d19.06 (172.16.1.11).
*Mar 1 00:12:01.371: DHCPD: unicasting BOOTREPLY to client 0016.d30d.1906 (172.16.1.11).
本文参考:/univercd/cc/td/doc/product/software/ios122/122cgc r/fipr_c/ipcprt1/1cfdhcp.htm
/en/US/products/sw/iosswrel/ps1835/products_com mand_reference_chapter09186a0080087376.html。