preface
- DHCP (Dynamic Host Configuration Protocol) is a protocol designed by IETF to realize automatic IP configuration. It can automatically assign TCP/IP parameters such as IP address, subnet mask, IP address of default gateway and DNS server for clients
1: Experimental environment
1.1: basic principles
-
Step 1: the client sends DHCP Discover message through broadcast to find the server
-
Step 2: the server sends DHCP Offer message through unicast to provide IP address and other network information to the client
-
Step 3: the client will broadcast the DHCP Request message to tell the server which IP address to choose locally
-
Step 4: the server informs the client that the IP address is legal and available through the DHCP Ack message
1.2: principle summary
- In the actual production environment, the second and fourth steps are basically unicast
- In the Microsoft system, the four basic principles are broadcast
1.3: experimental software
- eNSP
- One switch
- Two routers
- Five hosts
1.4: purpose of the experiment
- Automatically assign IP address through router DHCP
- Realize the interconnection between hosts of different VLANs
1.5: Huawei DHCP experiment topology
2: Experimental process
2.1: switch settings
<Huawei>system-view [Huawei]sysname SW1 [SW1]vlan bat 10 20 '//Continuously add vlan ' [SW1]interface Ethernet 0/0/1 '//Enter interface ' [SW1-Ethernet0/0/1]port link-type access '//Set interface mode ' [SW1-Ethernet0/0/1]port default vlan 10 '//Partition vlan ' [SW1-Ethernet0/0/1]undo shutdown [SW1-Ethernet0/0/1]interface Ethernet 0/0/2 [SW1-Ethernet0/0/2]port link-type access [SW1-Ethernet0/0/2]port default vlan 20 [SW1-Ethernet0/0/2]undo shutdown [SW1-Ethernet0/0/2]interface Ethernet 0/0/3 [SW1-Ethernet0/0/3]port link-type access [SW1-Ethernet0/0/3]port default vlan 10 [SW1-Ethernet0/0/3]undo shutdown [SW1-Ethernet0/0/3]interface Ethernet 0/0/4 [SW1-Ethernet0/0/4]port link-type access [SW1-Ethernet0/0/4]port default vlan 20 [SW1-Ethernet0/0/4]undo shutdown [SW1-Ethernet0/0/4]quit [SW1]interface GigabitEthernet 0/0/1 '//Enter interface ' [SW1-GigabitEthernet0/0/1]port link-type trunk '//Set interface mode ' [SW1-GigabitEthernet0/0/1]port trunk allow-pass vlan all '//Set the allowed vlan ' [SW1-GigabitEthernet0/0/1]undo shutdown
2.2: router (R1) settings
<Huawei>system-view [Huawei]sysname R1 [R1]dhcp enable [R1]interface GigabitEthernet 0/0/1.1 '//Enter interface ' [R1-GigabitEthernet0/0/1.1]dot1q termination vid 10 '//Select package type and set vlan attribution ' [R1-GigabitEthernet0/0/1.1]ip address 192.168.10.1 24 [R1-GigabitEthernet0/0/1.1]arp broadcast enable '//Turn on arp broadcast ' [R1-GigabitEthernet0/0/1.1]dhcp select interface '//Set DHCP based on interface [R1-GigabitEthernet0/0/1.1]dhcp server dns-list 3.3.3.3 '//Set dns address' [R1-GigabitEthernet0/0/1.1]undo shutdown [R1-GigabitEthernet0/0/1.1]interface GigabitEthernet 0/0/1.2 [R1-GigabitEthernet0/0/1.2]dot1q termination vid 20 [R1-GigabitEthernet0/0/1.2]ip address 192.168.20.1 24 [R1-GigabitEthernet0/0/1.2]arp broadcast enable [R1-GigabitEthernet0/0/1.2]dhcp select interface [R1-GigabitEthernet0/0/1.2]dhcp server dns-list 2.2.2.2 [R1-GigabitEthernet0/0/1.2]undo shutdown [R1-GigabitEthernet0/0/1.2]q [R1]interface GigabitEthernet 0/0/0 [R1-GigabitEthernet0/0/0]ip add 12.0.0.1 24 [R1-GigabitEthernet0/0/0]undo shutdown [R1]ip route-static 15.0.0.0 24 12.0.0.2 '//Add static route '
2.3: router (R2) settings
<Huawei>system-view [Huawei]sysname R2 [R2]dhcp enable [R2]interface GigabitEthernet0/0/0 [R2-GigabitEthernet0/0/0]ip add 12.0.0.2 24 [R2-GigabitEthernet0/0/0]undo shutdown [R2-GigabitEthernet0/0/0]interface GigabitEthernet0/0/1 [R2-GigabitEthernet0/0/1]ip add 15.0.0.1 24 [R2-GigabitEthernet0/0/1]undo shutdown [R2-GigabitEthernet0/0/1]quit [R2]ip route-static 192.168.10.0 24 12.0.0.1 '//Add static route ' [R2]ip route-static 192.168.20.0 24 12.0.0.1 [R2]ip pool v11 '//Enter ip address pool ' [R2-ip-pool-v11]gateway-list 15.0.0.1 '//Set gateway ' [R2-ip-pool-v11]network 15.0.0.0 mask 24 '//Set network number and subnet mask ' [R2-ip-pool-v11]dns-list 1.1.1.1 '//Set dns address' [R2-ip-pool-v11]quit [R2]interface GigabitEthernet0/0/1 [R2-GigabitEthernet0/0/1]dhcp select global '//Select global mode to assign DHCP '
2.4: host settings
3: Experimental verification and summary
3.1: successful experiment
3.2: experiment summary
- Static routing is recommended in production environments
- DHCP can be configured in two ways
3.2.1: the first mode: interface mode
- You can set the range where DHCP does not assign addresses
Interface mode //step1: [R1]dhcp enable '//###Enable DHCP function in global configuration mode //step2: [R1]interface GigabitEthernet0/0/0.10 '//###Enter sub interface ' [R1-GigabitEthernet0/0/0.10] dhcp select interface '//###Configure DHCP based on interface " [R1-GigabitEthernet0/0/0.10] dhcp server excluded-ip-address 192.168.10.200 192.168.10.210 '//##192.168.10.200 to 192.168.10.210 do not assign address' [R1-GigabitEthernet0/0/0.10]dhcp server dns-list 8.8.8.8 '//###Configure DNS'
3.2.1: the second method: global configuration mode
- Can assign fixed address (IP address + MAC address) to machine (IP address should be in address pool)
Global configuration mode //step1: [R1]dhcp enable '//###Enable DHCP function in global configuration mode //step2: [R1] ip pool v20 [R1-ip-pool-v20] gateway-list 192.168.20.1 [R1-ip-pool-v20] network 192.168.20.0 mask 255.255.255.0 [R1-ip-pool-v20] dns-list 114.114.114.114 [R1-ip-pool-v20] static-bind ip-address 192.168.20.9 mac-address 28d2-4469-5a55 '//####Bind IP 192.168.20.9 and assign it to the machine with MAC 28d2-4469-5a55, and IP 'in the pool is required [R1-ip-pool-v20] lease day 10 '//####Lease term 10 days' //step3: [R1]int g0/0/0.20 [R1-GigabitEthernet0/0/0.20] dhcp select global '//Select global mode to assign DHCP ' //Fixed allocation toMAC by28d2-4469-5a55 In the poolIP' [R1-ip-pool-v20] lease day 10 '//####The lease term is 10 days //step3: [R1]int g0/0/0.20 [R1-GigabitEthernet0/0/0.20] dhcp select global '//Select global mode to assign DHCP '
Reference: there is an undead city in the deep sea!