动态主机配置协议(Dynamic Host Configuration Protocol)-DHCP

动态主机配置协议(Dynamic Host Configuration Protocol)-DHCP

作用:自动分配IP地址、掩码、网关、DNS 输入图片说明

输入图片说明

DHCP工作原理:

输入图片说明

DHCP Discover:(广播,Ethernet) Client——>Server 作用:广播发现DHCP服务器的存在,请求获取IP地址的分配 DHCP Offer:(携带了IP、Mask、GW、DNS) Server——>Client 作用:由Server为Client提供地址信息 DHCP Request: Client——>Server 作用:请求分配相应的IP地址信息 DHCP ACK: Server——>Client 作用:确认分配的地址信息   DHCP报文内容:

输入图片说明 E2|IP|UDP(67,68)|Bootstrap Protocol|FCS   消息类型: 输入图片说明 Discover消息: 输入图片说明   Offer消息: 输入图片说明

输入图片说明 Request消息: 输入图片说明

Ack: 输入图片说明

DHCP配置:

输入图片说明 ①同一个广播域的DHCP DHCP Client PC:本地连接——属性——TCP/IP协议栈v4——自动获取IP地址,自动获取DNS Router: R1(config)#no ip routing——关闭IP Routing功能。 R1(config)#exit R1# R1#show ip route Default gateway is not set Host Gateway Last Use Total Uses Interface ICMP redirect cache is empty   R1(config)#int f0/0 R1(config-if)#no shutdown R1(config-if)#ip address ? A.B.C.D IP address dhcp IP Address negotiated via DHCP pool IP Address autoconfigured from a local DHCP pool R1(config-if)#ip address dhcp——接口使用DHCP来动态获取IP地址   DHCP Server: R3(config)#int f0/0 R3(config-if)#ip add 192.168.10.1 255.255.255.0 R3(config-if)#no shutdown R3(config-if)#exit R3(config)#int f0/1 R3(config-if)#ip add 192.168.20.1 255.255.255.0 R3(config-if)#no shutdown R3(config-if)#exit   配置DHCP地址池:(DHCP Address Pool) R3#show run | s dhcp ip dhcp pool VLAN10——创建地址池,命名为VLAN10 network 192.168.10.0 255.255.255.0——定义网段为192.168.10.0/24(必要) default-router 192.168.10.1 ——定义默认网关192.168.10.1(必要) dns-server 8.8.8.8 ——定义DNS服务器为8.8.8.8(可选) lease 1 1 1——定义租期为1天1小时1分钟(可选)   ip dhcp pool VLAN20 network 192.168.20.0 255.255.255.0 default-router 192.168.20.1 dns-server 9.9.9.9   排除地址: R3(config)#ip dhcp excluded-address 192.168.10.1 192.168.10.100 R3(config)#ip dhcp excluded-address 192.168.20.1 192.168.20.49 R3(config)#ip dhcp excluded-address 192.168.20.101 192.168.20.254 输入图片说明 R2(config)#int f0/0 R2(config-if)#no shutdown R2(config-if)#ip address dhcp R2(config-if)#exit  输入图片说明输入图片说明 R3#debug ip dhcp server packet R3#debug ip dhcp server events 输入图片说明

