DHCP (Dynamic Host Configuration Protocal)

Source: Internet
Author: User

DHCP is the abbreviation of Dynamic Host Configuration Protocol (Dynamic Host Allocation Protocol). Its predecessor is BOOTP. BOOTP was originally used on a network without a disk host connection: the network host uses boot Rom instead of the disk to start and connect to the network. BOOTP can automatically set the TCP/IP environment for those hosts. However, BOOTP has one disadvantage: You must obtain the hardware address of the client before setting it, and the corresponding IP address is static. In other words, BOOTP lacks "dynamic". In a limited IP resource environment, a pair of BOOTP will cause a considerable waste. DHCP can be said to be an enhanced version of BOOTP. It is divided into two parts: one is the server, and the other is the client. All IP network settings are centrally managed by the DHCP server and are responsible for handling DHCP requirements of the client. The client uses IP environment data allocated from the server. Compared with BOOTP, DHCP uses the "lease" concept to effectively and dynamically allocate TCP/IP settings of the client. In addition, DHCP takes full care of BOOTP client requirements as compatibility considerations. In the form of DHCP allocation, at least one DHCP server must work on the network. It listens to DHCP requests on the network and interoperates with the client to set the TCP/IP environment. It provides three IP address locating methods:
Manual allocation

The Network Administrator binds a fixed IP address to a few specific hosts and the address does not expire.

Automatic Allocation

Automatic Allocation: Once the DHCP Client successfully rents the IP address from the DHCP server for the first time, it will always use this address.

Dynamic Allocation

Dynamic Allocation. After DHCP is rented from the HDCP server for the first time to the IP address, it is not permanently used. As long as the lease term expires, the client must release the IP address (release, for other workstations. Of course, the client can give priority to the update lease or lease other IP addresses than other hosts. 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 the customer, however, this does not mean that you can have a maximum of 200 customers. You must know that your customers cannot access the Internet at the same time. Apart from their different behavior habits, they may also be limited by telephone lines. In this way, you can lease these 200 addresses to the connected customers in turn. This is also the reason why the IP address is different each time you view the IP address (unless you apply for a fixed IP address, usually the ISP can meet this requirement, this may be charged separately ). Of course, ISP does not necessarily use DHCP to allocate addresses, but this concept is the same as IP pool. In addition to dynamically setting IP addresses, DHCP can also retain some IP addresses for special-purpose machines. DHCP can assign IP addresses according to hardware addresses, this gives you a larger design space. In addition, DHCP can also help clients specify projects such as router, netmask, DNS server, and WINS server, there is almost no need to set any IP environment.

The working principle of DHCP varies depending on whether the client logs on to the network for the first time. When logging on for the first time:

Find the server. When the DHCP client logs on to the network for the first time, that is, the client finds that there is no IP address data set on the local machine, and it sends a DHCP discover packet to the network. Because the client does not know which network it belongs to, the source address of the packet will be, And the destination address will be, and then the DHCP discover information will be attached to broadcast to the network. In Windows, the waiting time for DHCP discover is set to 1 second, that is, if the client does not receive a response within 1 second after sending the first DHCP discover packet, the second DHCP discover broadcast is performed. If no response is received, the client will have four DHCP discover broadcasts (including the first time), except for waiting for one second for the first time, the remaining three waiting times are 9, 13, and 16 seconds. If no response is received from the DHCP server, the client displays an error message indicating that the DHCP discover fails. Then, based on the user's choice, the system will repeat the DHCP discover process five minutes later.

Provides IP address leasing. When the DHCP server listens to the DHCP discover broadcast sent by the client, it selects the first vacant IP address from the address range that has not been rented out, along with other TCP/IP Settings, returns a DHCP offer packet to the client. Because the client has no IP address at the beginning, the DHCP discover packet contains its MAC address information and an Xid number to identify the packet, the DHCP offer packet responded by the DHCP server will be transmitted to the customer requesting the lease based on the information. Based on the server settings, DHCP offer packets contain information about the lease term.

Accept the IP lease. If the client receives a response from Multiple DHCP servers on the network, it selects only one DHCP offer (usually the first one) and sends a DHCP request broadcast packet to the network, tell all DHCP servers which server it will accept the IP address. At the same time, the client sends an ARP packet to the network to check whether other machines on the network use the IP address. If the IP address is occupied, the client sends a DHCPDECLINE packet to the DHCP server, rejects the DHCP offer, and resends the DHCP discover information. In fact, not all DHCP clients accept the DHCP server's offer unconditionally. In particular, these hosts are installed with client software related to TCP/IP. The client can also use DHCP request to propose DHCP options to the server. These options will be filled in with different numbers in the DHCP option field:

In other words, the settings on the DHCP server may not all be accepted by the client, and the client can retain some of its own TCP/IP Settings. The initiative is always on the client side.

Lease confirmation. When the DHCP server receives the DHCP request from the client, it sends a dhcpack response to the client to confirm that the IP lease takes effect. This completes the DHCP process. The preceding workflow is as follows:

After the DHCP issuance process logs on for the first time: Once the DHCP Client successfully obtains the DHCP lease from the server, the IP address is reset back to unless the lease has expired, otherwise, no DHCP discover information needs to be sent, and DHCP request information is directly sent to the previous DHCP server using the rented IP address, the DHCP server tries its best to allow the client to use the original IP address. If there is no problem, directly respond to dhcpack for confirmation. If the address has expired or has been used by other machines, the server will respond to a dhcpnack packet to the client and request it to execute DHCP discover again. As for the lease term of IP addresses, it is not as simple as renting a house. For example, in NT: in addition to sending a DHCP request when the DHCP workstation is started, a DHCP request will also be sent when the lease term is half. If the DHCP server is not confirmed at this time, the workstation can continue to use this IP address; then, when the remaining lease term is half (that is, 75% of the lease term), the workstation will not be able to own this IP address if it is not confirmed. Why does the IP address not be abandoned until the lease term ends completely ?, Sorry, the younger brother is also an unskillful student. If you have not gone into depth, but want to answer the MCSE question, you must remember that NT is working like this. If you want to cancel the lease, you can send the dhcplerease command at any time to cancel the contract, even if your lease was obtained in the first second.

Cross-network DHCP operations from the process described above, it is not difficult to find that dhcdiscover is broadcast, and the situation can only be performed within the same network, because the router does not transmit broadcasts. But what if the DHCP server is deployed on another network? The DHCP client has no IP environment settings, so it does not know the router address, and some routers do not transmit DHCP broadcast packets, therefore, in this case, DHCP discover will never be able to reach the DHCP server, and of course no offer or other actions will occur. To solve this problem, we can use the DHCP agent (or DHCP proxy) host to take over the client's DHCP request and then pass the request to the real DHCP server, then, send the server response to the customer. Here, the proxy host must have its own Routing Capability and can transmit packets from both sides to each other. If you do not use the proxy, you can also install the DHCP server in each network. However, in this case, the device costs increase and the management is scattered. Of course, in a very large network, such a balanced architecture is still desirable. Depends on your actual situation. DHCP packet format

The following is a brief description of each field: op

If the client sends a packet to the server, set it to 1 and reverse to 2. Htype

Hardware type. The value of Ethernet is 1.


The hardware address length. The Ethernet value is 6.


If the packet needs to be transmitted through the router, add 1 to each station. If the packet is in the same network, it is 0.

Transaction ID

DHCP request value, which is used as the basis for dhcpreply.


The start time (in seconds) of the client ).


