DHCP and DHCP Relay--Principle and Configuration--Huawei Experiment--Configure Interface Mode, Global Mode, and Relay Mode


One, DHCP

1 Overview

  • DHCP (Dynamic Host Configuration Protocol, Dynamic Host Configuration Protocol) is a network protocol for local area networks. It works with UDP protocol and has two main purposes:
    • Automatically assign IP addresses to internal networks or network service providers
    • For users or internal network administrators as a means of central management of all computers

2. Advantages

  1. Reduce the workload of administrators
  2. Avoid the possibility of input errors
  3. Avoid IP address conflicts
  4. When changing the IP address segment, there is no need to reconfigure each user's IP address
  5. Improved utilization of IP addresses
  6. Convenient client configuration

3. Application

  • The typical application mode of DHCP is as follows:
    • Set up a dedicated DHCP server in the network to centrally allocate various network address parameters (mainly including IP address, subnet mask, broadcast address, default gateway address, DNS server address)
    • Other hosts act as DHCP clients, configure the network card to automatically obtain addresses, and then communicate with the DHCP server to complete the automatic configuration process
  • The DHCP protocol uses UDP as the transmission protocol. The host sends a request message to port 67 of the DHCP server, and the DHCP server responds with a response message to port 68 of the client.

4. Interactive process

  1. Step 1: The client searches for the server in the network. The
    client sends a DHCP Discover message through broadcast to find the server.
  2. Step 2: The server responds to the client with a response service. The
    server sends a DHCP Offer
    message through unicast to provide the client with network information such as an IP address, and selects an unassigned IP address from the IP address pool to assign to the client
  3. Step 3: The client sends a service request to the server.
    If multiple DHCP servers send a DHCP-offer message to the client, the client only accepts the first received DHCP-offer message and extracts the IP address. The client broadcasts a DHCP Request message to inform the server to choose the IP address locally
  4. Step 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 legally available, and adds the lease information of the IP address to the option field
  5. Step 5: Re-login to the
    DHCP client every time you re-login to the network, you do not need to send DHCP Discover information, but directly send the HCP Request request information containing the IP address assigned last time
  6. Step 6: Renew the lease When
    the IP address leased by the DHCP server to the client reaches 50%, the lease needs to be renewed. The client directly sends a DHCP Request packet to the server that provides the lease, requesting to update the existing address lease

5. Configuration method

  • There are 2 configuration methods for DHCP

5.1 Interface mode

The interface address pool can dynamically assign 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. Network segment assigns addresses to clients

[R1]dhcp enable ###系统模式开启DHCP功能

[R1]interface GigabitEthernet0/0/0
[R1-GigabitEtherneto/0/0] dhcp select interface ###基于接口配置DHCP
[R1-GigabitEtherneto/0/0] dhcp server lease day 7 ##井配置基于接口的DHCP servser租期(默认租期为1天)

[R1-GigabitEthernet0/0/0] dhcp server excluded-ip-address 192.168.10.200 192.168.10.210
###配置接口地址池中不参与自动分配的IP地址范为192.168.10.200到192.168.10.210
[R1-GigabitEthernet0/0/0] dhcp server dns-list 8.8.8.8 ###给用户端自动分配DNS服务器地址

5.2 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 is the same network segment, that is, multiple different network segment pools correspond to their respective ports, and finally realize different network segment clients Obtain the corresponding address automatically

[R1] dhcp enable ###系统模式开启DHCP功能
[R1] ip pool 1 ###创建地址池名称
[R1-ip-pool-1] gateway-list 192.168.20.1 ###设置DHCP客户端的出口网关地址
[R1-ip-pool-1] network 192.168.20.0 mask 255.255.255.0 ###配置DHCP可分配地址网段,掩码也可用24表示
[R1-ip-pool-1] dns-list 114.114.114.114 ##井配置DHCP分配DNS地址
[R1-ip-pool-1] excluded-ip-address 192.168.20.250 192.168.20.254 ###配置保留地址
[R1-ip-pool-1] static-bind ip-address 192.168.20.9 mac-address 5489-98C6-OCEE
###定IP192.168.20.9固定分配给MAC为28d2-4469-5a55的机器,需池中IP
[R1-ip-pool-huawei1] lease day 10 ###租期10天

[R1]int g0/0/0
[R1-GigabitEthernet0/0/0] dhcp select global ##配置DHCP为global全局模式, interface即接口模式[Huawei] display ip pool ###查看IP地址池信息

Two, DHCP relay

