Principles and configuration analysis of dhcp and dhcp relay experiment Xiaobai will meet in seconds (detailed experimental configuration analysis) (Huawei ensp simulator)

1. Overview of DHCP

DHCP (Dynamic Host Configure Protocol) is the abbreviation of Dynamic Host Configuration Protocol, which is used to assign IP addresses and some TCP/IP configuration information to computers in the network. DHCP improves safe, reliable and simple TCP/IP network settings, avoids address conflicts in TCP/IP networks, and also greatly reduces the burden of managing IP address settings.

1. What is DHCP:

DHCP is a TCP/IP standard that simplifies IP configuration management and dynamically configures TCP/IP information for clients. When the DHCP client is started for the first time, the client will request an IP address in the network. When the DHCP server receives the IP address request, it will select an IP address from the addresses defined in the database and provide it to the DHCP client. To use DHCP in a TCP/IP protocol network, at least one computer in the network must be used as a DHCP server, and other computers must be used as DHCP clients.

2. Advantages of using DHCP:

  1. Reduce the workload of the administrator.
  2. Reduce the possibility of input errors.
  3. Avoid IP conflicts.
  4. When the network changes the IP address range, there is no need to reconfigure the IP address of each computer.
  5. No need to reconfigure the IP address when moving the computer.
  6. Improved utilization of IP addresses

2. Briefly describe the working process of DHCP service:

In addition to obtaining an IP address from the DHCP server, the client can also obtain information such as the subnet mask, the default gateway address, and the DNS server address. The above process is also called the DHCP lease process. Because when the client receives the provided IP address, the DHCP server will lease the IP address to the client for a specified period of time. The lease process is divided into 4 steps, namely: client requests an IP address-server response-client selects an IP address-server confirms the lease.

1. Four types of messages and request process of DHCP service

1.1, the client requests an IP lease

The DHCP client broadcasts a DHCPDiscover packet in the network to request an IP address, so this process is also called DHCPDiscover. The source IP address of the DHCPDiscover packet is 0.0.0.0 and the destination IP address is 255.255.255.255. The packet also contains the client's MAC address and computer name, so that the DHCP server can determine which client sends the request.
Insert picture description here

1.2, server response

When the DHCP server receives the client's request for an IP address, it will look in its own IP address database to see if there is a legal IP address provided to the client. If so, the DHCP server will mark the IP address and broadcast it. DHCPOffer packet (this process is also called DHCPOffer). Because the DHCP client does not yet have an IP address, the DHCP server sends a broadcast message
Insert picture description here

1.3, the client selects the IP address

The DHCP client selects an IP address from the first DHCPOffer packet it receives, and broadcasts the DHCPRequest packet to all DHCP servers, indicating that it accepts the provided content (this process is also called DHCPRequest). If the client accepts the IP address, the DHCP server that issued the IP address reserves the address, and the address cannot be provided to another DHCP client; if those DHCPOffer packets are rejected, the DHCP server cancels the provision and reserves its IP address. Used for the next IP lease request.
Insert picture description here
In the process of selecting an IP address by the client, although the client has selected an IP address, the IP address has not yet been configured, so the source address is still 0.0.0.0, and there may be several DHCP servers in a network, so the DHCP client Still broadcast the DHCPRequest packet.

1.4. The server confirms the IP lease

The fourth and final step in the DHCP lease process is to confirm the IP lease for the server, also known as DHCPACK/DHCPNAK. After receiving the DHCPRequest, the DHCP server broadcasts a successful confirmation to the client in the form of a DHCPACK (DHCPAcknowledge) message, which contains the valid lease of the IP address and other possible configuration information. When the client computer receives the DHCPACK packet, it configures the IP address and completes the initialization of TCP/IP, so that it can communicate on the TCP/IP network.
Insert picture description here

2. IP lease update

When the client restarts or the lease period reaches 50%, it needs to renew the lease. The client directly sends a DHCPRequest packet to the server that provides the lease, requesting to update the existing address lease. If the DHCP server receives the request, it will send a DHCP confirmation message to the client to update the client lease. If the client cannot get in touch with the server that provides the lease, the client waits until the lease reaches 87.5% and enters the reapplying state. It broadcasts the DHCPDiscover packet to all servers on the network to update the existing address lease. If the server responds to the client's request, the client uses the address information provided by the server to update the existing lease. If the lease is terminated or cannot communicate with other servers, the client will not be able to use the existing address lease.
The client can use the ipconfig/renew command to send a DHCPRequest packet to the DHCP server to receive the update options and lease time. If the DHCP server does not respond, the client will continue to use the current DHCP configuration options.

3. Release of IP lease

