当前位置:网站首页>How DHCP router works

How DHCP router works

2022-07-07 06:58:00 Wangzai sec

DHCP- Router

stay TCP/lP In the network , Every computer wants to communicate , Access resources on the network , All must be configured TCP/IP Parameters , Some of the main TCP/IP Parameters such as lP Address 、 Subnet mask 、 The default gateway 、DNS Servers are essential . There are two ways to configure these parameters :

Manual configuration

Automatically assigned ( Automatic direction DHCP Server get  IP Address )

Manual DHCP Distribute : The administrator specifies preallocated IP Address ,DHCP It's just that the IP Address to device .

Automatically DCHP Distribute :DHCP Select static... From the available address pool IP Address , Automatically assign it permanently to the device . There is no lease term problem , The address is permanently assigned to the device .

dynamic DHCP Distribute :DHCP Automatically and dynamically allocate or rent from the address pool IP Address , The service life is a limited period of time selected by the server , Or until the client tells DHCP The server does not need this address anymore .

Manual configuration  TCP/IP Parameter is a method used by some network administrators . Usually , The network administrator needs to create a A detailed configuration list , And take it with you or store it on the computer , So that it can be viewed and configured at any time IP Address 、 Subnet mask and default gateway and  DNS Server's  IP Address . This method seems simple and feasible , But it is quite time-consuming and error prone .

Automatically assigned  TCP/IP Parameters can avoid the heavy workload caused by manual configuration 、 Time consuming 、 Error prone 、 Address conflicts and many other problems , Just deploy one to provide automatic allocation  TCP/IP Parameter server , Other computers can access the Internet without configuration or extremely simple configuration . We call this kind of server  DHCP The server , Get... Dynamically  IP Address of the Computers are DHCP client .

DHCP The full name is Dynamic  Host Configuration Protocol( Dynamic Host Configuration Protocol ), By IETF (Internet Engineering Task Force,Internet  Engineering task force ) Design and development of , Used exclusively for  TCP/IP The Internet The computer in automatically assigns IP Address , And finish TCP/IP Parameters ( Include IP Address 、 Subnet mask 、 The default gateway and DNS The server etc. ) Configured Protocol . DHCP The server can start from the preset  IP Automatically assign to hosts in the address pool  IP Address , It can not only solve  IP The problem of address conflict , It can also be recycled in time  IP Address to improve  IP Address utilization .

When to use DHCP  service In practice , Generally, it is necessary to adopt  DHCP Server to automatically allocate  TCP/IP Parameters :

(1) The scale of the network is large , Need to allocate in the network  IP There are many hosts with addresses , Especially in the network to add and delete Except for the network host or when you want to reconfigure the network , Manual configuration requires a lot of work , And often because users do not abide by the rules And there was an error , Lead to  IP Address conflicts, etc , You can use  DHCP service .

(2) There are many hosts in the network , and IP Not enough address , You can also use DHCP Server to alleviate this problem . For example, there is  260  Computers , Use static  IP Address time , Each computer needs to reserve one  IP The earth site , That is, common needs  260  individual  IP Address , But available  IP The address is  254  individual , If manual configuration is adopted , There will always be  6  Station meter The computer cannot access the network , But in practice , this 260  Computers cannot be turned on at the same time , Use DHCP just Can be adjusted  IP Use of address . But this situation is right ISP(Internet Service Provider, Internet service provider ) It is a very serious problem , If ISP Yes 100000  Users , If you need 100000  individual IP Address ? therefore The solution to this problem is to use DHCP service . We use dial-up Internet access from ISP There are dynamic gains Get a public  IP Address .

(3) Some hosts ( For example, laptops or  PDA) When moving in different subnets , Can pass DHCP When moving to a subnet, automatically obtain the  IP Address , No additional configuration is required , So as to meet the needs of mobile users . Auditorium 、 The restaurant 、 Hotels and other public places with large mobile users are usually use  DHCP Server allocation  IP Address .

DHCP To client / Working in server mode , Like any other client / Server relationships work the same . When one PC Connect to DHCP Server time , The server assigns or rents one IP Give me the address PC. then PC Use rented IP Address connected to the network , Until the end of the lease . The host must contact regularly DHCP Server to renew the lease . This leasing mechanism ensures that hosts will not continue to occupy addresses they no longer need when they are removed or shut down .DHCP The server will return these addresses to the address pool , Reallocate as needed .

