DHCP protocol and its experiments (eNSP)

Table of contents

1. DHCP

1.1, DHCP function

1.2, DHCP address pool

1.3, DHCP message type

1.4, DHCP working principle

Thoughts on how DHCP works:

1.5, DHCP lease renewal

1.6, DHCP rebinding

1.7, IP address release

2. DHCP experiment

2.1, the network topology diagram is as follows:

 2.2, Experimental requirements

2.3, Configuration between various parts

Replenish:


1. DHCP


1.1, DHCP function


DHCP (Dynamic Host Configuration Protocol) is usually used in large-scale local area network environments. Its main function is to centrally manage and allocate IP addresses, so that hosts in the network environment can dynamically obtain IP addresses, Gateway addresses, and DNS. Server address and other information, and can improve the utilization rate of addresses, reduce the workload of administrators, and avoid address conflicts caused by users manually configuring network parameters.

1.2, DHCP address pool


There are two types of address pools:

Global address pool: The address pool configured in system view.
Interface address pool: The address pool configured in interface mode.

The difference between the two is as follows :

1. The global address pool can be called by dhcp from any other interface address. In other words, the global address pool is a public water pipe, and everyone can receive water from it.

2. The interface address pool specifies a specific interface to be assigned to this part of the IP address. This is for private use.

3. Global address pool, you can specify IP as gateway address

4. The interface address pool uses the interface IP as the gateway, and other IPs cannot be specified as the gateway.

5. Also, if there is a device below that is used as a dhcp relay, you can only use the global address pool.

6. The global address pool can be used by any other interface address. The dhcp calling interface can only be used by this interface.


1.3, DHCP message type


Message type Meaning
DHCP DISCOVER The client uses it to find the DHCP server
DHCP OFFER The DHCP server uses it to respond to the DHCP DISCOVER message. This message carries various configuration information
DHCP REQUEST The client requests configuration confirmation or lease renewal
DHCP ACK server Confirmation response to the REQUEST message
DHCP NAK Server rejection response to the REQUEST message
DHCP RELEASE Used to notify the server when the client wants to release the address


1.4, DHCP working principle

 1. The client sends a broadcast to the server, requesting an IP address.
 2. The server sends an offer message, Microsoft's operating system sends a broadcast, and Cisco and Huawei's hardware equipment sends a unicast.
 3. The client sends a message to confirm, indicating that the client has decided to use the IP address provided by the server.
 4. The server sends a confirmation message indicating that the client can use this IP address.

Thoughts on how DHCP works:

1. Why does the client send a broadcast to request an IP address? When the client sends a request, how are the messages sent by the client encapsulated at Layer 2 and Layer 3?

To answer this question, first, we can grab the discover message and take a look, as follows:

 From the above figure, we can see that when sending the discover message, the second-layer d-mac uses the full f broadcast mac address. First, this is to allow the DHCP SERVER in the network to receive our request. Second, because we don’t know the mac address of the DHCP SERVER, we can’t find them accurately. We can only tell them that we are looking for them, and then let them come to us. It can be seen that the third layer uses the UDP protocol to make the request and issuance of IP addresses faster. The s-ip of the third layer uses 0.0.0.0, which is used for temporary communication and is also used to identify that the client does not have an IP.

2. After the client receives the IP address, why does it still send a message to tell the server? And why is it not unicast but broadcast?

Send this broadcast message . First, it is to tell the server that provides the IP that I want to use this IP, so that the server that provides this IP will officially mark the leased IP as leased; second, it is to let other DHCP servers that provide the IP know that I am not using them . IP, and tell other DHCP servers not to send any more offers. (The offer contains IP information)

3. What else does the DHCP OFFER message received by the client contain besides IP information?

We can answer this question by looking at the offer message, as follows:

 From the picture above, we can see that the offer message provides us with the IP address 10.1.1.254, subnet mask, gateway IP, domain name resolution server IP, and IP lease time. Our host receives this information And after configuration, you can start communicating with the external network!


1.5, DHCP lease renewal

 

When the IP lease period reaches 50%, the DHCP client will request to renew the IP address lease. Huawei's default address lease period is one day .


1.6, DHCP rebinding


When the lease period reaches 87.5%, the DHCP client has not received a response from the server and will apply for rebinding. There are
two possible reasons for the lack of response from the IP server: 1. Message loss, 2. Loop.