输入图片说明 Debug消息: R3# *Mar 1 00:31:16.015: DHCPD: Sending notification of DISCOVER: *Mar 1 00:31:16.019: DHCPD: htype 1 chaddr c000.3308.0000 *Mar 1 00:31:16.019: DHCPD: remote id 020a0000c0a80a0100000000 *Mar 1 00:31:16.019: DHCPD: circuit id 00000000 *Mar 1 00:31:16.019: DHCPD: DHCPDISCOVER received from client 0063.6973.636f.2d63.3030.302e.3333.3038.2e30.3030.302d.4661.302f.30 on interface FastEthernet0/0. *Mar 1 00:31:16.023: DHCPD: Seeing if there is an internally specified pool class: *Mar 1 00:31:16.023: DHCPD: htype 1 chaddr c000.3308.0000 *Mar 1 00:31:16.023: DHCPD: remote id 020a0000c0a80a0100000000 *Mar 1 00:31:16.023: DHCPD: circuit id 00000000 R3# *Mar 1 00:31:16.023: DHCPD: Allocate an address without class information (192.168.10.0) R3# *Mar 1 00:31:18.027: DHCPD: Adding binding to radix tree (192.168.10.103) *Mar 1 00:31:18.027: DHCPD: Adding binding to hash tree *Mar 1 00:31:18.027: DHCPD: assigned IP address 192.168.10.103 to client 0063.6973.636f.2d63.3030.302e.3333.3038.2e30.3030.302d.4661.302f.30. *Mar 1 00:31:18.027: DHCPD: Sending DHCPOFFER to client 0063.6973.636f.2d63.3030.302e.3333.3038.2e30.3030.302d.4661.302f.30 (192.168.10.103). *Mar 1 00:31:18.031: DHCPD: broadcasting BOOTREPLY to client c000.3308.0000. *Mar 1 00:31:18.107: DHCPD: DHCPREQUEST received from client 0063.6973.636f.2d63.3030.302e.3333.3038.2e30.3030.302d.4661.302f.30. R3# *Mar 1 00:31:18.111: DHCPD: Sending notification of ASSIGNMENT: *Mar 1 00:31:18.111: DHCPD: address 192.168.10.103 mask 255.255.255.0 *Mar 1 00:31:18.111: DHCPD: htype 1 chaddr c000.3308.0000 *Mar 1 00:31:18.111: DHCPD: lease time remaining (secs) = 90060 *Mar 1 00:31:18.111: DHCPD: No default domain to append - abort update *Mar 1 00:31:18.115: DHCPD: Sending DHCPACK to client 0063.6973.636f.2d63.3030.302e.3333.3038.2e30.3030.302d.4661.302f.30 (192.168.10.103). *Mar 1 00:31:18.115: DHCPD: broadcasting BOOTREPLY to client c000.3308.0000.

问题:如何判断获取哪个地址池的IP地址? 解释:通过接收DHCP Discover消息的接口来判断IP地址是否与本地地址池相匹配。   配置: R3#show run | s dhcp ip dhcp excluded-address 192.168.10.1 192.168.10.100 ip dhcp excluded-address 192.168.20.1 192.168.20.49 ip dhcp excluded-address 192.168.20.101 192.168.20.254 ip dhcp pool VLAN10 network 192.168.10.0 255.255.255.0 default-router 192.168.10.1 dns-server 8.8.8.8 lease 1 1 1 ip dhcp pool VLAN20 network 192.168.20.0 255.255.255.0 default-router 192.168.20.1 dns-server 9.9.9.9 R3#   ②跨广播域的DHCP(必须要提供DHCP中继Relay) 输入图片说明 DHCP Server: ip dhcp excluded-address 192.168.10.1 192.168.10.100 ip dhcp excluded-address 192.168.20.1 192.168.20.49 ip dhcp excluded-address 192.168.20.101 192.168.20.254 ip dhcp pool VLAN10 network 192.168.10.0 255.255.255.0 default-router 192.168.10.1 dns-server 8.8.8.8 lease 1 1 1 ip dhcp pool VLAN20 network 192.168.20.0 255.255.255.0 default-router 192.168.20.1 dns-server 9.9.9.9   DHCP Client 动态获取IP地址   DHCP Relay(DHCP中继) 重要:需要把接口收到DHCP Discover广播消息转换成单播消息发送到DHCP服务器上。 命令:#ip helper-address x.x.x.x R3(config)#int f0/0 R3(config-if)#ip helper-address 34.1.1.4——把F0/0接口收到的广播消息转成单播发送到34.1.1.4 R3(config-if)#exit   输入图片说明输入图片说明 R4收到Discover消息,回应offer到192.168.10.1   R4(config)#ip route 192.168.10.0 255.255.255.0 34.1.1.3——保证R4拥有回去192.168.10.0/24网段的路由条目 R4(config)#int f1/0 R4(config-if)#ip dhcp relay information trusted ——信任DHCP中继消息。

由睿江云运维人员提供,想了解更多,请登陆www.eflycloud.com

转载于:https://my.oschina.net/u/3363053/blog/912514

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值