Use the ipconfig/release command on the client to make the DHCP client send a DHCPRelease packet to the DHCP server and release its lease. This is useful when moving the client to a different network and the client does not need a previous lease. After issuing this command, the client's TCP/IP communication is stopped.
If the client remains closed within the lease time (and does not renew the lease), after the lease expires, the DHCP server may assign the client's IP address to different clients. If the client does not send the DHCPRelease packet, it will try to continue using the last used IP address when it restarts.

4. DHCP relay

1. The DHCP client applies for an IP lease and sends a DHCPDiscover packet.
2. The relay agent receives the packet and forwards it to the DHCP server on another network segment.
3. The DHCP server receives the packet and sends the DHCPOffer packet to the relay agent.
4. The relay agent forwards the address lease (DHCPOffer) to the DHCP client.
In the following process, the DHCPRequest packet is forwarded from the client to the DHCP server through the relay agent, and the DHCPACK message is forwarded from the server to the client through the relay agent.

3. DHCP and DHCP relay experiment

1. Experimental purpose and experimental environment

The IP address is automatically assigned to the PC through the DHCP service, with 3 Huawei (ensp emulator) routers, 1 switch, and 5 PCs.

2. Experimental topology diagram

Insert picture description here

3. Experimental configuration

R1 configuration

sysname R1 ------------------------------------------------ Rename R1
vlan batch 10 20 ------------------------------------------- Create different vlans in batch
dhcp enable ------------------------------------------- ----- Open dhcp service
interface GigabitEthernet0/0/0 ----------------------- Enter this interface
ip address 12.0.0.1 255.255.255.0 - ---------------- Add IP address
interface GigabitEthernet0/0/1.10 -------------------- Enter this subinterface
dot1q termination vid 10 ------------------------------ This sub-interface belongs to vlan 10
ip address 192.168.10.1 255.255.255.0 --- -------- Add IP address
arp broadcast enable =--------------------------------- enable arp Broadcast
dhcp select relay --------------------------------------- dhcp service selects dhcp relay
dhcp relay server-ip 14.0.0.2 ------------------------- The specified port address of the dhcp relay service
interface GigabitEthernet0/0/1.20 - ----------------- Enter this sub-interface
dot1q termination vid 20 ------------------------- ----- This sub-interface belongs to vlan 20
ip address 192.168.20.1 255.255.255.0 ----------- Add IP address
arp broadcast enable -------------- -------------------- Open arp broadcast
dhcp select interface ------------------------ ----------- dhcp service selects this subinterface
dhcp server dns-list 2.2.2.2 8.8.8.8 ----------------- dns domain name of dhcp service
interface GigabitEthernet0/0/2------------------------ Enter this interface
ip address 14.0.0.1 255.255.255.0 --------- --------- Add IP address
ip route-static 15.0.0.0 255.255.255.0 12.0.0.2 — Configure static route entries

R2 configuration

sysname R2
dhcp enable
interface GigabitEthernet0/0/0
ip address 12.0.0.2 255.255.255.0

interface GigabitEthernet0/0/1
ip address 15.0.0.1 255.255.255.0
dhcp select relay
dhcp relay server-ip 14.0.0.2
ip route-static 0.0.0.0 0.0.0.0 12.0.0.1

R3 configuration

sysname R3
dhcp enable
ip pool DHCP15.0.0.0 ------------------------------------ creating dhcp Following the address pool
gateway-list 15.0.0.1 ------------------------------------ Set the gateway
network 15.0. 0.0 mask 255.255.255.0 -------------- Network number and subnet mask
static-bind ip-address 15.0.0.55 mac-address 5489-9855-6106
Add a fixed value to the MAC address of this PC5 Dhcp relay IP address
excluded-ip-address 15.0.0.100 15.0.0.254 ------- Set the network segment 100~245 to not allow allocation of
dns-list 8.8.8.8 2.2.2.2 ------ ----------------------------- dns domain name
ip pool DHCPvlan10
gateway-list 192.168.10.1
network 192.168.10.0 mask 255.255.255.0
dns- list 8.8.8.8 2.2.2.2
interface GigabitEthernet0/0/0
ip address 14.0.0.2 255.255.255.0
dhcp select global --------------------------------------- dhcp service select global
ip route-static 0.0.0.0 0.0.0.0 14.0.0.1
ip route-static 15.0.0.0 255.255.255.0 14.0.0.1

Configuration of LSW1

sysname SW1

vlan batch 10 20
interface Ethernet0/0/1
port link-type access
port default vlan 10

interface Ethernet0/0/2
port link-type access
port default vlan 10

interface Ethernet0/0/3
port link-type access
port default vlan 20

interface Ethernet0/0/4
port link-type access
port default vlan 20

PC configuration

Check the DHCP service option of each PC
Insert picture description here

4. Experimental results

Insert picture description here

Guess you like

Origin blog.csdn.net/wulimingde/article/details/107191974