DHCP protocol overview

Source: Internet
Author: User
Tags continue end client

DHCP is the acronym for Dynamic Host Configuration Protocol, which is formerly a BOOTP. BOOTP was originally used for diskless host-connected networks: Network hosts use the BOOT ROM instead of disk to start and connect to the Internet, BOOTP can automatically set the TCP/IP environment for those hosts. But BOOTP has a disadvantage: you need to obtain prior to the client's hard address, and the corresponding IP is static. In other words, BOOTP is very lack of "dynamic", if in a limited IP resource environment, BOOTP one-to-one corresponding will cause a very considerable waste.

DHCP can be said to be the enhanced version of BOOTP, it is divided into two parts: one is the server side, and the other is the client. All IP network settings are centrally managed by the DHCP server and are responsible for handling the DHCP requirements of the client, while the client uses the IP environment data that is assigned from the server. Compared to BOOTP, DHCP through the concept of "lease", efficient and dynamic allocation of client TCP/IP settings, and, as a compatibility consideration, DHCP also fully take care of the requirements of BOOTP client.

Allocation form of DHCP

First, there must be at least one DHCP job on the network, which listens for DHCP requests on the network and with the client rubbing the TCP/IP settings environment. It provides two types of IP positioning:

Automatic allocation is automatically assigned, in the case that once the DHCP client successfully leases the IP address from the DHCP server side, it is always used.

Dynamic allocation is dynamically allocated and is not permanently used after DHCP first leased to an IP address from the HDCP server, and the client has to release this IP address for use by other workstations as long as the lease expires. Of course, clients can have a higher priority than other hosts to extend (renew) leases, or lease other IP addresses.

