Principle and configuration of DHCP

Posted by iJoseph on Sat, 18 Dec 2021 18:19:18 +0100

1. Functions and benefits of DHCP

2.2 principle

3.3 lease term

4.DHCP service

5.DHCP configuration

5.1 same network segment

5.2 different network segments - DHCP relay

summary

1. Functions and benefits of DHCP

DHCP -- Dynamic Host Configuration Protocol

Role: distribute IP address, subnet mask, gateway, DNS server, lease term and other parameters to clients

Benefits of using DHCP:

1. Simplify client settings

2. Prevent customers from misoperation

3. Avoid duplicate IP addresses

Note: the client refers to the device and the client refers to the user

The transport layer corresponding to DHCP service is UDP protocol. Because it is a C/S architecture, DHCP service is divided into client occupying UDP port 67 and DHCP server occupying UDP port 68.

Architecture: C/S architecture client / server architecture C - client s - server

2.2 principle

Principle: ① DHCP client sends DHCPdiscovery request to all DHCP servers in LAN. (DHCP client sends DHCP request to DHCP server to request IP)

② All DHCP servers in the LAN will reply to DHCPoffer and provide the IP address for the client

③ The client selects the IP address replied by the first DHCP server and sends DHCPrequest notification to all DHCP servers in the LAN. It selects which IP and which DHCP server. Note: there are two reasons for the client to send DHCPreques notification. The first layer is to notify all DHCP servers so that other unselected DHCP servers can recycle the unused address. The second layer is to notify the selected DHCP server that the DHCP client is going to use.

④ After receiving the DHCPrequest message, the selected DHCP server will reply a DHCPack to the DHCP client to formally confirm that the IP can be used by the client. The DHCP client will bind the IP with its own MAC to continue to use next time, and other DHCP servers will recycle the IP assigned to the DHCP client.

3.3 lease term

Lease term: DHCP clients use IP addresses for a limited period of time. Generally, when the DHCP client uses the IP address allocated by DHCP to 50% of the lease term, it will actively send a renewal request to the DHCP server. After the DHCP server receives the renewal request from the DHCP client, the DHCP server will check whether this IP address is preempted by other DHCP clients. If not, the renewal is successful. If this IP address is occupied by other DHCP clients, the renewal will not succeed. At this time, the DHCP client will re initiate the DHCPdiscovery request to obtain the new IP address.

4.DHCP service

The implementation of DHCP service can be divided into two cases:

Case 1: DHCP server and DHCP client are in the same network segment

Case 2: DHCP server and DHCP client are not in the same network segment

Note: DHCP relay can only be implemented by the router, and the DHCP server cannot be implemented alone - for case 2

5.DHCP configuration

5.1 same network segment

