DHCP and DHCP relay

1. DHCP

1. Concept

DHCP and DHCP Relay
DHCP (Dynamic Host Configuration Protocol, Dynamic Host Configuration Protocol) is a LAN network protocol that uses UDP protocol to work, mainly for two purposes:
1) Automatically assign IP addresses to internal networks or network service providers
2 ) For users or internal network administrators as a means of central management of all computers

2. The benefits of using DHCP

1. Reduce the workload of the administrator
2. Avoid the possibility of input errors
3. Avoid IP address conflict
4. When the IP address segment is changed, there is no need to reconfigure each user's IP address
5. Convenient client configuration

3. The working principle of DHCP's automatic IP address acquisition

Step 1: The client searches for the server in the network. The
client sends a DHCP Discover message to find the server by broadcasting.

Step 2: The server responds to the client to serve the
client. The server sends a DHCP Offer
message through unicast to provide the client with network information such as the IP address, and selects an unallocated IP from the IP address pool to assign to the client

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, and then The client broadcasts a DHCP Request message to inform the server to choose the IP address locally.

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 in the option field

Five: Re-login the
DHCP client every time you re-login to the network, you do not need to send DHCP Discover information, but directly send the DHCP Requset request message containing the IP address assigned last time

Six: Renew the lease.
When the lease of the IP address leased by the DHCP server to the client reaches half, the lease needs to be renewed. The client sends a DHCP Request packet directly to the server, requesting to renew the existing address lease.

The typical application mode of DHCP is as follows :
set up a dedicated DHCP server in the network, which is responsible for centrally assigning various network address parameters (mainly including IP address, subnet mask, broadcast address, default gateway address, DNS server address); other As a DHCP client, the host configures the network card to automatically obtain an address, and then communicates 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.

DHCP configuration commands

DHCP 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.

[R1]dhcp enable
system mode to enable DHCP function

[R1]interface GigabitEthernet0/0/0
enter the downstream interface

[R1-GigabitEthernet0/0/0]dhcp select interface
configures DHCP based on the interface

[R1-GigabitEthernet0/0/0]dhcp server lease day 7
Configure the interface-based DHCP servser lease (the default lease is 1 day)

Optional [R1-GigabitEthernet0/0/0]dhcp server excluded-ip-address 192.168.10.200 192.168.10.210
Configure the IP range of the interface address pool that does not participate in automatic allocation from 192.168.10.200 to 192.168.10.210

[R1-GigabitEthernet0/0/0]dhcp server dns-list 8.8.8.8
automatically assign DNS server address to the client

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]dhcp enable
system mode to enable DHCP function

[R1]ip pool 1
create address pool name

[R1-ip-pool-1]gateway-list 192.168.20.1
Set the export gateway address of the DHCP client

[R1-ip-pool-1]network 192.168.20.0 mask 255.255.255.0
Configure the DHCP assignable address network segment, the mask can also be expressed as 24

[R1-ip-pool-1]dns-list 114.114.114.114
configure DHCP to assign DNS address

[R1-ip-pool-1]excluded-ip-address 192.168.20.250 12.168.20.254
Configure reserved address

[R1-ip-pool-1]static-bind ip-address 192.168.20.9 mac-address 5489-98c6-0cee
绑定IP

[R1-ip-pool-1 ] lease day 10
lease 10 days

[R1]int g0/0/0
enter the downlink interface

[R1-GigabitEthernet0/0/0] dhcp select global
configures DHCP to global mode, interface is interface mode

[Huawei]display ip pool
View IP address pool information

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, can the client apply for an IP address from the server? This requires a DHCP relay agent. DHCP relay agent is actually a kind of software technology. The device (router, switch, server) installed with DHCP relay agent is called DHCP relay agent server, which undertakes the communication tasks of DHCP client and server between different network segments. .

(2) Working principle

When the DHCP client starts and initializes the DHCP, it broadcasts a configuration request message on the local network.
If there is a DHCP server in the local network, you can directly perform DHCP configuration without a DHCP relay.
If the local network does not have a DHCP server, the network device connected to the local network with a DHCP relay function will process the broadcast message appropriately and forward it to the designated DHCP server on other networks.
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.
Configure the DHCP relay server
[R1]dhcp enable

[R1]interface GigabitEthernet 0/0/1
and the interface connected to the client

[R1-GigabitEthernet0/0/1]ip add 192.168.1.1 24

[R1-GigabitEthernet0/0/1] dhcp select relay
enables DHCP relay function

[R1-GigabitEthernet0/0/1]dhcp relay server-ip 12.0.0.1
points to the address of the DHCP server 12.0.0.1 to request DHCP service

[R1]ip route-static 0.0.0.0 0.0.0.0 12.0.0.1
If the DHCP relay server and the DHCP server cross the network segment, static or dynamic routing must be configured

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

Configure the DHCP server:
[R2]dhcp enable

[R2]interface GigabitEthernet 0/0/0
and DGCP trunk connection direction interface

[R2-GigabitEthernet0/0/0]ip add 12.0.0.1 24

[R2-GigabitEthernet0/0/0] dhcp select global
configures the interface as global mode to request DHCP service

[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

[R2-ip-pool-1 ] lease day 3
lease three days

[Huawei] ip route-static 192.168.1.0 255.255.255.0 12.0.0.2
If the DHCP relay server and the DHCP server cross the network segment, you need to configure static or dynamic routing

Guess you like

Origin blog.csdn.net/zhangyuebk/article/details/112345186