DHCP(动态主机配置协议)是一个局域网的网络协议。指的是由服务器控制一段lP地址范围,客户机登录服务器时就可以自动获得服务器分配的lP地址和子网掩码。默认情况下,DHCP作为Windows Server的一个服务组件不会被系统自动安装,还需要管理员手动安装并进行必要的配置。
通俗来讲就是,通过该协议给内部网络自动分配IP地址及一些配置信息(集中分发和管理IP地址)
它是基于Client/Server(CS)结构的。
(1)该设备必须拥有所要下放地址广播域内的直接接口或网卡。
(2)该接口或网卡必须自身已经拥有合法IP地址。
DHCP Server(服务器)<------------->DHCP Client(客户端)
<-------------DHCP Discover(广播发送)------------(当刚开始客户端没有地址时,它就会以广播的方式发出DHCP Discover报文,在这个网络范围内问谁能够给我提供地址?)
--------------DHCP Offer(广播发送)------------->(所有的DHCP Server都能够接收到DHCP Client发送的DHCP Discover报文,所有的DHCP Server都会给出响应,向DHCP Client发送一个DHCP Offer报文。 DHCP Offer报文中“Your(Client) IP Address”字段就是DHCP Server能够提供给DHCP Client使用的IP地址,且DHCP Server会将自己的IP地址放在“option”字段中以便DHCP Client区分不同的DHCP Server。DHCP Server在发出此报文后会存在一个已分配IP地址的纪录。)
<-------------DHCP Request(广播发送)-----------(DHCP Client只能处理其中的一个DHCP Offer报文,一般的原则是DHCP Client处理最先收到的DHCP Offer报文。DHCP Client会发出一个广播的DHCP Request报文,在选项字段中会加入选中的DHCP Server的IP地址和需要的IP地址。)
--------------DHCP Ack------------------------->(DHCP Server收到DHCP Request报文后,判断选项字段中的IP地址是否与自己的地址相同。如果不相同,DHCP Server不做任何处理只清除相应IP地址分配记录;如果相同,DHCP Server就会向DHCP Client响应一个DHCP ACK报文,并在选项字段中增加IP地址的使用租期信息。)
1. Discovery DHCP 发现包
2. Offer DHCP 提供包
3. Request DHCP 请求包
4. Ack DHCP 确认包
在配置之前首先得明确一点,就是PC上网必备条件:
1、IP地址
2、网络掩码
3、网关:是一个网络范围内的一个接口的IP地址。
4、DNS:域名系统(服务)协议(DNS)是一种分布式网络目录,主要用于域名与 IP 地址的相互转换,以及控制因特网的电子邮件的发送。
R1(config)#ip dhcp pool ccna //给设备创建一个DHCP服务器的地址池,CCNA为name。
R1(dhcp-config)#network 10.1.1.0 255.255.255.0 //告诉该pool我发的是10.1.1.0/24整个网络范围的地址。
R1(dhcp-config)#default-router 10.1.1.1 //配网关
R1(dhcp-config)#dns-server 8.8.8.8 //配DNS服务
R2#config terminal
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#hostname serve
serve(config)#end
serve#
*Feb 1 22:13:48.599: %SYS-5-CONFIG_I: Configured from console by console
serve#show ip interface brief
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 unassigned YES unset administratively down down
FastEthernet0/1 unassigned YES unset administratively down down
SSLVPN-VIF0 unassigned NO unset up up
serve#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
serve(config)#interface fastEthernet 0/0
serve(config-if)#no shutdown
serve#show ip interface brief
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 unassigned YES unset up up
FastEthernet0/1 unassigned YES unset administratively down down
SSLVPN-VIF0 unassigned NO unset up up
serve#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
serve(config)#interface fastEthernet 0/0
serve(config-if)#ip address 10.1.1.1 255.255.255.0
serve(config-if)#end
serve#
*Feb 1 22:21:22.879: %SYS-5-CONFIG_I: Configured from console by console
serve#show ip interface brief
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 10.1.1.1 YES manual up up
FastEthernet0/1 unassigned YES unset administratively down down
SSLVPN-VIF0 unassigned NO unset up up
serve#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
serve(config)#ip dhcp pool ?
WORD Pool name
serve(config)#ip dhcp pool ccna
serve(dhcp-config)#network 10.1.1.0 255.255.255.0
serve(dhcp-config)#dns-server 114.114.114.114
serve(dhcp-config)#default-router 10.1.1.1
serve(dhcp-config)#end
serve#show running-config
Building configuration...
Current configuration : 1171 bytes
!
upgrade fpd auto
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname serve
!
boot-start-marker
boot-end-marker
!
logging message-counter syslog
!
no aaa new-model
ip source-route
no ip icmp rate-limit unreachable
ip cef
!
!
!
ip dhcp pool ccna
network 10.1.1.0 255.255.255.0
dns-server 114.114.114.114
default-router 10.1.1.1
!
!
no ip domain lookup
no ipv6 cef
!
multilink bundle-name authenticated
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
memory-size iomem 0
archive
log config
hidekeys
!
!
!
!
!
ip tcp synwait-time 5
ip ssh version 1
!
!
!
!
interface FastEthernet0/0
ip address 10.1.1.1 255.255.255.0
duplex auto
speed auto
!
interface FastEthernet0/1
no ip address
shutdown
duplex auto
speed auto
!
ip forward-protocol nd
no ip http server
no ip http secure-server
!
!
!
no cdp log mismatch duplex
!
!
!
!
!
!
control-plane
!
!
!
mgcp fax t38 ecm
!
--More--
R1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#hostname PC
PC(config)#interface fastEthernet 0/0
PC(config-if)#no shutdown
PC(config-if)#
*Feb 1 22:42:59.947: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Feb 1 22:43:00.947: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
PC(config-if)#ip address dhcp
PC(config-if)#
*Feb 1 23:49:06.499: %DHCP-6-ADDRESS_ASSIGN: Interface FastEthernet0/0 assigned DHCP address 10.1.1.2, mask 255.255.255.0, hostname PC
PC#show ip interface brief
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 10.1.1.2 YES DHCP up up
FastEthernet0/1 unassigned YES unset administratively down down
SSLVPN-VIF0 unassigned NO unset up up
PC#
R1(config)#ip dhcp excluded-address 172.16.1.254
R1(config)#ip dhcp excluded-address 172.16.1.100 172.16.1.200
起始地址 结束地址