DHCP (Dynamic Host Configuration Protocol) protocol is used to provide configuration information to Internet hosts in TCP/IP networks. It is developed on the basis of BOOTP(BOOTP), which increases the automatic allocation ability of reusable network addresses and additional configuration options, while DHCP retains the relay agent function of BOOTP.
Chapter 2: Introduction to the Agreement
Dhcp (Dynamic Host Configuration Protocol) protocol is based on BOOTP protocol.
Based on, its function is to provide configuration information to Internet hosts in TCP/IP networks.
DHCP adopts client/server mode, and the client applies to the server for configuration (including the assigned IP address,
Subnet mask, default gateway and other parameters), the server returns the corresponding configuration information according to the policy.
DHCP messages are encapsulated by UDP as a transport layer protocol.
DHCP 2 part:
1, DHCP relay function, which sends the configuration information specified by the DHCP server to the host; ;
2. Server function, which assigns network address and other configuration parameters to the host.
DHCP IP allocation method:
1, automatically assigned, and assigned a fixed IP address to some hosts connecting to the network for the first time. This address
Will be used by this host for a long time.
2, dynamic allocation, DHCP server specifies an IP address for the host, and specifies the address at the same time.
There is a lease term. If the lease expires, the customer must apply for an address again. This is the client.
The most common method of applying for an address;
3. Manual allocation. The network administrator specifies a fixed IP address for a few specific hosts.
DHCP specifies the priority classification of the address:
The 1.IP address is statically bound to the MAC address of the client in the DHCP server address pool.
2. The address used by the client. When the client applies for an address again, the client sends DHCP Discover.
Message, the address option will contain the last used IP address, unless the IP address is assigned or the address
Other unavailable operations have been performed (for example, this IP address is blocked, etc.). ), otherwise the client will remake it.
Use this address.
3. The IP address specified by the client in the "Requested IP Address" option (if the address is in the address pool).
And has not been assigned, the address is assigned to the client.
4. Search the IP addresses available for allocation in the DHCP address pool in turn, and the available IP address found first has high priority.
Chapter 3: DHCP message format
The meaning of each field in the message
The Option field is a variable-length field, and DHCP clients must be able to receive messages with a length of 3 12 bytes.
DHCP messages in the Options field, that is, DHCP clients must be able to accept IP messages with a length of at least 576 bytes.
DHCP clients can negotiate the maximum DHCP message size through the "Maximum DHCP message size" option.
Length.
Logo format:
B: leftmost bit, broadcast sign; ;
MBZ: The remaining bits are reserved for future use.
Chapter 4: DHCP message construction and sending
DHCP uses the port number of UDP protocol.
DHCP messages are encapsulated by UDP as a transport layer protocol. A DHCP message from the client to the server is sent to.
The port number of DHCP server is 67, and the port number of the message sent from the server to the client and then to DHCP client is 68.
DHCP option
DHCP messages need to contain a series of options, namely a list of options. The list of options is based on
It starts with a 4-byte magic word, followed by a series of options and ends with an "end" option.
Client ID
DHCP defines an option to identify clients, namely "Client Identifier" option. The customer must
Select a value that uniquely identifies yourself in the physical network to fill in the value of the client ID option. once
This value is initialized and cannot be changed in subsequent message interactions. It is recommended to use the MAC address of the client as the client ID.
Value.
Server ID
DHCP defines an option to identify the server, that is, the "server identifier" option. Computer network server
Select your own IP address as the server ID. If a DHCP server has multiple IP addresses, it can choose at will.
One is used as the server ID, but it is recommended to use an IP address that the client can reach. For example, when the server and the client are located in the same place.
When there is a network segment, it is best to choose the address of the network segment as the server ID. If the client sends a unicast message to the server, the destination address will use the server ID value.
The source IP address of the message sent by the client.
Before the client obtains the IP address, the source IP of the message it sends (referring to the source IP field in the IP header) must be
Fill in 0.
Broadcast sign
Flag, 1 bit is used as the broadcast flag, and the following 15 bit is reserved and must be set to 0.
When the software cannot effectively configure the IP address of its own IP protocol, the client may not be able to handle the received unicast.
Text, in this case, the client must set the broadcast flag position to 1, Server or Relay when sending Discover and Request messages.
When the agent receives such a message, it must reply the broadcast message to the client.
If the client can process the broadcast message, it will broadcast the flag position 0 and the server or relay agent will receive it.
The message of discovery and request can be replied by unicast message, and the destination IP address is assigned by the server to.
The IP address of the client, that is, the value of the yiaddr (your IP address) field in the message. Of course, it is a server or a relay agent.
You can also reply by radio.
Processing ciaddr and giaddr fields on the server side
Ciaddr, the IP address of the client, only the client is in the state of binding, renewal and rebinding, and
Only when it can respond to ARP requests can it be filled;
Giaddr, IP address of relay agent;
1. If the giaddr field of the message received by the server is not 0 (i.e. it means that the message is carried out through a relay proxy.
Forwarded message), then it will reply in a unicast way, and its destination address is the value of the giaddr field;
2. If the giaddr field of the message received by the server is 0, and the ciaddr field is not 0 (that is, it means that the client is already valid.
Configured its own IP address), then it will reply unicast, and the destination address is ciaddr word.
The value of the segment;
3. if the giaddr field of the message received by the server is 0, the ciaddr field is 0, and the broadcast flag bit is not 0 (that is,
Ming client has not configured its own IP address, and can't handle unicast messages at this time), then it will be widely used.
Reply by radio;
4. If the giaddr field of the message received by the server is 0, the ciaddr field is 0 and the broadcast flag bit is 0 (that is, the description
Although the client has not configured its own IP address, it can handle unicast messages at this time), and then it will use the.
Unicast reply (unicast reply is recommended, of course, reply can also be broadcast).
Transaction ID
Xid (transaction id) is a random number selected by the client and used to exchange messages between the server and the client.
This game.
The client must adopt the corresponding algorithm to ensure that its xid value is different from that of other clients as much as possible.
That is to minimize the same probability.
Option overload
In the DHCP header, both sname and file fields occupy more bytes, if these two fields are in one message.
If one or two of them don't contain information, space is wasted. To this end, DHCP can extend the option content to sname and file words.
In the paragraph. DHCP defines an overload option. If there is an overload option, tell it.
The receiver sname and file fields have lost their original meanings and represent options.
Message type
DHCP defines the message type in the message type option.
The format of the message type option is as follows:
Option code: the length is 1 byte, and the value is 53, indicating the message type option; ;
Option length: the length is 1 byte, and its value is 1, indicating that the length of the option value field is 1 byte;
Option value: the length is 1 byte, and its value identifies the message type of DHCP.
The following eight DHCP messages are defined in RFC2 13 1:
Type description
1 DHCPDISCOVER
2 DHCPOFFER
3 DHCPREQUEST
4 DHCPDECLINE
5 DHCPACK
6 DHCPNAK
7 DHCPRELEASE
8 DHCPINFORM
The messages that DHCP server can receive from the client are: DHCPDISCOVER, DHCPREQUEST,
DHCPDECLINE, DHCPRELEASE and DHCPINFORM;;
The messages that DHCP clients can receive from the server are: DHCPOFFER, DHCPACK and DHCPNAK.
DHCPDISCOVER
When the server receives the DHCPDISCOVER message from the client, the server will select a network for the client.
Network address, if there is no available address, then the server will report to the system administrator; If an address is available, the server
An available address will be selected for the client by:
1, the IP address of the statically bound client MAC address in the server address pool;
2. The expired or released address previously used by the client (if the address is available in the address pool).
Address, and has not been assigned, then this address is assigned to the client;
3. The IP address specified by the client in the "Requested IP Address" option. If this address is an address,
A valid address in the pool, and it has not been allocated, then this address is allocated to the client;
4. According to the specific selection method, assign the valid unassigned new address in the address pool to the client.
Use.
Lease period selection mechanism:
1. If the client requests the lease term specified in DHCPDISCOVER, has the client been
If a network address is specified, the server will be designated as the requested lease;
2. If the client has not requested to specify the lease term, and the client has allocated a network address, then
The server will assign the lease term previously used by this address to this address;
3. If the client does not request to specify the lease term and no network address is assigned to the client, then
The server will specify the local default lease term.
DHCPREQUEST
DHCPREQUEST means that the client responds to the DHCPOFFER message from the server and checks the previously allocated network.
Resolve or extend the existing lease. If the DHCPREQUEST message contains the Server Identifier option, then
This message is used to respond to DHCPOFFER, otherwise, this message is used to request to check and extend the existing.
Leased.
If the client in DHCPREQUEST uses the Client Identifier option, all subsequent
Use the same "customer identifier" in all messages; If the DHCPDISCOVER message contains a demand parameter column
Table, then this parameter list should be included in subsequent messages.
The configuration parameters in DHCPACK should not conflict with the DHCPOFFER message, but should conflict with the configuration parameters used by the client.
This number is the configuration parameter in the DHCPACK message.
DHCPDECLINE
If the client finds that the network address suggested by the server has been used, it will send it to the server.
DHCPDECLINE message, the server must mark the network address as unavailable and notify the local system.
Configuration problems that administrators may encounter.
The client checks whether the address allocated by the server has been used: the client receives an ACK message from the server,
Before configuring your own IP address and other parameters, send free ARP to check whether the IP address is enabled in the network.
Use.
DHCPRELEASE
If the client no longer needs to use its specified address, the client will send a DHCPRELEASE report to the server.
After receiving DHCPRELEASE, the server will mark that this network address is no longer allocated, but the server should keep it.
Record the initialization parameters of the client in order to respond to the possibility that the client may reuse the address in the future.
DHCPINFORM
When the client configures its own IP address but wants to configure other parameters, it will send it to the server.
DHCPINFORM message, requesting other parameter configuration.
When receiving the DHCPINFORM message, the server directly sends the DHCPACK to the address given in the message "ciaddr" field.
News. The server does not have to send the lease over time, nor should it fill in the "yiaddr" field.
DHCPOFFER
The server receives the DHCPDISCOVER message and responds with the DHCPOFFER message. DHCPOFFER
The message should include the available network address of the "yiaddr" domain and other configuration parameters of the DHCP option. When assigning a new address
The server should confirm that the provided network address is not used by other clients (the server can be divided by the sending direction.
Respond to the request with the ICMP of the address to confirm that the allocated address is not used).
DHCPACK & ampDHCPNAK
If the configuration parameters provided by the server are acceptable, the client records the address of the server, and
Write the address into the "server identifier" field of DHCPREQUEST and send it out in the form of broadcast. If it is received,
The configuration parameters in the DHCPREQUEST message are valid, and the server will respond to the DHCPACK message. once
When the DHCPACK is received, the client will be initialized and enter the binding state.
If the configuration parameter in the DHCPREQUEST message is invalid, the server will respond with one parameter.
DHCPNAK message.