Computer Networking Notes: Dynamic Host Configuration Protocol (DHCP)

Protocol configuration :

  • In order to make the protocol software universal and portable, the writers of the protocol software will not fix all the details in the source code. Instead, they parameterize the protocol software, which makes it possible to use the protocol software on many computers. The same compiled binary code.
  • Much of the difference between one computer and another can be reflected in a few different parameters.
  • Each parameter must be assigned a value before the protocol software runs. The act of assigning values ​​to these parameters in the protocol software is called protocol configuration , and a protocol software must be correctly configured before it is used.

Overview of Dynamic Host Configuration Protocol (DHCP) : Dynamic Host Configuration Protocol is a widely used protocol at present, which provides a plug-and-play networking mechanism. This mechanism allows a computer to join a new network and obtain an IP address without manual participation.

Application of DHCP :

  • DHCP is applicable to both computers running client software and server software;
  • When the computer running the client software is moved to a new network, it can use DHCP to obtain its configuration information without manual intervention;
  • DHCP assigns a permanent address to a fixed-location computer running server software, and the address does not change when the computer is restarted.

Simple process of DHCP protocol :

  • DHCP uses a client-server approach.
  • The discovery message is sent :
    • The host that needs an IP address broadcasts and sends a discovery message to the DHCP server (set the destination IP address to 255.255.255.255) when it is started, and the host becomes a DHCP client at this time.
    • The broadcast message is sent because it is not yet known where the DHCP server is, so the IP address of the DHCP server needs to be discovered.
    • This host does not currently have its own IP address, so the source IP address of the IP datagram is set to all 0s.
    • All hosts in the local network can receive this broadcast message, but only the DHCP server can reply to this broadcast message.
  • Offer message sent :
    • The DHCP server first looks up the computer's configuration information in its database. If found, return the found information; if not found, take an address from the server's IP address pool and assign it to the computer.
    • The reply message of the DHCP server is called an offer message, indicating that configuration information such as an IP address is provided.

DHCP relay agent :

  • The background of the existence of the DHCP relay agent : Since configuring a DHCP server for each network will make the number of DHCP servers too large, it is more common to configure at least one DHCP relay agent (usually a router) for each network. ), the IP address information of the DHCP server is configured in the relay agent.
  • The working process of DHCP relay agent :
    • When the DHCP relay agent receives the discovery message sent by host A in broadcast form, it forwards the message to the DHCP server in unicast form and waits for its reply.
    • After receiving the offer message answered by the DHCP server, the DCP relay agent provides the offer message to host A.

Lease period :

  • Concept : The IP address assigned by the DHCP server to the DHCP client is temporary, so the DHCP client can only use the assigned IP address for a limited period of time, which is called the lease period.
  • Length of time : The length of the lease period is determined by the DHCP server. The optional lease time ranges from 1 second to 136 years.

DHCP port :

  • Client port : UDP port used by DHCP clients is 68;
  • Service port : The UDP port used by the DHCP server is 67.

The detailed process of DHCP :

  1. The DCHP server passively opens UDP port 67, waiting for the message from the client;
  2. The DHCP client sends a DHCP discovery message from UDP port 68;
  3. Every DHCP server that receives a DHCP discovery message sends a DHCP offer message, so the DHCP client may receive multiple DHCP offer messages;
  4. The DHCP client selects one of several DHCP servers, and sends a DHCP request message to the selected DHCP server;
  5. The selected DHCP server sends a confirmation message DHCPACK. From then on, the DHCP client can use this IP address, and this state is called the bound state. At this point, the IP address and MAC address of the DHCP client have been bound, and the obtained temporary IP address can be used. At this time, the DHCP client will set two timers according to the provided lease period T, and the timing time is 0.5T and 0.875T respectively. When the timeout expires, it will request to renew the lease period.
  6. When half of the lease period has passed, the DHCP client sends a request message DHCPREQUEST to request to renew the lease period.
  7. If the DHCP server does not agree, it will send back a negative message, DHCPPACK. At this time, the DHCP client must stop using the original IP address immediately, and must reapply for an IP address.
  8. If the DHCP server does not respond to the request, then when the second timer expires, the DHCP client resends the request message DHCPREQUEST, and then continues the above steps.
  9. The DHCP client can terminate the lease period provided by the server in advance at any time. At this time, it only needs to send the release message DHCPRELEASE to the DHCP server.

Practical use of DHCP : DHCP is very suitable for computers that frequently move locations. The Windows computer automatically obtains the IP address and automatically obtains the DNS server address option, which means that the DHCP protocol is used.

Guess you like

Origin blog.csdn.net/hanmo22357/article/details/131119970