1. Application scenarios

  • In a large network, there may be multiple network segments
  • The DHCP client gets the IP address after obtaining the response from the DHCP server through the network broadcast message, but the broadcast message cannot cross the network segment
  • Therefore, if the DHCP client and server are in different network segments, can the client apply for an IP address from the server? This requires the use of a DHCP relay agent
  • The DHCP relay agent is actually 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 the DHCP client and server between different network segments.

2. 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 Mudi network does not have a DHCP server, the network device connected to this 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 the 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

3. Configure the DHCP relay server

[R1]dhcp enable
[R1]interface GigabitEtherneto/0/1 ###与客户端相连的接口
[R1-GigabitEtherneto/0/1] ip add 192.168.1.1 24
[R1-GigabitEthernet0/0/1] dhcp select relay ###开启DHCP中继功能
[R1-GigabitEtherneto/0/1] dhcp relay server-ip 12.0.0.1 ##指向DHCP服务器的地址12.0.0.1请求DHCP服务

[R1]ip route-static 0.0.0.0 0.0.0.0 12.0.0.1
###如果DHCP中继服务器与DHCP服务器跨网段则要配置静态或动态路由

[R1]interface GigabitEtherneto/0/0
[R1-GigabitEtherneto/0/0] ip add 12.0.0.2 24

4. Configure the DHCP server

[R2] dhcp enable
[R2]interface GigabitEtherneto/0/0 ###与DHCP中继连接方向的接口
[R2-GigabitEthernet0/0/0] ip add 12.0.0.1 24
[R2-GigabitEthernet0/0/0] dhcp select global ###给接口配置为全局模式请求DHCP服务

[R2] ip pool 1
[R2-ip-pool-1]gateway-list 192.168.1.1
[R2-ip-pool-1]network 192.168.1.0 mask 255.255.255.0

[R2-ip-pool-1]dns-list 114.114.114.114
[R1-ip-pool-1]lease day 3 ####租期3天
[Huawei]ip route-static 192.168.1.0 255.255.255.0 12.0.0.2 ##记得要配置静态/默认路由或者动态路由

Three, interface mode configuration

Topology

  • The environment is set up as follows:
    mark

R1

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R1
[R1]un in en
Info: Information center is disabled.
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 192.168.1.1 24
[R1-GigabitEthernet0/0/0]un sh
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R1-GigabitEthernet0/0/0]q
##系统模式开启DHCP功能
[R1]dhcp enable 
Info: The operation may take a few seconds. Please wait for a moment.done.
[R1]int g0/0/0
##基于接口配置DHCP
[R1-GigabitEthernet0/0/0]dhcp select interface 
##配置基于接口的DHCP server租期
[R1-GigabitEthernet0/0/0]dhcp server lease day 7
##配置接口池中不参与自动分配的IP地址范围为192.168.1.250至192.168.1.254
[R1-GigabitEthernet0/0/0]dhcp server excluded-ip-address 192.168.1.250 192.168.1
.254
##给用户端自动分配DNS服务器地址
[R1-GigabitEthernet0/0/0]dhcp server dns-list 8.8.8.8
##检查一下
[R1-GigabitEthernet0/0/0]di th
[V200R003C00]
#
interface GigabitEthernet0/0/0
 ip address 192.168.1.1 255.255.255.0 
 dhcp select interface
 dhcp server excluded-ip-address 192.168.1.250 192.168.1.254 
 dhcp server lease day 7 hour 0 minute 0 
 dhcp server dns-list 8.8.8.8 
#
return

PC

mark
mark

mark
mark


Four, global mode

Topology

  • Add a new host
    mark
  • Note: The following is the configuration from the beginning, it is recommended to save the topology diagram and re-enter, and then add a new PC to follow along

R1

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R1
[R1]un in en
Info: Information center is disabled.
##配置各端口IP
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 192.168.1.1 24
[R1-GigabitEthernet0/0/0]un sh
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]ip add 192.168.100.1 24
[R1-GigabitEthernet0/0/1]un sh
Info: Interface GigabitEthernet0/0/1 is not shutdown.
##检查一下
[R1-GigabitEthernet0/0/1]di ip int b

