当前位置:网站首页>DHCP protocol detailed analysis
DHCP protocol detailed analysis
2022-07-29 02:46:00 【Li-YC】
One 、DHCP Definition
DHCP( Dynamic Host Configuration Protocol ): Is an application layer network protocol . It refers to a period of time controlled by the server IP Address range , When the client logs in to the server, it can automatically get the server assigned IP Address and subnet mask . When we will host the client ip When the address is set to dynamic access mode ,DHCP The server will be based on DHCP The protocol assigns... To the client IP, Enables clients to take advantage of this IP surf the internet .
DHCP Formerly known as BOOTP, stay Linux It can also be seen in the network card configuration of BOOTP,DHCP Introduce a bootp No concept : lease .bootp The assigned address is permanent and dhcp The assigned address can have a time limit
DHCP It is divided into two parts : A server side , The other is the client ( Usually in the network PC、 Printer and other terminal equipment ).
Two 、DHCP Function and characteristics
1、DHCP Can be automatically assigned IP、 Subnet mask 、 gateway 、DNS.
2、DHCP The port used by the client is 68, The server port is 67, The use of UDP Application layer protocol .
3、DHCP Generally, servers are not allocated IP, Because they need to be fixed IP, therefore DHCP Generally, it is only allocated to the host of the office environment IP
4、DHCP The server and client need to be in a LAN , Allocating IP You need to broadcast many times , but DHCP It can also be allocated to hosts in other network segments IP, As long as the router between the two network segments is connected, it can forward DHCP Configure the request , But this requires the router to configure the relay function .
3、 ... and 、DHCP The server IP There are three ways to allocate
1、 Automatic allocation method ,DHCP The server specifies a permanent IP Address , once DHCP The first successful client from DHCP Server side lease to IP After the address , You can use the address permanently ,
2、 Dynamic distribution mode ,DHCP The server specifies a time limited IP Address , When the time expires or the host explicitly gives up the address , This address can be used by other hosts .
3、 Manual allocation method , Client's IP The address is specified by the network administrator ,DHCP The server will only specify IP Address to client host
The third is the most common form of use , The effective use period of the address is called the lease term , Before the expiration of the lease , The client must request the server to continue renting . The server can continue to use after accepting the request , Otherwise, give up unconditionally .
Four 、DHCP relay
By default , Router isolates official blog packets , The received broadcast packets will not be sent from one subnet to another . When DHCP When the server and client are not in the same subnet , The router acting as the default gateway of the client sends broadcast packets to DHCP The subnet where you are , This function is called DHCP relay .
DHCP Relay agent , Is in the DHCP Forwarding between server and client DHCP Data packets . When DHCP The client and server are not on the same subnet , There must be DHCP Relay agent DHCP Request and reply messages ,DHCP Data forwarding of relay agent data , Different from the usual router forwarding , Generally, routing and forwarding are relatively transparent , The equipment will not be modified IP Package content , and DHCP The relay agent received DHCP After the news , Regenerate a DHCP news , Then forward it
DHCP The relay host must have its own routing capability , And the datagrams of both parties are transmitted to each other . If relay is not used , You can also install DHCP The server , But in that case , As a result, the cost of equipment will increase , And the management is also relatively decentralized , Of course , If in a large network , Such a balanced architecture is desirable .

5、 ... and 、DHCP Service workflow
First step : Search phase
When DHCP The first time a client logs on to the network , The computer found nothing on this computer IP Address setting , Will be sent by radio DHCP discover Find information to look for DHCP The server , That is to 255.255.255.255 Send a specific broadcast signal , Every one on the network has TCP/IP All hosts of the protocol will receive the broadcast information , But only DHCP The server will respond .(dhcp discover)
The second step : Provision phase
Received... In the network DHCP discover Found information DHCP The server will respond , It has never been assigned IP Choose one of the address pools to assign to DHCP The client , towards DHCP The client sends an... Containing the assignment IP Address and other settings DHCP offer Provide information , Because at this time, the client has not IP, So the return is also broadcast .(dhcp offer)
The third step : Selection stage
DHCP Client received DHCP offer After providing information , Select the first received offer , Then answer a... By radio DHCP request Request information , This information contains the DHCP Server request IP The content of the address .(DHCP REQUEST)
Step four : Confirmation stage
When DHCP Server received DHCP The client answers DHCP request After requesting information , Defecate DHCP The client sends a message containing the IP Address and other settings DHCP ack Confirmation information , Confirm lease , And specify the lease duration . tell DHCP The client can use the IP Address . then ,DHCP The client will put it TCP/IP Protocol and network card binding , in addition , except DHCP Client selected DHCP Outside the server , Other DHCP The server will take back what it provided IP Address .(DHCP ACK)

in the future DHCP Every time the client logs back on the network , You don't need to send DHCP discover Found information , Instead, send directly containing the last assigned IP Address of the DHCP request Request information . When DHCP When the server receives this message , It will try to make DHCP The client continues to use the original IP Address , And answer a DHCP ack Confirmation information . If so IP The address can no longer be assigned to the original DHCP When the client is in use , be DHCP Server to DHCP The client answers a DHCP nack Deny information . When the original DHCP The client receives this DHCP nack After denying information , It has to be resend DHCP discover Discover information to request new IP Address .
DHCP Renewal
1、 In the past of the lease period 50% At the moment , The client sends unicast to the server DHCP REQUEST Message renewal period .
2、 If you receive from the server DHCP ACK message , Then the lease term will be extended accordingly , Lease renewal succeeded . If not received DHCP ACK message , Then the client continues to use this IP Address . In the past of the lease period **87.5%** At the moment , Send a broadcast to the server DHCP REQUEST Message renewal period .
3、 If you receive from the server DHCP ACK message , Then the lease term will be extended accordingly , Lease renewal succeeded . If not received DHCP ACK message , Then the client continues to use this IP Address . Use at the expiration of the lease term , The client automatically gives up using this IP Address , And start a new DHCP The process .
边栏推荐
猜你喜欢
随机推荐
Multimodal Unsupervised Image-to-Image Translation多通道无监督图像翻译
owt-server源码剖析(四)--video模块分析之Mixer Out
C语言:判断字母
C语言:空心正方形图案
以科技传递温度,vivo亮相数字中国建设峰会
Teach you how to install vscode by hand (with illustrated steps)
QT compilation of IOT management platform 48 characteristic function design
Only when you are far away will you miss
ECCV 2022 | airdet: a small sample target detection method without fine tuning
Flink内核源码(七)Flink SQL提交流程
双for循环
XSS range (II) xss.haozi
where、having、group by、order by,is null,not in,子查询,delete,日期函数
C语言:小乐乐与进制转换
C语言实现三子棋游戏
Understand the evolution of redis architecture in one article
Three implementation methods of Servlet
MySQL basic operation and comprehensive instance project based on MySQL basic operation
MQTT例程
童年的快乐时光