16 bits in total from 0 to 15. When the leftmost bit is 1, the server sends packets to the client in broadcast mode, and the rest are not used yet.


If the client wants to continue using the previously obtained IP address, it is listed here.


From the DHCP offer and dhcpack packets sent back from the server to the client, fill in the IP address allocated to the client in this column.


If the client needs to boot through the network, enter the address of the server where the startup program code is located in the DHCP offer, dhcpack, and dhcpnack packets sent from the server.


If you need to issue DHCP across domains, this column is the address of the relay agent; otherwise, it is 0.


The hardware address of the client.


Server Name string, ending with 0x00.


If the client needs to boot through the network, this column indicates the name of the boot program, which will be transmitted using TFTP later.


Vendors are allowed to determine the option (vendor-specific area) to provide more configuration information (such as netmask, gateway, DNS, and so on ). Its length is variable and multiple options can be carried at the same time. The first byte of each option is the Information Code, the last byte is the Data Length of the item, and finally the project content. Code Len value this field is fully compatible with BOOTP, and more options are expanded. DHCP packets can be encoded as 0x53 to set the encapsulation category: item value category.

1 DHCP discover

2 DHCP offer

3 DHCP Request


5 dhcpack

6 dhcpnack

7 dhcprelease DHCP has many options. For more information, see RFC or related documents.

RFC file RFC-951 for DHCP protocol, RFC-1084, RFC-1123, RFC-1533, RFC-1534, RFC-1497, RFC-1541

DHCP is a software that automatically assigns an IP address to a client that logs on to the TCP/IP network 」). Such software is usually executed on routers and other network devices. According to the preset settings, your gatelock router is set to use DHCP, so you do not need to manually assign a permanent IP address to each device on the network. We recommend that you do not change this setting so that your PC can be distinguished as a DHCP server.

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.