DHCP dynamic host configuration protocol and DHCP relay

A.dhcp

(1) The concept and function of dhcp

1. Concept: dhcp is automatically obtained ip is a local area network protocol.
Working with UDP protocol, the client sends a request to port 67 of the dhcp server, and the dhcp server responds with a response message to port 68 of the client (server 67, client 68)
2. Function:
a. To the internal network or network service provider Automatically assign IP addresses
b. To users or internal network administrators as a means of central management of all computers
3. The benefits of using dhcp

  • Reduce the workload of administrators
  • Avoid the possibility of input errors
  • Avoid IP address conflicts
  • When the IP address segment is changed, there is no need to reconfigure each user's IP address
  • Improve the utilization of ip addresses
  • Convenient client configuration

4. DHCP classic application scenario
Set up a dedicated DHCP server in the network, responsible for centrally assigning various network address parameters (mainly including IP address, subnet mask, broadcast address, default gateway address, DNS server address) and other hosts as DHCP client, configure the network card to automatically obtain an address, and then communicate with the DHCP server to complete the automatic configuration process.

(2) The working principle of dhcp (interactive process)

1. The client searches the network server
client through the broadcast sends DHCP Discover packets to find the server
2. The server response to client service
server via unicast sending DHCP Offer
packet provides IP address and other network information to clients, from Select an unallocated IP from the IP address pool to assign to the client
3. The client sends a service request to the server.
If multiple DHCP servers send a DHCP-offer message to the client, the client will only accept the first one received DHCP-offer message and extract the IP address, and then the client broadcasts a DHCP Request message to inform the server to choose to use the IP address locally.
4. The server provides services to the client. The
server sends a DHCP Ack message through unicast to inform the client that the IP address is legal and usable, and adds the lease information of the IP address in the option field. 5. Re-login to the DHCP client every time When logging in to the network, there is no need to send DHCP Discover information, but directly send a DHCP Requset request message containing the IP address assigned last time. 6. Renew the lease. When the lease period of the IP address leased by the DHCP server to the client reaches half, then To renew the lease, the client directly sends a DHCP Request packet to the server, requesting to renew the existing address lease.




The client sends a message to the dhcp server through broadcast, and the dhcp server responds to the message through unicast
Insert picture description here

Two, DHCP relay server

(1) Application scenarios

In a large network, there may be multiple network segments. The DHCP client obtains the IP address after obtaining the response from the DHCP server through the network broadcast message. But broadcast messages cannot cross network segments. Therefore, if the DHCP client and server are in different network segments, the DHCP relay agent will be used when the client requests the dhcp server to assign an IP address. The DHCP relay agent is a software technology. The device (router, switch, server) installed with the DHCP relay agent is called the DHCP relay agent server, which undertakes the communication tasks of DHCP clients and servers between different network segments.

(Two) working principle

1. When the DHCP client starts and performs DHCP initialization, it broadcasts a configuration request message on the local network.
2. If there is a DHCP server in the local network, you can directly perform DHCP configuration without a DHCP relay.
3. If the local network does not have a DHCP server, the network device connected to the local network with DHCP relay function will process the broadcast message appropriately and forward it to the designated DHCP server on other networks.
4. The DHCP server performs corresponding configuration according to the information provided by the client, and sends the configuration information to the client through the DHCP relay to complete the dynamic configuration of the client.

Three, dhcp command configuration and dhcp relay server command configuration

(1) DHCP configuration

Configure router interface address and configure or enable dhcp service on the router's downstream interface

1.dhcp global mode