<Huawei>UN	
<Huawei>undo TE	
<Huawei>undo terminal MO	
<Huawei>undo terminal monitor 
Info: Current terminal monitor is off.
<Huawei>SY	
<Huawei>system-view 
Enter system view, return user view with Ctrl+Z.
[Huawei]SYSN	
[Huawei]sysname SW2
[SW2]US	
[SW2]user-IN	
[SW2]user-interface CO	
[SW2]user-interface console 0
[SW2-ui-console0]ID	
[SW2-ui-console0]idle-timeout 0 0
[SW2-ui-console0]Q
[SW2]VL	
[SW2]vlan BA	
[SW2]vlan batch 10 20
Info: This operation may take a few seconds. Please wait for a moment...done.
[SW2]INT e0/0/1
[SW2-Ethernet0/0/1]po	
[SW2-Ethernet0/0/1]port li	
[SW2-Ethernet0/0/1]port link-ty	
[SW2-Ethernet0/0/1]port link-type ac	
[SW2-Ethernet0/0/1]port link-type access 
[SW2-Ethernet0/0/1]po	
[SW2-Ethernet0/0/1]port de	
[SW2-Ethernet0/0/1]port default vl	
[SW2-Ethernet0/0/1]port default vlan 10
[SW2-Ethernet0/0/1]int e0/0/2
[SW2-Ethernet0/0/2]po	
[SW2-Ethernet0/0/2]port li	
[SW2-Ethernet0/0/2]port link-ty	
[SW2-Ethernet0/0/2]port link-type ac	
[SW2-Ethernet0/0/2]port link-type access 
[SW2-Ethernet0/0/2]po	
[SW2-Ethernet0/0/2]port de	
[SW2-Ethernet0/0/2]port default vl	
[SW2-Ethernet0/0/2]port default vlan 20
[SW2-Ethernet0/0/2]int g0/0/1
[SW2-GigabitEthernet0/0/1]po	
[SW2-GigabitEthernet0/0/1]port li	
[SW2-GigabitEthernet0/0/1]port link-ty	
[SW2-GigabitEthernet0/0/1]port link-type tr	
[SW2-GigabitEthernet0/0/1]port link-type trunk 
[SW2-GigabitEthernet0/0/1]po	
[SW2-GigabitEthernet0/0/1]port rt	
[SW2-GigabitEthernet0/0/1]port tr	
[SW2-GigabitEthernet0/0/1]port trunk al	
[SW2-GigabitEthernet0/0/1]port trunk allow-pass vl	
[SW2-GigabitEthernet0/0/1]port trunk allow-pass vlan al	
[SW2-GigabitEthernet0/0/1]port trunk allow-pass vlan all 
[SW2-GigabitEthernet0/0/1]
<Huawei>un	
<Huawei>undo TE	
<Huawei>undo terminal MO	
<Huawei>undo terminal monitor 
Info: Current terminal monitor is off.
<Huawei>sys	
<Huawei>system-view 
Enter system view, return user view with Ctrl+Z.
[Huawei]sysn	
[Huawei]sysname sw3
[sw3]us	
[sw3]user-in	
[sw3]user-interface co	
[sw3]user-interface console 0
[sw3-ui-console0]id	
[sw3-ui-console0]idle-timeout 0 0
[sw3-ui-console0]q
[sw3]vl	
[sw3]vlan ba	
[sw3]vlan batch 10 20
Info: This operation may take a few seconds. Please wait for a moment...done.
[sw3]int e0/0/1
[sw3-Ethernet0/0/1]po	
[sw3-Ethernet0/0/1]port li	
[sw3-Ethernet0/0/1]port link-ty	
[sw3-Ethernet0/0/1]port link-type ac	
[sw3-Ethernet0/0/1]port link-type access 
[sw3-Ethernet0/0/1]po	
[sw3-Ethernet0/0/1]port de	
[sw3-Ethernet0/0/1]port default vl	
[sw3-Ethernet0/0/1]port default vlan 10
[sw3-Ethernet0/0/1]int e0/0/2
[sw3-Ethernet0/0/2]po	
[sw3-Ethernet0/0/2]port li	
[sw3-Ethernet0/0/2]port link-ty	
[sw3-Ethernet0/0/2]port link-type ac	
[sw3-Ethernet0/0/2]port link-type access 
[sw3-Ethernet0/0/2]po	
[sw3-Ethernet0/0/2]port de	
[sw3-Ethernet0/0/2]port default vl	
[sw3-Ethernet0/0/2]port default vlan 20
[sw3-Ethernet0/0/2]int g0/0/1
[sw3-GigabitEthernet0/0/1]po	
[sw3-GigabitEthernet0/0/1]port li	
[sw3-GigabitEthernet0/0/1]port link-ty	
[sw3-GigabitEthernet0/0/1]port link-type tr	
[sw3-GigabitEthernet0/0/1]port link-type trunk 
[sw3-GigabitEthernet0/0/1]po	
[sw3-GigabitEthernet0/0/1]port tr	
[sw3-GigabitEthernet0/0/1]port tr	
[sw3-GigabitEthernet0/0/1]port trunk al	
[sw3-GigabitEthernet0/0/1]port trunk allow-pass vl	
[sw3-GigabitEthernet0/0/1]port trunk allow-pass vlan al	
[sw3-GigabitEthernet0/0/1]port trunk allow-pass vlan all 
[sw3-GigabitEthernet0/0/1]
<Huawei>un	
<Huawei>undo te	
<Huawei>undo terminal mo	
<Huawei>undo terminal monitor 
Info: Current terminal monitor is off.
<Huawei>sy	
<Huawei>system-view 
Enter system view, return user view with Ctrl+Z.
[Huawei]sysn	
[Huawei]sysname sw1
[sw1]us	
[sw1]user-in	
[sw1]user-interface co	
[sw1]user-interface console 0
[sw1-ui-console0]id	
[sw1-ui-console0]idle-timeout 0 0
[sw1-ui-console0]q
[sw1]vl	
[sw1]vlan ba	
[sw1]vlan batch 10 20
Info: This operation may take a few seconds. Please wait for a moment...done.
[sw1]int g0/0/1
[sw1-GigabitEthernet0/0/1]po	
[sw1-GigabitEthernet0/0/1]port li	
[sw1-GigabitEthernet0/0/1]port link-ty	
[sw1-GigabitEthernet0/0/1]port link-type tr	
[sw1-GigabitEthernet0/0/1]port link-type trunk 
[sw1-GigabitEthernet0/0/1]po	
[sw1-GigabitEthernet0/0/1]port tr	
[sw1-GigabitEthernet0/0/1]port trunk al	
[sw1-GigabitEthernet0/0/1]port trunk allow-pass vl	
[sw1-GigabitEthernet0/0/1]port trunk allow-pass vlan al	
[sw1-GigabitEthernet0/0/1]port trunk allow-pass vlan all 
[sw1-GigabitEthernet0/0/1]int g0/0/2
[sw1-GigabitEthernet0/0/2]po	
[sw1-GigabitEthernet0/0/2]port li	
[sw1-GigabitEthernet0/0/2]port link-ty	
[sw1-GigabitEthernet0/0/2]port link-type tr	
[sw1-GigabitEthernet0/0/2]port link-type trunk 
[sw1-GigabitEthernet0/0/2]po	
[sw1-GigabitEthernet0/0/2]port tr	
[sw1-GigabitEthernet0/0/2]port trunk al	
[sw1-GigabitEthernet0/0/2]port trunk allow-pass 
                                                ^
