DHCP appearsA computer or mobile phone needs an IP address to access the Internet. Liu has two computers and two mobile phones, Xiaomei has a laptop, a tablet and two mobile phones, and Lao Wang, Ali and Minmin also have several terminal devices. If you manually configure an IP address for each device, it will be very cumbersome and inconvenient. Especially for mobile phones, laptops, tablets and other devices, every time you move to a new place and connect to a different network, you have to re-set the IP address, which is really too troublesome. So there is the DHCP protocol, which automatically configures the network parameters of the device, including IP address, subnet mask, gateway address, DNS server, etc., instead of manual configuration. It can also unify IP address allocation and facilitate network management. Introduction to DHCPThe DHCP protocol is developed from the BOOTP protocol. However, BOOTP runs in a relatively static environment. Each device is configured with a dedicated BOOTP parameter file, which will remain unchanged for a long time. DHCP extends BOOTP in the following two aspects:
After Liu and his team's devices use the DHCP function, they can perform TCP/IP communication as long as they are connected to the network. For routers and switches, parameters such as IP addresses are usually configured manually. DHCP is a network protocol in Client/Server mode, where the DHCP Client submits a configuration request to the DHCP Server, and the DHCP Server returns the configuration information allocated to the DHCP Client. The Client and Server here are applications that can run on computers, servers, routers and other devices. For example:After Liu's computer is turned on, the DHCP Client automatically runs. The DHCP Client actively makes requests to the DHCP Server on other devices. The DHCP Server returns the corresponding IP configuration information according to the pre-configured strategy. The DHCP Client uses the obtained IP configuration information to communicate with other devices. DHCP allocation mechanismDHCP provides two address allocation mechanisms, and different allocation strategies can be selected for different clients according to network requirements.
In actual situations, we find that after the DHCP Client is restarted, it can still obtain the same IP address. When the DHCP Server assigns an IP address to the DHCP Client, it uses the following sequence:
If no available IP address is found, the system will query the IP addresses that have expired or are in conflict. If found, the IP address will be allocated. Otherwise, an error message will be issued. DHCP System CompositionThe DHCP system consists of DHCP Server, DHCP Client, DHCP Relay, etc.
Basic DHCP ProcessDHCP protocol messages are encapsulated in UDP mode. The listening port number of the DHCP Server is 67, and the listening port number of the DHCP Client is 68. DHCP devices interact with each other by sending and receiving messages on UDP port 67 and UDP port 68. The basic workflow of DHCP is divided into four stages, namely the discovery stage, the provision stage, the request stage, and the confirmation stage. We assume that Liu's PC is a new computer. The following describes how the PC obtains an IP address through DHCP for the first time . For the convenience of description, DHCP Server is referred to as Little S and DHCP Client is referred to as Little C. 1. DiscoveryXiao C broadcasts a DHCP Discover message in the local network segment, aiming to find Xiao S who can assign an IP address. 2. Provision phaseAfter receiving the DHCP Discover message, the local network segment's Xiao S responds with a DHCP Offer message, which contains the available IP address and other network parameters. Xiao C determines whether the Offer message is sent to him by comparing the xid fields in the Discover message and the Offer message to see if they are the same . 3. Request phaseXiao C will receive the DHCP Offer message sent by Xiao S. If there are multiple Xiao Ss, each Xiao S will respond to the DHCP Offer message. Usually Xiao C will select the Offer message received first and broadcast a DHCP Request message to indicate which Xiao S is selected, and the rest of the Xiao Ss will be left out. If Xiao C does not receive a DHCP Offer message after a certain period of time, it will resend a DHCP Discover message. 4. Confirmation stageAfter receiving the DHCP Request broadcast message, Xiao S sends a DHCP Ack message as a response, which contains Xiao C's network parameters. The parameters of the DHCP Ack message and the previous DHCP Offer message cannot conflict, otherwise Xiao S will respond with a DHCP Nak message. When Xiao C receives the DHCP Ac k message, it will send a free ARP message for detection, with the destination address being the obtained IP address. If the detection shows that this address is not in use, Xiao C will use this address and complete the configuration. DHCP LeaseFrom the perspective of the DHCP protocol, Xiao S has the ownership of the IP address, while Xiao C only has the right to use the IP address. Every time Xiao S assigns an IP address to Xiao C, it will agree on a lease period for the IP address, which is usually 24 hours. During the lease period, Xiao C can use the corresponding IP address. When the lease period expires, Xiao C will no longer be able to use the IP address. Of course, Xiao C can apply to renew the lease of the IP address before the lease period expires. Time T1 is when the lease is halfway through, and time T2 is when the lease is 87.5%. At time T1, Xiao C will unicast a DHCP Request message to Xiao S to request renewal of the IP address. If Xiao C receives a DHCP Ack response message, it means that the renewal is successful. If Xiao C does not receive a DHCP Ack response message until time T2, it will broadcast a DHCP Request message to continue requesting to renew the IP address. If Xiao C receives a DHCP Ack response message, it means that the renewal is successful. If Xiao C does not receive a DHCP Ack response message before the lease expires, he must stop using the original IP address. Xiao C will start from the discovery phase and apply for a new IP address. DHCP RelayIn the process of dynamically obtaining an IP address, a broadcast message is used, so DHCP is only applicable when Little C and Little S are in the same subnet. If a Little S is configured for each network segment, this is obviously a waste. In fact, there is also a role called DHCP Relay. Xiao C communicates with Xiao S across network segments through DHCP Relay to obtain an IP address. In this way, Xiao C on multiple subnets can use the same Xiao S, which saves costs and facilitates centralized management. The working principle of DHCP Relay is as follows:
DHCP protocol messageThe previous content mentioned some DHCP message types. Now let's talk about the 8 main DHCP message types. The 5 common message types are: DHCP Discover, DHCP Offer, DHCP Request, DHCP Ack and DHCP Release. The 3 less used message types are: DHCP Nak, DHCP Decline and DHCP Inform.
DHCP State MachineIf we string together the eight messages with different functions, we get the entire DHCP protocol interaction process. The four stages mentioned above (discovery, provision, request, and confirmation) cannot be fully displayed, so we need to use the DHCP protocol state machine. The state indicates the type of message used in the next step, and the state transition is through the reception, transmission, or timeout of the message. The following is the client state machine. The client starts from the INIT state and broadcasts a DHCP Discover message. In the Selection state, it receives a DHCP Offer message and decides which address and server to use. After making a choice, it enters the Request state through a DHCP Request message. If the assigned address is inconsistent with the previously used address, it responds to a DHCP Nak message to reject it and returns to the INIT state; if the assigned address is already occupied, it responds to a DHCP Decline message to reject it and also returns to the INIT state. Usually, it receives a required address, responds to a DHCP Ack message, obtains the lease timeout values T1 and T2, and enters the Binding state. At this time, the address can be used until the lease expires. When T1 expires, it enters the Renewal state and applies for renewal. If the renewal is successful, it can receive a DHCP Ack message and return to the Binding state; if the renewal is unsuccessful, it will apply for renewal again when T2 expires. If the lease eventually expires, the Client will be prohibited from using the leased address and return to the INIT state. DHCP Network PracticeThe DHCP protocol was created to solve network problems. Now we will simulate the actual environment, perform hands-on operations, and verify the function of DHCP. DHCP Server ExampleNetwork topologyExperimental requirements
ProcedureConfiguration ideas:
Configuration commands: Before using the DHCP function, you must enable the DHCP function. In the system view, use the dhcp enable command to enable the DHCP function. To dynamically allocate IP addresses, you need to have multiple allocable IP addresses. Use the ip pool ip-pool-name command to create a global address pool. ip-pool-name indicates the name of the address pool. In the global address pool view, use the network ip-address [ mask { mask | mask-length } ] command to configure the allocatable IP address segment. mask { mask | mask-length } indicates the subnet mask. The mask length is usually determined based on the number of devices. With the IP address and subnet mask, plus the default gateway, the terminal devices can communicate with each other on the network. In the global address pool view, use the command gateway-list ip-address to configure the gateway IP address. The network is interconnected, but the website cannot be accessed normally. You need to configure a DNS server for domain name resolution. In the global address pool view, use dns-list ip-address to configure the IP address of the DNS server. In address pool configuration, the commonly used optional commands are as follows, which can be selectively set according to needs. lease { day day [ hour hour [ minute minute ] ] | unlimited }: Configure the lease period of the IP address. The default lease period is 1 day. excluded-ip-address start-ip-address [ end-ip-address ]: Set the IP addresses that are not allocated in the allocatable address pool. For example, if the address pool is 192.168.100.0/24, you can set 192.168.100.1 - 192.168.100.10 to exclude them from address allocation. static-bind ip-address ip-address mac-address mac-address: Assign a fixed IP address to the Client. After configuring the address pool, you need to reference it so that the DHCP Server function can be used normally. To configure the reference under the RT interface, use the command dhcp select global. Functional VerificationAfter the configuration is completed , the DHCP function theoretically works normally. In actual situations, you can use the display ip pool name pool-name used command to view the configuration of the address pool and address allocation. Check the DHCP Server address allocation status on RT. At the same time, the dynamic address acquisition status is also checked on the PC for two-way verification. By capturing packets, you can also see the detailed process of DHCP message interaction, and at the same time verify whether the theoretical knowledge is correct. Here we find that the packet capture we see is a DHCP Offer unicast message, while in the previous introduction, the DHCP Offer is a broadcast message. In fact, the DHCP Offer message may be unicast or broadcast. DHCP has a broadcast bit in the flag field of the message. If the client supports receiving Offer unicast messages, the client will set the broadcast bit in the sent message to 0, otherwise it will be 1. DHCP Relay ExampleNetwork topologyExperimental requirements
Procedure
Functional VerificationThe PC can obtain the IP configuration, and the obtained configuration is correct. Capture packets on G0/0/1 of RT1 to view the message interaction process between the DHCP Client and DHCP Relay. Capture packets on G0/0/0 of RT1 to view the message interaction process between the DHCP Server and DHCP Relay. DHCP message formatIf you want to learn more about the DHCP protocol, you need to look at its message format. DHCP devices implement protocol functions by identifying message contents.
With the DHCP message format, you can understand the message content obtained by packet capture. DHCP Discover message: DHCP Offer message: DHCP Request message: DHCP Ack message: |
<<: Is the time ripe for “rate experience billing” in 5G multi-dimensional billing?
>>: 6G Proposal: Entering a new stage and meeting new challenges
I have shared DiyVM many times in my blog. It is ...
spinservers has released a special package for th...
CloudCone has launched a new flash sale, launchin...
On November 26, 2019, all IPv4 addresses were all...
Time flies, HostKvm has been established for 10 y...
After entering the URL in the browser, it will pe...
Migrating a data center is no small feat, and it ...
Recently, Acumen Research and Consulting, a globa...
A recent report released by Research And Markets ...
A few days ago, I received a request for help fro...
Big data has transformed both ends of the web hos...
spinservers has launched a new promotion this mon...
[51CTO.com original article] In the past, users o...
Ansible is a powerful automated operation and mai...
Sharktech (also known as Shark Data Center, SK Da...