DHCP Protocol /DHCP Protocol
Directory
- Basic theory of DHCP
- DHCP Communication Process
- DHCP Complete Message
- Optional field for DHCP
- Type of message for DHCP
1 Basic theory of DHCP
DHCP (Dynamic Host Configuration Protocol) is a network protocol for LAN, which works with UDP protocol, mainly has two purposes, and is described in detail in RFC 2131 .
1. automatically assign IP addresses to internal network or network service providers;
2. To the user or the internal network administrator as a means of central management of all computers .
DHCP has 3 ports, where UDP67 and UDP68 are normal DHCP service ports, respectively, as service ports for DHCP server and DHCP client, port546 for DHCPv6 Client, instead of DHCPV4, it is for DHCP failover service, which is a service that needs to be opened specifically, DHCP failover is used to do "Dual machine hot standby".
DHCP is primarily compliant with the RFC2131 protocol and can be used for BOOTP compatibility.
2 DHCP Communication Process
The basic communication flow of DHCP is similar to BOOTP, according to the description of the RFC2131, which works as shown in the main way,
1. First the client will issue a DHCP Discover broadcast request to all the servers that are listening;
2. The server receiving the request analyzes the request message, determines that it is a valid discover request, and then returns an offer message informing the client that the IP address can be provided;
3. The client may receive multiple offer messages, usually responding to the first received message and issuing request requests;
4. When the server receives a request for a broadcast request, it verifies the received requests to see if the offer itself is selected, and if it sends an ACK to establish the connection.
5. The release message is sent to the server until the end of the client's use (including setting information such as the lease period), freeing the used IP.
3 DHCP Complete Message
The data message format of the DHCP is basically the same as the BOOTP message format, the biggest difference is the 236-bit Options Information section. The Options Information section of DHCP contains a number of important information. For information on the first 236 bits, refer to the BOOTP protocol.
4 DHCP of the Options Field
Option ID |
Length (bytes) |
Describe |
1 |
4 |
Subnet Mask |
3 |
N*4 |
Router (Gateway) |
6 |
N*4 |
DNS Server |
7 |
N*4 |
Log Server |
26 |
2 |
Interface MTU |
33 |
N*8 |
Static Route |
35 |
4 |
ARP Cache Timeout |
42 |
N*4 |
NTP servers |
51 |
4 |
IP Address Lease time |
53 |
1 |
message type 1-dhcpdiscover 2-dhcpoffer 3-dhcprequest 4-dhcpdecline 5-dhcpack 6-dhcpnak 7-dhcprelease 8-dhcpinform |
54 |
4 |
DHCP Server Identifier |
More option values can be referenced by links
Note:
Here is a notable place, the magic word that DHCP uses to differentiate between BOOTP, which is typically at the beginning of the options, usually 4 bytes, fixed to decimal 99, 130, 83, 99 (that is, hexadecimal 0x63, 0x82, 0x53, 0X63), these four fields are both intended to differentiate between DHCP and BOOTP as well as for compatibility with DHCP and BOOTP.
5 DHCP type of message
There are 8 main types of messages in DHCP, DHCP Discover, DHCP offer, DHCP Request, DHCP ACK, DHCP NAK, DHCP Release, DHCP decline, DHCP Inform, respectively. Each message type functions as follows,
DHCP Message Type |
Describe |
DHCP Discover |
When a DHCP client requests an address, it does not know the location of the DHCP server, so the DHCP client sends the request message in the local network as a broadcast, which becomes a discover message to discover the DHCP server in the network. All DHCP servers that receive discover messages send a response message, which allows the DHCP client to know the location of the DHCP server that exists on the network. |
DHCP Offer |
After the DHCP server receives the discover message, it will look for an appropriate IP address in the configured address pool, add the appropriate lease duration and other configuration information (such as gateways, DNS servers, etc.), construct an offer message, and send it to the user informing the user that the server can provide it with an IP address. < just tells the client to provide, is pre-allocated, and requires the client to detect whether the IP is repeated through ARP > |
DHCP Request |
DHCP clients may receive a lot of offer, so you must select one of these responses. The client usually chooses the first server that responds to the offer message as its target server and responds to a broadcast request message to advertise the selected server. After the DHCP client obtains the IP address successfully, the lease request message is sent to the DHCP server during the last 1/2 of the leased period, and if no DHCP ACK message is received, the broadcast request message is sent to renew the lease period at the last 3/4 of the lease period. |
DHCP ACK |
After the DHCP server receives the request message, it finds the corresponding lease record based on the user's Mac that is carried in the request message, and if so, sends an ACK message in response to notify the user that the assigned IP address can be used. |
DHCP NAK |
If the DHCP server receives a request message, does not find a corresponding lease record, or for some reason the IP address is not properly assigned, the NAK message is sent as a response informing the user that the appropriate IP address cannot be assigned. |
DHCP Release |
When the user no longer needs to use the assigned IP address, it will proactively send the release message to the DHCP server, informing the server that the user no longer needs to assign an IP address, and the DHCP server will release the bound lease. |
DHCP decline |
After the DHCP client receives an ACK message from the DHCP server, it detects that the server is assigned an address conflict through the address conflict detection or is not available for other reasons, sending a decline message informing the server that the assigned IP address is not available. |
DHCP Inform |
If the DHCP client needs to obtain more detailed configuration information from the DHCP server, send the inform message to the server to request, after the server receives the message, will be based on the lease to find the appropriate configuration information, send an ACK message to respond to the DHCP client. < rarely used > |
Related reading
1. BOOTP protocol
2. The Python implementation of DHCP
Reference Links
http://blog.csdn.net/one_in_one/article/details/51684551
http://blog.csdn.net/nosodeep/article/details/45971677
http://blog.csdn.net/longjianhappy/article/details/42968199
Http://blog.chinaunix.net/uid-20530497-id-2203830.html
The basic theory of DHCP, DHCP protocol, network programming for Python [4]