Error:Incomplete command found at '^' position.
[sw1-GigabitEthernet0/0/2]po	
[sw1-GigabitEthernet0/0/2]port li	
[sw1-GigabitEthernet0/0/2]port link-ty	
[sw1-GigabitEthernet0/0/2]port tr	
[sw1-GigabitEthernet0/0/2]port trunk al	
[sw1-GigabitEthernet0/0/2]port trunk allow-pass vl	
[sw1-GigabitEthernet0/0/2]port trunk allow-pass vlan al	
[sw1-GigabitEthernet0/0/2]port trunk allow-pass vlan all 
[sw1-GigabitEthernet0/0/2]q
[sw1]dhcp en	
[sw1]dhcp enable 
Info: The operation may take a few seconds. Please wait for a moment.done.
[sw1]int vl	
[sw1]int Vlanif 10
[sw1-Vlanif10]ip ad	
[sw1-Vlanif10]ip address 192.168.10.1 24
[sw1-Vlanif10]dh	
[sw1-Vlanif10]dhcp se	
[sw1-Vlanif10]dhcp select in	
[sw1-Vlanif10]dhcp select interface 
[sw1-Vlanif10]dh	
[sw1-Vlanif10]dhcp se	
[sw1-Vlanif10]dhcp ser	
[sw1-Vlanif10]dhcp server dns	
[sw1-Vlanif10]dhcp server dns-list 4.4.4.4 8.8.8.8
[sw1-Vlanif10]ip p	
[sw1-Vlanif10]ip po	
[sw1-Vlanif10]q
[sw1]ip po	
[sw1]ip poo	
[sw1]ip pool dh	
[sw1]ip pool dhcp2
Info:It's successful to create an IP address pool.
[sw1-ip-pool-dhcp2]net	
[sw1-ip-pool-dhcp2]network 192.168.20.0 ma	
[sw1-ip-pool-dhcp2]network 192.168.20.0 mask 24
[sw1-ip-pool-dhcp2]gate	
[sw1-ip-pool-dhcp2]gateway-list 192.168.20.1
[sw1-ip-pool-dhcp2]dns	
[sw1-ip-pool-dhcp2]dns-list 2.2.2.2 40.40.40.40
[sw1-ip-pool-dhcp2]le	
[sw1-ip-pool-dhcp2]lease day 9
[sw1-ip-pool-dhcp2]in	
[sw1-ip-pool-dhcp2]int vl	
[sw1-ip-pool-dhcp2]int vlan 20
[sw1-Vlanif20]ip ad	
[sw1-Vlanif20]ip address 192.168.20.1 24
[sw1-Vlanif20]dh	
[sw1-Vlanif20]dhcp se	
[sw1-Vlanif20]dhcp select go	
[sw1-Vlanif20]dhcp select gl	
[sw1-Vlanif20]dhcp select global 
[sw1-Vlanif20]