In the global mode, multiple global address pools are set up, and there is a corresponding relationship between the defined address pool network segment and port IP that are the same network segment , that is, multiple address pools of different network segments correspond to their respective ports, and finally realize different network segments The client automatically obtains the corresponding address.
[R1]int g0/0/0 #Enter the interface configuration address
[Huawei-GigabitEthernet0/0/0]ip add 192.168.20.1 24 #The address network segment is a dhcp network segment that can be allocated
[R1]dhcp enable #system mode Enable the DHCP function
[R1]ip pool 1 #Create an address pool name
[R1-ip-pool-1]gateway-list 192.168.20.1 #Create the export gateway address of the DHCP client
[R1-ip-pool-1]network 192.168.20.0 mask 24 #Configure DHCP assignable address network segment, subnet mask is also available 255.255.255.0
[R1-ip-pool-1]dns-list 8.8.8.8 #Configure DHCP to assign DNS address
optional [R1-ip-pool- 1]excluded-ip-address 192.168.20.80 12.168.20.90 #Configure reserved address
matching [R1-ip-pool-1] static-bind ip-address 192.168.20.88 mac-address 5489-98c6-0cee #Bind with the host Fixed IP address
[R1-ip-pool-1] lease day 10 #Lease day 10 days (default lease time is 1 day)
[R1]int g0/0/0 #Enter the downstream interface
[R1-GigabitEthernet0/0/0]dhcp select global #Configure DHCP to global global mode, interface is the interface mode
[Huawei]display ip pool #View IP address pool information

2. Interface mode

The interface address pool can dynamically allocate IP addresses. The range is the network segment where the IP address of the interface is located , and it only takes effect on this interface. When the DHCP server receives the request message from the DHCP client, the DHCP server will use the address of the interface The network segment assigns addresses to clients.
Enter the router's downstream interface configuration address
[R1]dhcp enable ### Enable the DHCP function in the system mode
[R1]interface GigabitEthernet0/0/1 ### Enter the downstream interface
[R1-GigabitEthernet0/0/1]dhcp select interface ###Based on Interface configuration DHCP
[R1-GigabitEthernet0/0/1]dhcp server lease day 7
[R1-GigabitEthernet0/0/1]dhcp server excluded-ip-address 192.168.30.100 192.168.30.111
Configure the IP addresses in the interface address pool that do not participate in automatic allocation The range is 192.168.30.100 to 192.168.30.111
[R1-GigabitEthernet0/0/0]dhcp server dns-list 8.8.8.8
automatically assign DNS server address to the client
Insert picture description here

(2) DHCP relay service command configuration

1. Repeater command configuration

[R1]dhcp enable #Turn on dhcp
[R1]interface GigabitEthernet 0/0/0 #Downstream interface of the interface connected to the client
[R1-GigabitEthernet0/0/0]ip add 192.168.1.1 24
[R1-GigabitEthernet0/0/0 ]dhcp select relay #Turn on the DHCP relay function
[R1-GigabitEthernet0/0/0]dhcp relay server-ip 12.0.0.1 #Point to the address of the interface between the DHCP server and the relay server 12.0.0.2 Request DHCP service
[R1]ip route -static 0.0.0.0 0.0.0.0 12.0.0.2 #If the DHCP relay server and the DHCP server cross the network segment, static or dynamic routing should be configured

2. Command configuration of DHCP server

The configuration of the dhcp server is global mode. Enable the global mode on the interface connected to the relay server.
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]uie
[Huawei-ui -console0]sysname r2
[r2]int g0/0/0
[r2-GigabitEthernet0/0/0]ip add 12.0.0.2 24
[r2-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[r2-GigabitEthernet0/0/0]q
[r2]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[r2]ip pool 1
Info: It's successful to create an IP address pool.
[r2-ip-pool-1]gateway-list 192.168.1.1
[r2-ip-pool-1]network 192.168.1.0 mask 24
[r2-ip-pool-1]lease day 10
[r2-ip-pool -1]q
[r2]int g0/0/0
[r2-GigabitEthernet0/0/0]dhcp select global
[r2-GigabitEthernet0/0/0]q
[r2]ip route-static 0.0.0.0 0 12.0.0.1
Experimental results
pc1 get IP address
pc2 gets the address and can communicate with pc1

Guess you like

Origin blog.csdn.net/weixin_53567573/article/details/112638351