Dynamic allocation is obviously more flexible than automatic allocation, especially if your actual IP address is not sufficient, for example, you are an ISP that can only provide 200 IP addresses to dial-up customers, but does not mean that your customer can only have 200. Because to know, your customers can not all the same time on the Internet, in addition to their different behavior habits, it may be the phone line restrictions. In this way, you can use the 200 addresses, in turn, to hire the incoming customers. That's why when you look at an IP address, it's a different reason for each call (unless you're applying for a fixed IP, the usual ISP can meet that requirement, which may cost you another fee). Of course, ISPs do not necessarily use DHCP to allocate addresses, but this concept is the same as the principle of using IP Pool.

DHCP In addition to dynamically set IP address, you can also retain some of the IP to some special use of the machine, it can be fixed at the hard address of the allocation of IP address, which can give you a larger design space. At the same time, DHCP can also help clients to specify Router﹑netmask﹑dns Server﹑wins Server﹑, and so on, you on the client, in addition to the DHCP option tick, almost no need to do any IP environment settings.

How the work of DHCP works

Depending on whether the client is logged on to the network for the first time, the working form of DHCP differs.

The first time you log in:

1. Looking for the Server. When the DHCP client first logs on to the network, the client discovers that there is no IP data set on the computer, it sends a DHCPDISCOVER packet to the network. Because the client does not know which network they belong to, so the packet's source address will be 0.0.0.0, and the destination address is 255.255.255.255, and then attach DHCPDiscover information, broadcast to the network.

In the case of Windows preset, the DHCPDiscover wait time is preset to 1 seconds, which means that when the client sends out the first DHCPDISCOVER packet, the second DHCPDISCOVER broadcast occurs within 1 seconds. If there is no response, the client will have four DHCPDISCOVER broadcasts (including the first), except for the first time waiting for 1 seconds, while the remaining three wait times are 9﹑13﹑16 seconds respectively. If you do not receive a response from the DHCP server, the client displays an error message declaring a dhcpdiscover failure. Then, based on the user's choice, the system will continue to repeat the DHCPDISCOVER process after 5 minutes.

2. Provide IP leased address. When the DHCP server hears the DHCPDiscover broadcast from the client, it will select the front-left IP, along with other TCP/IP settings, to respond to the client with a DHCPOFFER packet from those sites that are not yet leased out.

Since the client does not have an IP address at the beginning, it will have its MAC address information in its DHCPDISCOVER packet and a XID number to identify the packet, and the Dhcpoffer packet that the DHCP server responds to will be passed to the client requesting the lease. Depending on the server-side settings, the Dhcpoffer packet will contain information about the duration of the lease.

3. Accept IP leases. If the client receives a response from multiple DHCP servers on the network, only one of the Dhcpoffer (usually the first ones) is selected, and a DHCPREQUEST broadcast packet is sent to the network, telling all the DHCP servers that it will specify which server to receive the IP Addresses.

At the same time, the client will send an ARP packet to the network, the query network has no other machine to use the IP address, if the IP is found to have been occupied, the client will send a dhcpdecline packet to the DHCP server, refuse to accept its Dhcpoffer, and resend DHC Pdiscover information.

In fact, not all DHCP clients accept the offer of DHCP servers unconditionally, especially if they have other TCP/IP-related client software installed. The client can also use DHCPRequest to present DHCP selections to the server, which are filled out in the DHCP option Field in different numbers:

In other words, the configuration above the DHCP server is not necessarily the client all accept, the client can keep some of their own TCP/IP settings. And the initiative is always on the client side.

4. Lease confirmation. When the DHCP server receives the client's dhcprequest, it sends a DHCPACK response to the client to confirm that the IP lease is formally in effect and ends a complete DHCP work process. As shown in the following work Flow diagram:

DHCP release process

After the first logon:

Once a DHCP client succeeds in obtaining a DHCP lease from the server, unless its lease expires and the IP address is reset back to 0.0.0.0, no further dhcpdiscover information is sent, and the previously leased IP address is used directly to the DHCP servo DHCPRequest information, the DHCP server will try to let the client use the original IP address, if there is no problem, direct response to Dhcpack to confirm it. If the address is invalidated or is already in use by another machine, the server responds with a DHCPNACK packet to the client requesting it to perform a new dhcpdiscover.

As for the IP lease period is very sophisticated, not as simple as we rent a house, in the case of NT: DHCP workstation In addition to the boot of the DHCPREQUEST request, in the lease period is half of the time also issued DHCPRequest, if the DHCP server at this time , the workstation can continue to use the IP, and then the workstation cannot have the IP if the remaining lease is half the time (that is, 75% of the lease) and is not confirmed. As for why not to the end of the lease period to give up IP? Sorry, the younger brother is also ignorant person, did not go deep, only know to answer MCSE topic, you must remember NT is so work.

If you want to retire, you can send out the dhcplerease command at any time, even if your lease was received a second ago.

Cross-network DHCP operations

From the process described above, it is not difficult to find that the Dhcdiscover is broadcast, and the situation can only be done within the same network, because router will not transmit the broadcast. But what if the DHCP server is installed on other networks? Because the DHCP client does not have an IP environment set up, it does not know the Router address, and some Router will not send DHCP broadcast packets out, so in this case dhcpdiscover is never able to Up to the DHCP server, and of course, there will be no offer or any other action. To resolve this problem, we can use the DHCP Agent (or DHCP Proxy) host to take over the client's DHCP request, then pass the request to the real DHCP server, and then relay the server's reply to the customer. Here, the Proxy host must have the ability to route itself, and can transfer the packets between the two sides.

If you do not use Proxy, you can also install the DHCP server in each network, but in this way, the cost of equipment will increase, and management is also more decentralized. Of course, such a balanced architecture is desirable in a very large network. The end depends on your actual situation.

DHCP envelope Format

The following is a brief description of each field:

OP

If the client gives the server the packet, set to 1, reverse to 2.

Htype

Hardware category, Ethernet is 1.

Hlen

Hard position length, Ethernet is 6.

Hops

If the packet need to pass through router transmission, add 1 per station, if in the same net, for 0.

TRANSACTION ID

The value produced when dhcprequest to be the basis for dhcpreply.

SECONDS

Client-side startup time (seconds).

FLAGS

From 0 to 15 bits, the leftmost bit of 1 indicates that the server will broadcast packets to the client and the rest is not yet in use.

Ciaddr

This is listed here if the client side wants to continue using the IP address previously obtained.

Yiaddr

From the server back to the client's DHCPOFFER and DHCPACK packet, this column fills in the IP address assigned to the client.

Siaddr

If the client needs to boot through the network, in the DHCPOFFER, DHCPACK, Dhcpnack packets sent from the server, this column fills in the address of the server where the boot code resides.

Giaddr

For DHCP distribution across the network domain, this column is the address of the relay agent, otherwise 0.

Chaddr

The hard address of the Client.

Sname

The name string of the Server, ending with 0x00.

File

If the client needs to boot through the network, this column will indicate the boot program name and be transferred later with TFTP.

Options

Allow factory to negotiate options (vendor-specific area) to provide more information about settings (e.g. Netmask, Gateway, DNS, etc.). The length is variable and can carry multiple options, the first byte of each option is the information code, followed by a byte for the data length, and finally the item content.

There are many options for DHCP, please consult the RFC or related literature, and understand, no longer described here.





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.