Second floor sw1
[] vlan bat 10 20 create vlan 10 20
[] int e0/0/1 enter interface e0/0/1
[] port link type access sets the interface link type to access
[] port default vlan 10 divides the interface into VLAN 10
[] int e0/0/2 enter interface e0/0/2
[] port link type access sets the interface link type to access
[] port default vlan 20 divides the interface into VLAN 20
[] int g0/0/1 enter interface g0/0/1
[] port link type trunk set the interface link type to trunk
[] port trunk allow pass VLAN all set white list
Second floor sw2
[] vlan bat 10 20 create vlan 10 20
[] int e0/0/1 enter interface e0/0/1
[] port link type access sets the interface link type to access
[] port default vlan 10 divides the interface into VLAN 10
[] int e0/0/2 enter interface e0/0/2
[] port link type access sets the interface link type to access
[] port default vlan 20 divides the interface into VLAN 20
[] int g0/0/1 enter interface g0/0/1
[] port link type trunk set the interface link type to trunk
[] port trunk allow pass VLAN all set white list
Third floor sw3
[] int g0/0/1 enter interface g0/0/1
[] port link type trunk set the interface link type to trunk
[] port trunk allow pass VLAN all set white list
[] int g0/0/2 enter interface g0/0/2
[] port link type trunk set the interface link type to trunk
[] port trunk allow pass VLAN all set white list
[] vlan bat 10 20 create vlan 10 20
[] dhcp enable enables the DHCP function
[] int vlan 10 enters vlanif10
[ ]ip add 192.168. 10.1 set the length of the IP subnet mask to 24
[] dhcp select interface distributes IP addresses
[ ]dhcp server dns-list 2.2.2.2 3.3.3.3 issue DNS server address
[] ip pool dhcp2 create a new DHCP address pool with the name DHCP2
[ ]network 192.168.20.0 mask 24 specifies the network segment distributed by DHCP2 address pool
[ ]gateway-list 192.168.20.1 specify the gateway address obtained by the DHCP client
[ ]dns-list 4.4.4.4 5.5.5.5 specify the DNS server address obtained by the DHCP client
[] lease day 9 specifies the address lease period that DHCP clients can use
[] int vlan 20 enters vlanif20
[ ]ip add 192.168. 20.1 set the IP, and the length of subnet mask is 24
[] dhcp select global specifies that DHCP allocates IP addresses in the form of address pool
All four PC s obtain IP through DHCP
PC1: ipconfig authentication get IP
PC2: ipconfig authentication get IP
PC3: ipconfig authentication get IP
PC4: ipconfig authentication get IP

5.2 different network segments - DHCP relay

 