BOOTP And DHCP

Bootstrap agreement (BOOTP) Defined in RFC 951, yes DHCP The forerunner of , And DHCP There are some similarities in operation .BOOTP Available for diskless workstation to download address and start configuration . Diskless workstation has no hard disk and operating system . for example , Many automatic cash registers in supermarkets are diskless workstations .DHCP and BOOTP Are based on the client / Server mode , And use UDP port 67 And 68. These ports are still called BOOTP port . The four basic requirements for joining the network IP Parameters :

IP Address 、 default gateway 、 Subnet mask 、DNS Server address

DHCP And BOOTP There are three main differences between :

The first difference is , Use BOOTP when , The host information must be pre configured manually in the server database , and DHCP Then it is allowed to dynamically assign the network address and configuration to the newly connected host . When BOOTP Client request IP Address time ,BOOTP The server searches predefined tables with clients MAC Address matching entries . If the entry exists , Then the corresponding IP The address will be returned to the client . in other words ,BOOTP The server must be pre configured MAC Address and IP Binding between addresses .

DHCP Allow network address recovery and reassignment through rental mechanism . say concretely , adopt DHCP Mechanism assigned to the client IP The address is valid for a limited lease term . After the expiration of the lease term , You can put this IP The address is reassigned to another client ; During the lease term , If the client moves to another subnet , You can get IP Address assignment . The client can also renew the lease and keep the same IP Address .BOOTP Do not use rental mechanism .BOOTP Reserved for clients IP Address , It cannot be assigned to any other client .

BOOTP The amount of information provided to the host is limited .DHCP Provide additional IP Configuration parameters , for example WINS And domain names, etc .

 DHCP  The working process of the service

1DHCP The workstation logs into the network for the first time

When DHCP When the client first logs into the network , Mainly through 4  Stages and DHCP The server establishes a connection , Pictured   Shown .

——DHCP DISCOVER( Find out )IP Lease options ——

——DHCP OFFER( Provide )IP The lease provides ——

——DHCP REQUEST( request )IP Lease options ——

——DHCP ACK( confirm )IP Lease confirmation ——

 

1——DHCP DISCOVER( Find out )IP Lease options ——

When  DHCP When the client starts for the first time, there is no  IP Address , I don't know what the server is  IP Address , Because the host does not have a valid IP Information , So it uses the 2 Tier and tier 3 The layer broadcast address communicates with the server . So the client is in the current subnet with 0.0.0.0  As the source address , With 255.255.255.255  As the destination address to DHCP Server broadcast DHCP Discover message , Apply for one  IP Address .DHCP Discover The message also includes the client's MAC Address and host name .

2——DHCP OFFER( Provide )IP The lease provides ——

DHCP Provided by the server  IP Address DHCP The server receives  DHCP Discover After the message , It will be provided with an unallocated... From the address pool IP Address , And put the provided  IP The address is temporarily marked “ Unavailable ” . Server unicast  DHCP Offer The message is sent back to the client ,DHCP Offer The information contained in the message is shown in the figure . If the network contains more than one DHCP The server , Then the client may receive several  DHCP Offer message , Clients usually only recognize the first DHCP Offer.

When DHCP Server received DHCDISCOVER When the news , It will find a rental IP Address , Create a host containing the requestor MAC Address and rental IP Address of the ARP entry , And use DHCPOFFER Message transmission binding provides message .DHCPOFFER Messages are sent as unicast , The server's second 2 layer MAC The address is the source address , The number of clients 2 The layer address is the destination address .

In some cases , From the server DHCP Message exchange may be broadcast , Not unicast .

