Principle overview
As the scale of the network expands and the complexity of the network increases, changes in the location of computers (such as carrying laptops) and the number of computers exceeding the assignable IP addresses will often occur. DHCP (Dynamic Host Configuration Protocol) was developed to meet these needs. The DHCP protocol works in the client/server mode. The DHCP Client dynamically requests configuration information from the DHCP Server, and the DHCP Server returns the corresponding configuration information (such as IP address) according to the policy.
You don't need to configure the IP address manually, that's it.
Work flow (a bit ugly)
In my own words, PC-1 wants to ask for an IP address with R1 (broadcast, because now PC-1 has nothing now), R1 receives the request, finds you a usable IP address, and then Look at PC-1, look at PC-1 and think it works, and answer that it’s just him, R1 says it’s okay, you can use it, end.
Topology
Configure IP
Experimental steps
Configure IP, the switch is a Layer 2 device, no need to configure IP
[R1]int g 0/0/0
[R1-GigabitEthernet0/0/0]ip address 192.168.1.254 24
[R1]int g 0/0/1
[R1-GigabitEthernet0/0/1]ip add 192.168.2.254 24
[R1-GigabitEthernet0/0/1]quit
Enable DHCP function on R1
[R1]dhcp enable
Configure the dhcp select interface command on the GE 0/0/0 and GE0/0/1 interfaces of R1 to enable the DHCP service function of the interface and assign addresses from the interface address pool.
[R1]int g 0/0/0
[R1-GigabitEthernet0/0/0]dhcp select interface
[R1-GigabitEthernet0/0/0]quit
[R1]int g 0/0/1
[R1-GigabitEthernet0/0/1]dhcp select interface
[R1-GigabitEthernet0/0/1]quit
The interface address pool can dynamically allocate IP addresses, and the range is the network segment where the IP address of the interface is located, and it is only valid under this interface. When the DHCP server receives the request message from the DHCP client, the DHCP server will use the address network segment of the interface to assign an address to the client.
Other configuration, lease period, IP not participating in the distribution, DNS
Lease period: Here, let the lease period of GE0/0/0 interface be modified to 100 days, and the default for other interfaces is 1 day.
[R1]int g 0/0/0
[R1-GigabitEthernet0/0/0]dhcp server lease day 100
Do not participate in the allocation of IP: Here let the GE0/0/0 interface 192.168.1.1 to 192.168.1.100 do not participate in the dynamic allocation, and save it for the New Year.
[R1-GigabitEthernet0/0/0]dhcp server excluded-ip-address 192.168.1.1 192.168.1.1
00
DNS server: here is the automatic configuration DNS server 8.8.8.8 under GE 0/0/0
[R1]int g 0/0/0
[R1-GigabitEthernet0/0/0]dhcp server dns-list 8.8.8.8
Validation results
Remember to apply
PC>ipconfig
Link local IPv6 address...........: fe80::5689:98ff:feb6:76b6
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.1.253
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.1.254
Physical address..................: 54-89-98-B6-76-B6
DNS server........................: 8.8.8.8
no problem