DHCP belongs to application layer protocol port 67 server 68 client UDP
How DHCP works
Understanding DHCP services
- DHCP(Dynamic Host Configuration Protocol)
- Designed and developed by lnternet task force
- A protocol designed to automatically assign TCP/IP parameters to computers in a TCP/IP network
Benefits of using DHCP
- Reduce administrator workload
- Avoid the possibility of input errors
- Avoid IP address conflicts
- When changing the lP address segment, there is no need to reconfigure the IP address of each user
- Improved IP address utilization
- Convenient client configuration
DHCP allocation method
- Automatic assignment: permanently used after being assigned to an IP address
- Manual assignment: the DHCP server administrator specifies the IP address specifically
- Dynamic allocation: release the lP after use for use by other clients
DHCP is a C/S mode. The DHCP server and client need to maintain communication. DHCP is based on UDP protocol. Both parties may initiate communication to each other, so both parties need to listen to the port
- Server side: DHCP Server (running dhcp service)
- UDP service: listening port 67 (bootps)
- CLient side: DHCP Client (running dhcp program)
- UDP service: listening port 68 (bootpc)
Typical C/S mode (Client/Server)
Set up a special DHCP server in the network, which is responsible for centrally allocating the parameters of various network addresses (mainly including IP address, subnet mask, broadcast address, default gateway and DNS server address). Other hosts, as DHCP clients, configure the network card as automatic acquisition, so as to communicate with the DHCP server and complete the automatic configuration process
DHCP lease process
The process by which a client obtains an IP address from a DHCP server is called the DHCP lease process
[the external chain picture transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-IO075o6q-1641918087681)(C:\Users\KK\Desktop \ picture \ QQ picture 20220107093710.png)]
[the external chain picture transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the picture and upload it directly (IMG erdpeguq-1641918087683) (C: \ users \ KK \ desktop \ picture \ QQ picture 20220107093736.png)]
[the external chain picture transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-8bKP3DQp-1641918087683)(C:\Users\KK\Desktop \ picture \ QQ picture 20220107093743.png)]
[the external chain picture transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-47V8eFLB-1641918087683)(C:\Users\KK\Desktop \ picture \ QQ picture 20220107093749.png)]
[the external chain picture transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the picture and upload it directly (IMG aeguoqag-1641918087684) (C: \ users \ KK \ desktop \ picture \ QQ picture 20220107093753.png)]
[the external chain picture transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-XjWwEw5w-1641918087684)(C:\Users\KK\Desktop \ picture \ QQ picture 20220107094058.png)]
[the external chain picture transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-qeW3X9Q2-1641918087684)(C:\Users\KK\Desktop \ picture \ QQ picture 20220107094145.png)]
Configuration of DHCP server
Dynamically configure host addresses using DHCP
- DHCP service
- Automatically assign addresses to a large number of clients and provide centralized management
- Reduce management and maintenance costs and improve network configuration efficiency
- The assignable address information mainly includes
- IP address and subnet mask of the network card
- Corresponding network address and broadcast address
- Default gateway address
- DNS server address
Install DHCP server
- DHCP server software
- Dhcp-4.2.5-47 in CentOS CD el7. centos. x86_ 64.rpm
- Main files of DHCP package
- Main configuration file: / etc / dhcpd conf
- Executor: / usr/sbin/dhcpd, / usr / SBIN / dhcrawley
Configure DHCP server
ls | grep dhcp #Look for a dhcp packet first yum install -y dhcp #If not, install yum by default in / etc cd /etc/dhcp/ ls less dhcpd.conf #List file information cd /usr/share/doc/dhcp-4.2.5/ ls less dhcpd.conf.example cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf vim /etc/dhcp/dhcpd.conf
#Set global configuration parameters default-lease-time 21600;#The default lease is 6 hours in seconds max-lease-time 43200;#The maximum lease is 12 hours in seconds option domain-name "benet.com" ;#Specify default domain name option domain-name-servers 202.106.0.20,202.106.148.1;#Specify DNS server address ddns-update-style none;#Disable DNS dynamic updates
#Subnet segment declaration (it applies to the whole subnet segment, and some configuration parameters have priority over the global configuration parameters) sets three network segments, which are local configuration parameters subnet 192.168.80.0 netmask 255.255.255.0{ #Declare the network segment address to be assigned range 192.168.80.10 192.168.80.20; #Set address pool option routers 192.168.80.254; #Specify the default gateway address } subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.100 192.168.1.200; option routers 192.168.1.254; } subnet 192.168.2.0 netmask 255.255.255.0 { range 192.168.2.20 192.168.2.30; option routers 192.168.2.254; } #Host host declaration (assign a fixed IP address to a single machine) host hostname { #Specify the name of the client that needs to be assigned a fixed IP address hardware ethernet oo:c0 :c3:22:46:81; #Specify the MAc address of the host fixed-address 192.16 suitable.4.100; #Specify the IP address reserved for this host
#The following contents can be deleted systemctl start dhcpd systemctl stop firewalld setenforce o netstat -anpu/ grep " :67" #If the DHCP service fails to start, you can view the log file t ail -f /var / log / messages
Use of DHCP clients
There are two ways to use DHCP client
- Modify the network card configuration file (such as ifcfg-ens33)
- BOOTPROTO=dhcp
- Using the dhclient command
dhclient [-d][Network interface name]
[root@localhost ~]# viletclsysconfig/network-scriptslifcfg-ens33DEVICE=ens33 ONBOOT=yes BOOTPROTO=dhcp [root@localhost ~]# ifdown ens33 ; ifup ens33
Use DHCP client
- Two ways of use
[root@localhost ~]# dhclient -d ens33 Listening on LPFlens33/00:0c:29:3b:ff:76 Sending on LPFlens33/00:0c:29:3b:ff:76 Sending on Socket/fallback DHCPDISCOVER on ens33 to 255.255.255.255 port 67 interval 5 #DHCP discovery (xid=Ox608095ef) DHCPREQUEST on ens33 to 255.255.255.255 port 67 (xid=Ox608095ef)#DHCP request DHCPOFFER from 192.168.4.11 DHCPACK from 192.168.4.11 (xid=Ox608095ef)#DHCP offer bound to 192.168.4.131 -- renewal in 8669 seconds.#DHCP confirmation
DHCP relay principle and configuration
DHCP relay principle
- When the internal network of an enterprise is large, it is usually divided into several different subnets. VLAN is configured in the network. VLAN can isolate broadcasting, while DHCP protocol uses broadcasting
- When the DHCP server is in VLAN 100, only clients in VLAN 100 can obtain IP addresses from it
- What if the client of VLAN 2 or VLAN 3 also needs to obtain the IP address through this DHCP server?
- A DHCP server is installed for each network segment, but this method wastes resources and is not conducive to centralized management
- Turn on the DHCP relay function on the devices connected to different network segments to forward the special broadcast information of DHCP between VLANs, so that clients of other VLANs can also obtain the IP address from the DHCP server
DHCP configuration
- Take ensp as an example
- First, add access and trunk to the layer 2 switch
- Then configure the dhcp server on the cloud
- Then start configuring DHCP relay
stay ensp Medium configuration QHCP relay dhcp enable #Enable DHCP function # interface vlanif10 ip address 192.168.1.254 255.255.255.0, dhcp select relay #Enable DHCP relay function dhcp relay server-ip 192.168.80.10 #Address to DHCP server # interface vlanif20 ip address 192.168.2.254 255.255.255.0 dhcp select relay dhcp relay server-ip 192.168.80.10 interface vlanif100 ip address 192.168.80.254255.255.255.0 dhcp select relay dhcp relay server-ip 192.168.80.10
ress 192.168.2.254 255.255.255.0
dhcp select relay
dhcp relay server-ip 192.168.80.10
interface vlanif100
ip address 192.168.80.254255.255.255.0
dhcp select relay
dhcp relay server-ip 192.168.80.10