Second floor sw1
[] vlan bat 10 20 create vlan 10 20
[] int e0/0/1 enter interface e0/0/1
[] port link type access sets the interface link type to access
[] port default vlan 10 divides the interface into VLAN 10
[] int e0/0/2 enter interface e0/0/2
[] port link type access link type is set to access
[] port default vlan 20 is divided into VLAN 20
[] int g0/0/1 enter interface g0/0/1
[] port link type trunk link type is set to trunk
[] port trunk allow pass VLAN all set white list
Second floor sw2
[] vlan bat 10 20 create vlan 10 20
[] int e0/0/1 enter interface e0/0/1
[] port link type access link type is set to access
[] port default vlan 10 is divided into VLAN 10
[] int e0/0/2 enter interface e0/0/2
[] port link type access link type is set to access
[] port default vlan 20 is divided into VLAN 20
[] int g0/0/1 enter interface g0/0/1
[] port link type trunk link type is set to trunk
[] port trunk allow pass VLAN all set white list
Layer 3 sw3 relay
[] dhcp enable enables the DHCP function
[] int g0/0/1 enter interface g0/0/1
[] port link type trunk link type is set to trunk
[] port trunk allow pass VLAN all set white list
[] int g0/0/2 enter interface g0/0/2
[] port link type trunk link type is set to trunk
[] port trunk allow pass VLAN all set white list
[] vlan bat 10 20 100 create vlan 10 20 100
[] int vlan 10 enters vlanif10
[ ]ip add 192.168. 10.1.24 set IP address and mask length
[] dhcp select relay enable DHCP relay
[ ]dhcp relay server-ip 10.10.10.2 specify DHCP server address
[] int vlan 20 enters vlanif10
[ ]ip add 192.168.20.1 24 setting IP address and mask length
[] dhcp select relay enable DHCP relay
[ ]dhcp relay server-ip 10.10.10.2 specify DHCP server address
[] int g0/0/3 enter interface g0/0/3
[] port link type access set the link type to access
[] port default vlan 100 divides the interface into VLAN 10
[] int vlan 100 enters vlanif100
[ ]ip add 10.10. 10.1.24 set IP address and mask length
Router R1
[] dhcp enable enables the DHCP function
[] int g0/0/0 enter interface g0/0/0
[ ]ip add 10.10. 10.2.24 setting IP address and mask length
[] dhcp select global distributes IP addresses by selecting an address pool
[ ]ip route-static 192.168.10.0 24 10.10.10.1 set static routing destination network segment 192.168 10.0 the length of subnet mask is 24, and the next hop in interface is IP10 10.10. one
[ ]ip route-static 192.168.20.0 24 10.10.10.1 set static routing destination network segment 192.168 20.0 the length of subnet mask is 24, and the next hop in interface is IP10 10.10. one
[] ip pool dhcp1 create a new DHCP address pool with the name DHCP1
[ ]network 192.168.10.0 mask 24 specifies the network segment distributed by DHCP1 address pool
[ ]gateway-list 192.168.10.1 specify the gateway address obtained by the DHCP client
[ ]dns-list 2.2.2.2 4.4.4.4 specify the DNS server address obtained by the DHCP client
[] lease day 9 specifies the address lease period that DHCP clients can use
[] q return to the previous level
[] ip pool dhcp2 create a new DHCP address pool with the name DHCP2
[ ]network 192.168.20.0 mask 24 specifies the network segment distributed by DHCP2 address pool
[ ]gateway-list 192.168.20.1 specify the gateway address obtained by the DHCP client
[ ]dns-list 8.8.8.8 40.40.40.40 specify the DNS server address obtained by the DHCP client
[] lease day 9 specifies the address lease period that DHCP clients can use
All four PC s obtain IP through DHCP
PC1: ipconfig authentication get IP
PC2: ipconfig authentication get IP
PC3: ipconfig authentication get IP
PC4: ipconfig authentication get IP

summary

DHCP is a dynamic host configuration protocol that distributes IP address, subnet mask, gateway, DNS server, lease term and other parameters to clients

There are two situations for DHCP implementation: DHCO server and client are in the same network segment, and DHCP client and server are in different network segments

 

Topics: udp