[R1-GigabitEthernet0/0/1]q
##系统模式下开启DHCP功能
[R1]dhcp enable 
Info: The operation may take a few seconds. Please wait for a moment.done.
##创建地址池,名称为1
[R1]ip pool 1
Info: It's successful to create an IP address pool.
##设置DHCP客户端的出口网关地址
[R1-ip-pool-1]gateway-list 192.168.1.1
##配置DHCP可分配地址网段,需配置掩码
[R1-ip-pool-1]network 192.168.1.0 mask 255.255.255.0
##配置DHCP分配DNS地址
[R1-ip-pool-1]dns-list 8.8.8.8
##配置保留地址
[R1-ip-pool-1]excluded-ip-address 192.168.1.250 192.168.1.254
##固定分配给特定MAC某个特定的IP
[R1-ip-pool-1]static-bind ip-address 192.168.1.88 mac-address 5489-9805-1F11
[R1-ip-pool-1]di th

##配置租期
[R1-ip-pool-1]lease day 10
[R1-ip-pool-1]int g0/0/0
##配置DHCP为global全局模式
[R1-GigabitEthernet0/0/0]dhcp select global 
##配置地址池pool2
[R1-GigabitEthernet0/0/0]ip pool 2
Info: It's successful to create an IP address pool.
##配置DHCP客户端出口网关地址
[R1-ip-pool-2]gateway-list 192.168.100.1
##配置DHCP可分配地址网段及掩码
[R1-ip-pool-2]network 192.168.100.0 mask 24
##配置租期
[R1-ip-pool-2]lease day 7
##配置DHCP分配DNS地址
[R1-ip-pool-2]dns-list 114.114.114.114
[R1-ip-pool-2]di th

[R1-ip-pool-2]int g0/0/1
##进入相应端口配置全局模式
[R1-GigabitEthernet0/0/1]dhcp select global 


PC

  • Configure PC, get IP automatically

mark
mark

mark
mark


Five, relay mode

Topology

mark

R1

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R1
[R1]un in en
Info: Information center is disabled.

[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 192.168.1.1 24
[R1-GigabitEthernet0/0/0]un sh
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]ip add 10.0.0.2 24
[R1-GigabitEthernet0/0/1]un sh
Info: Interface GigabitEthernet0/0/1 is not shutdown.

[R1-GigabitEthernet0/0/1]q
##开启DHCP
[R1]dhcp enable 
Info: The operation may take a few seconds. Please wait for a moment.done.
[R1]int g0/0/0
##开启DHCP中继功能
[R1-GigabitEthernet0/0/0]dhcp select relay
##指向DHCP中继服务器的地址
[R1-GigabitEthernet0/0/0]dhcp relay server-ip 20.0.0.4
[R1-GigabitEthernet0/0/0]q
##配置静态路由
[R1]ip route-static 0.0.0.0 0.0.0.0 10.0.0.3

R2

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R2
[R2]un in en
Info: Information center is disabled.
[R2]int g0/0/1
[R2-GigabitEthernet0/0/1]ip add 10.0.0.3 24
[R2-GigabitEthernet0/0/1]un sh
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[R2-GigabitEthernet0/0/1]int g0/0/0
[R2-GigabitEthernet0/0/0]ip add 20.0.0.3 24
[R2-GigabitEthernet0/0/0]un sh
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R2-GigabitEthernet0/0/0]q
[R2]ip route-static 192.168.1.0 24 10.0.0.2

R3

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R3
[R3]un in en
Info: Information center is disabled.

[R3]int g0/0/0
[R3-GigabitEthernet0/0/0]ip add 20.0.0.4 24
[R3-GigabitEthernet0/0/0]un sh
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R3-GigabitEthernet0/0/0]int g0/0/1
[R3-GigabitEthernet0/0/1]ip add 10.0.0.2 24
[R3-GigabitEthernet0/0/1]un sh
Info: Interface GigabitEthernet0/0/1 is not shutdown.

[R3-GigabitEthernet0/0/1]q
[R3]dhcp enable 
Info: The operation may take a few seconds. Please wait for a moment.done.

[R3]ip pool 1
Info: It's successful to create an IP address pool.
[R3-ip-pool-1]gateway-list 192.168.1.1
[R3-ip-pool-1]network 192.168.1.0 mask 24
[R3-ip-pool-1]lease day 7
[R3-ip-pool-1]dns-list 8.8.8.8

[R3-ip-pool-1]int g0/0/0
[R3-GigabitEthernet0/0/0]dhcp select global 
[R3-GigabitEthernet0/0/0]q
[R3]ip route-static 0.0.0.0 0.0.0.0 20.0.0.3

PC

mark
mark

mark
mark

Guess you like

Origin blog.csdn.net/weixin_51486343/article/details/112095917