DHCP Request and provide DHCP The client will wait 1  second , if  DHCP The client failed to get DHCP The address provided by the server , Will separate With 2  second 、4  second 、8  The second and 16  Rebroadcast four times at an interval of seconds , If you haven't got DHCP Response from the server , be  DHCP The client will start with  0~1000  The broadcast request is sent again at a random interval of milliseconds  IP Address . If  DHCP After the above efforts, the client still failed to get any  DHCP The server side gets  IP Address , It could happen One of the following two situations : The client will use the reserved  B Class address  169.254.0.1~169.254.255.254  One of the ranges . ① If the client is using  Windows  2000  And later , also  Windows  The operating system will automatically set IP The function of the address is active , Then the client will automatically start from  Microsoft  Retain  IP Select an automatic private address in the address field (Automatic Private IP Address,APIPA) As one's own  IP Address . Automatic private  IP The range of addresses is 169.254.0.1~169.254.255.254. Use automatic private IP Address , stay DHCP When the server is not available ,DHCP Private can still be used between clients  IP Address to communicate . therefore , Even if there is no DHCP The server , meter Computers can still find each other through their online neighbors . ② If using other operating systems or automatic settings IP The function of address is forbidden , Then the client cannot get IP The earth site , initialization failed . But the client is in the background every  5  Four times per minute  DHCP Discover Information until it receives DHCP Offer Information .

3——DHCP REQUEST( request )IP Lease options ——

The client receives  DHCP Offer after , The broadcast sends a message to the server containing information about DHCP Provided by the server IP Address of the DHCP Request message . If the client does not receive  DHCP Offer Message and remember the previous network configuration , here You can use the previous network configuration ( If the configuration is still valid ).

When the client receives a message from the server DHCPOFFER when , It sends back one DHCPREQUEST news . This message has two functions : First, rent to initiate , First, rent, update and inspect . For lease initiation , Client's DHCPREQUEST The message is required in IP Verify the validity of the address after allocation . This message provides error checking , Ensure that the address assignment is still valid .DHCPREQUEST It is also used as a binding acceptance notification to the selected server , And implicitly reject the binding information provided by other servers .

Many enterprise networks use multiple DHCP The server .DHCPREQUEST Messages are broadcast , Inform this about the acceptance of binding provision DHCP Servers and any other DHCP The server .

4——DHCP ACK( confirm )IP Lease confirmation ——

DHCP The server is receiving DHCP Request  After the message , Immediately send  DHCP Ack Confirmation information , To make sure that Establishment of lease , And this information also includes other  DHCP Option information

The client received DHCP Ack message , utilize ARP Check whether there are the same... On the network  IP The earth site . If the inspection passes , Then the client accepts this IP Address and its parameters . If problems are found , Client to server send out  DHCP Decline Information , And restart the new configuration process . Server received DHCP Decline After the message , Will be The address is marked “ Unavailable ” .

received DHCPREQUEST After the news , The server verifies the rental information , Create a new for the client lease ARP entry , And use unicast DHCPACK Reply to the message . Except for different message type fields ,DHCPACK News and DHCPOFFER The news is the same . Client received DHCPACK After the news , Record the configuration information , And execute for the assigned address APR lookup . If it does not receive a reply , Then it knows that IP The address is valid , Will start using it as your own IP Address .

 2DHCP The workstation logs into the network for the second time

DHCP The client gets  IP When logging into the network again after the address , You don't need to send DHCP Discover Message , Instead, send directly containing the last assigned  IP Address of the  DHCP Request message . When  DHCP Server received  DHCP Request message , Will try to let the client continue to use the original  IP Address , And answer a  DHCP Ack( Confirmation information ) message . If DHCP The server cannot be assigned to the client's original IP Address , Then answer one  DHCP NAck( Unconfirmed Information ) message . When the client receives DHCP NAck After the message , You have to resend  DHCP Request Please send a message Innovative  IP Address .

3DHCP Renewal of lease

 DHCP Server will IP The address is assigned to DHCP After the client , There are restrictions on the rental time ,DHCP The client must Update this lease before it expires . The client is in 50% After the lease time has passed , Please start at regular intervals seek  DHCP The server updates the current lease , If  DHCP When the server answers, the lease is extended . If DHCP The server always No response , During the valid lease period 87.5% when , The client should work with any other DHCP Server communication , and Request to update its configuration information . If the client cannot communicate with all DHCP Get in touch with the server , After the lease expires , It must abandon the current IP Address , And resend a DHCP Discover The message starts the above IP Address acquisition process . The client can actively send a message to the server DHCP Release message , Change the current  IP Address release .

原网站

版权声明
本文为[Wangzai sec]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070239040477.html