1.7, IP address release

 1. If no response from the server is received before the IP lease expires, the client will stop using the IP address.
 2. If the DHCP client no longer uses the assigned IP address, it can also actively send a DHCP RELEASE message to the DHCP server to release it. the IP address.

2. DHCP experiment

2.1, the network topology diagram is as follows:

 2.2, Experimental requirements

1. The R2 router on the left uses interface mode to configure DHCP, and the right router R3 uses global mode to configure DHCP service.

2. The link used between the switch and the router is trunk, and the link type used between the switch and the PC is access.

3. Please see the picture above for specific information.

2.3, Configuration between various parts

pc configuration:

Set the method for all PCs to obtain IP to DHCP.

Switch configuration (in fact, you don’t need to configure the switch to do this experiment, but I just want to configure vlan to practice):

First we need to create the required vlan number. Here we need vlan 10 20 30.

 Configure the g0/0/2 interface of the switch as shown below:

 1. Configure the link type of the interface—port link-type access.

 2. Configure the vlan of the interface—port default vlan 10.

The configuration of the g0/0/3 and g0/0/4 interfaces is not shown here. It is the same as configuring the g0/0/2 interface, except that the vlan number is different. Next, we show the configuration of the g0/0/1 interface:

 1. Configure the link type of the interface as trunk port - port link-type trunk 

2. Configure the vlan numbers allowed to pass through the interface - port trunk allow-pass vlan all, here we configure all vlan numbers allowed to pass.

If you can't understand the configuration of the switch and want to know more about the switch, you can read this blog I wrote about the switch, which contains detailed switching and vlan knowledge. http://t.csdn.cn/mJjca http://t.csdn.cn/mJjca

Configuration of router R2:

First, we manually enable the DHCP service on the router.

1. First, create three virtual sub-interfaces to split different vlans. I have created g0/0/0.1, g0/0/0.2, and g0/0/0.3 respectively to receive the data of vlan10 20 30. Only the data of vlan10 20 30 are shown here. Configuration of g0/0/0.1.

2. Configure an IP address for the virtual interface. This IP address is also the gateway of the host under this vlan.

3. Configure which vlan data is accepted. Here, the data of vlan20 is accepted.

4. Configure the address pool mode to interface mode.

5. Configure dns server information.

6. Set the lease period of the IP address. The default lease period is one day.

7. Enable arp forwarding service.

After the configuration is completed, we can check the IP information on each PC.

pc3

 pc4

 The above is the data we got on the PC after configuring the DHCP service on the router. These data are all pre-configured on the router. For example: the dns obtained by the PC: 8.8.8.8.

Configuration of router R3: The difference here from the above is that we need to create a global mode address pool.

 1. First enable the DHCP service.

2. Create a global address pool.

3. Configure the gateway information of the address pool.

4. Configure the dns server information of the address pool.

5. Configure the IP address information that can be allocated by the address pool.

 6. Enter the interface.

7. Select global mode - dhcp select global.

After that, check the ip information of pc6.

 You can see that pc6 has obtained the IP address information issued by the DHCP server.

2.4. Thoughts after the experiment

The specific process and details for the host to obtain the IP address from the DHCP server?

We capture packets at the following location to see the specific process of the host getting the IP address from the DHCP server.

 The following is the specific process for the host to obtain the IP address:

 Initially, the host sends a Discover message to all machines on the entire network, and then the DHCP server sends an offer message to the host in a unicast manner to provide the IP address and other information. After receiving the offer message, the host does not immediately use the IP information provided by the offer . Instead, it still uses 0.0.0.0 as the source IP and 255.255.255.255 as the destination IP to send the Request message. First, it is to tell the server that provided the IP. I want to use this IP and let the server that provides this IP officially mark the leased IP as leased; second, it is to let other DHCP servers that provide IP know that I am not using their IP, and let other DHCP servers not Send the offer again. Afterwards, the host still cannot use this IP because it cannot be officially used until the DHCP server sends an ack message. In short, the host will not start using the IP provided by the DHCP server until it receives the ack message.

Replenish:

The fourth layer of messages used by the DHCP protocol uses the UDP protocol instead of the TCP protocol. The client uses port 68, and the server uses port 67.

at last 

This blog’s introduction to the DHCP protocol and DHCP experiments ends here. If this blog is helpful to you, please like, collect and support it. Thank you! promise me! Don't have sex for free, okay? Hahaha! See you in the next blog.

Guess you like

Origin blog.csdn.net/weixin_64972949/article/details/132127950