We always have a lot to introduce about the DHCP protocol. We have a certain understanding of concepts, structures, and workflows before. Here, we will add some knowledge in the process, and focus on the DHCP protocol packet format.
Lease confirmation
After the DHCP server receives the DHCPrequest from the client, it sends a DHCPACK response to the client to confirm that the IP lease takes effect. This completes the DHCP process.
After the DHCP issuance process logs on for the first time: Once the DHCP Client successfully obtains the DHCP lease from the server, it will reset the IP address to 0.0.0.0 unless the lease has expired, otherwise, you do not need to send DHCPdiscover information. Instead, you can directly send DHCPrequest information to the previous DHCP server using the rented IP address. The DHCP server tries its best to make the client use the original IP address, if there is no problem, you can directly respond to DHCPack to confirm. If the address is invalid or used by another machine, the server returns a DHCPNACK packet to the client and asks the server to execute DHCPdiscover again.
As for the lease term of IP addresses, the lease term is not as simple as renting a house. For example, the DHCP workstation sends a DHCPrequest request when it starts up, A DHCPrequest will also be issued when the lease term is half. If the DHCP server is not confirmed at this time, the workstation can continue to use the IP address. When the lease term expires 87.5%, if the client still cannot contact the original DHCP server, it will communicate with other DHCP servers. If no DHCP server is running on the network, the client must stop using the IP address and repeat the entire process from sending a Dhcpdiscover packet. If you want to cancel the lease, you can send the DHCPRELEASE command to cancel the contract at any time, 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 DHCPDISCOVER 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, DHCPDISCOVER will never be able to reach the DHCP server, and of course there will be no OFFER or other actions. To solve this problem, we can use the DHCPAgent (or DHCPProxy) host to take over the client's DHCP request, then pass the request to the real DHCP server, and then send the server's reply 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 protocol packet format
The following is a brief description of each field:
If the OP is the packet sent from the client to the server, set it to 1 and reverse to 2.
HTYPE hardware type, where Ethernet is 1.
The length of the HLEN hardware address. The Ethernet value is 6.
HOPS if the packet needs to be transmitted through the router, 1 is added for each site. If the packet is in the same network, 0 is added.
The value generated when transaction id dhcprequest is used as the basis for DHCPREPLY.
The start time (in SECONDS) of the SECONDS Client ).
FLAGS are 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.
Ciaddr is listed here if the client wants to continue using the previously obtained IP address.
Yiaddr sends the DHCPOFFER and DHCPACK packets from the server to the client. Fill in the IP address allocated to the client in this field.
If the client needs to boot through the network, siaddr sends DHCPOFFER, DHCPACK, and DHCPNACK packets from the server. In this column, enter the address of the server where the startup program code is located.
If you need to issue DHCP protocol across domains, this column is the address of the relay agent; otherwise, it is 0. The hardware address of the chaddr Client. The name string of the sname Server, ending with 0x00. File 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. Options allows vendors 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. Among them, DHCP packets can be set with the option of encoding 0x53: item value category 1 DHCPDISCOVER 2DHCPOFFER3 DHCPREQUEST 4 DHCPDECLIENT 5 DHCPACK 6 DHCPNACK 7 dhcprelease dhcp protocol has many options, for more information, see RFC or related documents.