DHCP service configuration for Linux

Posted by Chris_Evans on Tue, 28 Sep 2021 22:15:51 +0200

1, What is DHCP service

DHCP (Dynamic Host Configuration Protocol) is a LAN network protocol. It refers to a range of IP addresses controlled by the server. When the client logs in to the server, it can automatically obtain the IP address and subnet mask assigned by the server. By default, DHCP, as a service component of Windows Server, will not be automatically installed by the system. It also needs to be manually installed and configured by the administrator.

  • DHCP adopts C/S architecture, C-client, S-server and client / server architecture
  • The DHCP service corresponds to the transport layer UDP protocol. Because it is a C/S architecture, the client port number is 67 and the server port number is 68

2, Benefits and distribution of DHCP

2.1 benefits of 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

2.2. 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 IP after use for use by other clients

2, How DHCP works

  • When a DHCP client starts, the client does not have an IP address, so the client needs to obtain a legal address through DHCP; At this time, the DHCP client sends DHCPDiscover discovery information by broadcasting to find the DHCP server

  • When the DHCP server receives the information from the client requesting the IP address, it looks for whether there is a legal IP address provided to the client in its own IP address pool; If yes, the DHCP server marks this IP address, adds it to the DHCPOffer message, and then broadcasts a DHCP Offer message

  • The DHCP client extracts the IP address from the first DHCP Offer message received, and the DHCP server that sends the IP address reserves the address, so that the address cannot be assigned to another DHCP client

  • After receiving the DHCP Request message, the DHCP server broadcasts a successful confirmation to the client in the form of DHCP ACK message, which contains the valid lease of IP address and other configurable information

3, Dynamically configure host addresses using DHCP

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

2. Assignable address information

  • IP address and subnet mask of the network card
  • Corresponding network address and broadcast address
  • Default gateway address
  • DNS server address

4, DHCP configuration

4.1. Close the firewall and selinux

[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0

4.2. Install dhcp service and view configuration file

[root@localhost ~]#yum install dhcp -y
#Install dhcp service
[root@localhost ~]#rpm -qc dhcp
#View profile
[root@localhost ~]#vim /etc/dhcp/dhcpd.conf
#DHCP Server Configuration file.
#See / usr / share / Doc / DHCP * / DHCP pd.conf.example # you can copy this document
#see dhcpd.conf(5) man page

4.3 copy the file, overwrite and modify the / etc / DHCP / dhcp.conf configuration file

cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

4.4 change the NAT mode of the network card to the host only mode

4.5. Modify the network card configuration and restart the network service

[ root@localhost Dhcp]# VIM / etc / sysconfig / network scripts / ifcfg-ens33 modify IP address and gateway

[ root@localhost dhcp]# systemctl restart network

4.6. Modify configuration file

[root@localhost dhcp]#vim dhcpd.conf
#Modify profile
#Line 8 changes the default global dns address
8 option domain-name-servers;(Line 8 modifies the default global dns (address)
27 subnet netmask {  Declare the network segment to be allocated
28   range; Be sure to use a semicolon  
29   option routers;Be sure to use a semicolon    
30   option domain-name-servers; DNS
31 } 
[root@localhost ~]# systemctl start dhcpd start service

4.7 verification area and global priority

Operate in Win10

5, DHCP relay configuration

5.1. eSPN topology

5.2 ECS settings

5.3. Configure layer-2 switch SW1

<Huawei>undo terminal monitor 
[Huawei]sysname SW1
[SW1]user-interface console 0
[SW1-ui-console0]idle-timeout 0 0
[SW1]vlan bat 10 20 100
[SW1]int e0/0/2
[SW1-Ethernet0/0/2]port link-type access 
[SW1-Ethernet0/0/2]port default vlan 10
[SW1-Ethernet0/0/2]int e0/0/3
[SW1-Ethernet0/0/3]port link-type access 
[SW1-Ethernet0/0/3]port default vlan 20
[SW1-Ethernet0/0/3]int e0/0/4
[SW1-Ethernet0/0/4]port link-type access 
[SW1-Ethernet0/0/4]port default vlan 100
[SW1-Ethernet0/0/4]int e0/0/1
[SW1-Ethernet0/0/1]port link-type trunk 
[SW1-Ethernet0/0/1]port trunk allow-pass vlan all

5.4 configure layer 3 switch LSW1

<Huawei>undo terminal monitor 
Info: Current terminal monitor is off.
[Huawei]sysname LSW1
[LSW1]user-interface console 0
[LSW1-ui-console0]idle-timeout 0 0
[LSW1]int g0/0/1
[LSW1-GigabitEthernet0/0/1]port link-type trunk
[LSW1-GigabitEthernet0/0/1]port trunk allow-pass vlan all
[LSW1]dhcp enable 
[LSW1]vlan batch 10 20 100
[LSW1]int vlan 10
[LSW1-Vlanif10]ip add 24
[LSW1-Vlanif10]dhcp select relay 
[LSW1-Vlanif10]dhcp relay server-ip
[LSW1]int vlan 20
[LSW1-Vlanif20]ip add 24
[LSW1-Vlanif20]dhcp select relay 
[LSW1-Vlanif20]dhcp relay server-ip
[LSW1]int vlan 100
[LSW1-Vlanif100]ip add 24
[LSW1-Vlanif100]dhcp select relay 
[LSW1-Vlanif100]dhcp relay server-ip

5.5 test

Topics: Linux udp