DHCP protocol

  

As we saw earlier, when using the TCP/IP protocol, you must use the same NetID and a different HostID if you want to pass information directly between computers. This way you have to set the IP and manage the records for each computer. If you want to manage a larger network or the computer nodes change frequently (such as dial-up network), it can be said that it is very annoying and there are many opportunities for error. In addition, if the IP re-planning is carried out, the workload is quite amazing.

In the face of these situations, DHCP can say that your Bodhisattva has not only saved the lives but also saved a lot of power. Let us uncover the mystery of DHCP together

What is DHCP

DHCP is the abbreviation of DynamicHostConfigurationProtocol. Its predecessor is BOOTP. BOOTP was originally used on the network for the diskless host connection. The network host using BOOTROM instead of the disk boot and connected to the network BOOTP can automatically set the TCP/IP environment for those hosts.

DHCP can be said to be an enhanced version of BOOTP. It is divided into two parts, one is the server side and the other is the client side. All IP network settings are centrally managed by the DHCP server and are responsible for handling the client's HDCP requirements and the client uses the IP environment data assigned from the server.

DHCP function

First, there must be a DHCP working on the network. It will listen to the network's DHCP request. It provides two IP positioning methods.

AutomaticAllocation automatically assigns it. The situation is that the DHCP client will always use this address once it has been successfully leased from the DHCP server to the IP address for the first time.

DynamicAllocation Dynamic Allocation When DHCP is first leased from the HDCP server to an IP address, it is not permanently used. As long as the lease expires, the client has to release the IP address to give Used by other workstations. Of course, the client can also renew the lease or lease other IP addresses. Dynamic allocation is obviously more flexible than automatic allocation, especially when your actual IP address is insufficient. For example, if you are an ISP, you can only provide 200 IP addresses for dial-up customers, but it does not mean that your customers can only There are 200. Because it is impossible to know that your customers are all connected to the Internet at the same time, in addition to their respective behavioral habits may also be the limit of the telephone line. This way you can use the 200 addresses to be rented to the dial-up customers. That's why when you use winipcfg to view your IP address, it will be different for each call (unless you are applying for a fixed IP. The usual ISP can satisfy this requirement. Of course, you may have to pay another fee. ). Of course, the ISP does not necessarily use DHCP to assign addresses but the principle is the same as using IPPool.

In addition to dynamically setting the IP address, DHCP can also reserve some IP for some special-purpose machines. It can also assign a fixed IP address according to the MAC address. This can give you a bigger Design space. At the same time, DHCP can also help the client to specify the network gateway routerNetMaskDNS server WINS server and so on. You can hardly make any IP environment settings except the DHCP option on the client.

The working form of DHCP

depends on whether the client will log in to the network for the first time.

When logging in for the first time

IP lease request When the DHCP client logs in to the network for the first time, the client finds that there is no IP data on the machine and it will be sent to the network. The road sends out a Dhcpdiscover packet. Because the client does not know which network it belongs to, the source address of the packet will be 0.0.0.0 and the destination address will be 255.255.255.255 and then the information of Dhcpdiscover will be attached to the network for broadcast.

The Dhcpdiscover wait time is preset to 1 second, that is, when the client sends the first Dhcpdiscover packet and does not get a response within 1 second, the second Dhcpdiscover broadcast will be performed. In the absence of a response, the client will have four Dhcpdiscover broadcasts (including the first one), except for the first time, waiting for one second, and the other three waiting times are 91,316 seconds. If the client does not get a response from the DHCP server, an error message is displayed to announce the failure of Dhcpdiscover. After that, based on the user's selection system, the Dhcpdiscover request will continue to be repeated after 5 minutes.

Providing IP leased address When the DHCP server listens to the Dhcpdiscover broadcast sent by the client, it will select the first vacant IP response from the address that has not yet been leased to the client. A Dhcpoffer Packet.

Because the client does not have an IP address at the beginning, it will have its MAC address information in its Dhcpdiscover packet and have an XID number to identify the Dhcpoffer packet that the packet DHCP server responds to. The information is passed to the customer who requested the lease. The Dhcpoffer packet will contain a lease term based on the settings on the server side.

Accepting IP leases If the client receives multiple DHCP servers on the network, it only needs to receive the first Dhcpoffer and will send a Dhcprequest broadcast packet to the network to tell all DHCP servers that it will accept the request. Which server provides the IP address.

At the same time, the client will also send an ARP to the network (AddressResolutionProtocol will be encountered below). The packet is queried on the network. Is there any other machine that uses the IP address? If the IP address is already occupied by the client, then A Dhcpdeclient packet will be sent to the DHCP server to reject its Dhcpoffer and resend the Dhcpdiscover message.

In fact, not all DHCP clients will unconditionally accept the offer of the DHCP server, especially if these hosts have other TCP/IP related client software installed. The client can also use the Dhcprequest to make a DHCP selection to the server. These choices will be filled in the DHCPOptionField with different numbers.

The number represents the meaning 01Sub-netMask03RouterAddress06DNSServerAddress0FDomainName2CWINS/NBNSServerAddress2EWINS/NBTNodeType2FNetBIOSScopeID

In other words The settings on the DHCP server are not necessarily consistent with all clients. The client can retain some of its own TCP/IP settings.

IP lease confirmation When the DHCP server receives the Dhcprequest from the client, it will send a Dhcpack response to the client to confirm the official validity of the IP lease. This completes a complete DHCP work process.

After the first login

Once the DHCP client successfully obtains the DHCP lease from the server, it will not be necessary unless its lease has expired and the IP address is reset back to 0.0.0.0. After sending the Dhcpdiscover information, it will directly send the Dhcprequest message to the DHCP server using the IP address that has been leased. The DHCP server will let the client use the original IP address. If there is no problem, directly respond to Dhcpack to confirm. If the address has expired or has been used by another machine, it will respond with a Dhcpnack packet to the client asking it to re-execute Dhcpdiscover.

As for the lease term of IP, it is very elegant. It is not as simple as renting a house. Take NT as an example. A DHCP workstation will issue a dhcprequest at half the lease term in addition to issuing a dhcprequest request at boot time. If the DHCP server is not confirmed at this time, the workstation can continue to use the IP and then the workstation will not be able to own the IP if it is not confirmed by half of the remaining lease term (ie, 75% of the lease). It is. As for why it is not until the end of the lease term, I will give up the IP. Sorry, the younger brother is not learning the unscrupulous person. I have to go deeper. I only know that when you want to answer the MCSE question, you must remember that NT is working this way.

Of course, you can also use the command to release the DHCP lease at any time, even if your lease was acquired in the previous second.

DHCP operation across the network

The above situation is carried out within the same network, but if the DHCP server is installed on other networks, the DHCP client has not yet The IP environment is set so that the Router address is not known and some Routers do not necessarily pass the DHCP broadcast packet. At this time, we can use the DHCPAgent (or DHCPProxy) host to take over the client's DHCP request and then pass the request to the real DHCP server. The device then passes the reply from the server to the client. Here the Proxy host must have its own routing capability.

Of course, you can also install a DHCP server on each network. However, the cost of the device will increase and the management will be scattered. Of course, if you are in a very large network, such a balanced architecture is still desirable.

Copyright © Windows knowledge All Rights Reserved