The principle and configuration method of DHCP and FTP in Linux network

DHCP service

Understand DHCP service

DHCP (Dynamic Host Configuration Protocol, dynamic host configuration protocol)
is designed and developed by the Internet Task Force. It
is a protocol specifically used to self-distribute ТСР/IP parameters for computers in a TCP/IP network.

Benefits of using DHCP

Reduce the workload of the administrator,
avoid the possibility of input errors, and
avoid IP address conflicts.
When changing the IP address segment, there is no need to reconfigure the IP address
of each user. Improve the utilization of the IP address.
Facilitate the configuration of the client.

DHCP allocation method

Automatic allocation: the client is assigned an IP address from the DHCP server for permanent use.
Manual allocation: the DHCP server administrator specifically assigns the IP address.
Dynamic allocation: the client releases the IP after use for other clients.

DHCP lease process

The process by which the client obtains an IP address from the DHCP server is called the DHCP lease process

Divided into four steps

1. Search for the DHCP server
2. DHCP parameter provision
3. DHCP parameter selection
4. DHCP service confirmation

Client requests IP address

When a DHCP client is started, the client does not yet have an IP address, so the client must obtain a legal address through DHCP.
At this time, the DHCP client broadcasts the DHCP Discover information to find the DHCP server

Server response

When the DHCP server receives the information requesting the IP address from the client, it searches its own IP address pool to find out whether there is a legal IP address provided to the client.
If so, the DHCP server will mark the IP address, add it to the DHCP Offer message, and then broadcast a DHCP Offer message

Client chooses IP address

The DHCP client extracts the IP address from the first DHCP Offer message it receives, and the DHCP server that issued the IP address reserves the address so that the address can no longer be assigned to another DHCP client.

The server determines the lease

After receiving the DHCP Request message, the DHCP server broadcasts a successful confirmation to the client in the form of a DHCP ACK message, which contains a valid lease of the IP address and other configurable information.
When the client receives the DHCP ACK message, configure the IP address , Complete the initialization of TCP/IP

re-register

Each time the DHCP client logs on to the network again, it does not need to send DHCP Discover information, but directly sends the DHCP Request request information containing the IP address assigned the previous time.

Renew lease

When the lease period of the IP address leased by the DHCP server to the client reaches 50%, the lease must be renewed. The
client directly sends a DHCP Request packet to the server that provides the lease, requesting to renew the existing address lease.

The address information that can be allocated mainly includes

Network card's IP address, subnet mask,
corresponding network address, broadcast address,
default gateway address,
DNS server address

Install DHCP server

Configuration in ensp

dhcp enable									#开启DHCP功能

interface Vlanif10
 ip address 192.168.1.254 255.255.255.0
 dhcp select relay							#开启DHCP中继功能
 dhcp relay server-ip 192.168.100.20			#指向DHCP服务器的地址

interface Vlanif20
 ip address 192.168.2.254 255.255.255.0
 dhcp select relay
 dhcp relay server-ip 192.168.100.20

interface Vlanif100
 ip address 192.168.80.254 255.255.255.0
 dhcp select relay
 dhcp relay server-ip 192.168.100.20

Configure DHCP server

DHCP server software


The main file of the DHCP software package dhcp-4.2.5-58.el7.centos.x86_64.rpm in the CentOS 7 CD-ROM
Main configuration file: /etc//dhcp/dhcpd.conf
Executive program: /usr/sbin/dhcpd, / usr/sbin/dhcrelay

Configure DHCP server

yum install -y dhcp

cd /etc/dhcp/
ls
less dhcpd.conf

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
#设置全局配置参数
default-lease-time 600; 									#默认租约为 10 分钟,单位为秒
max-lease-time 7200; 										#最大租约为 2 小时,单位为秒
option domain-name "benet.com"; 							#指定默认域名
option domain-name-servers 202.106.0.20, 202.106.148.1; 	#指定 DNS 服务器地址
ddns-update-style none; 									#禁用 DNS 动态更新

#subnet网段声明(作用于整个子网段,部分配置参数优先级高于全局配置参数)
subnet 192.168.80.0 netmask 255.255.255.0 {
    
    			        #声明要分配的网段地址
  range 192.168.80.10 192.168.80.20;				        #设置地址池
  option routers 192.168.80.254;					        #指定默认网关地址
}

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;
}

#后面内容可都删除

systemctl start dhcpd
systemctl stop firewalld
setenforce 0

netstat -anpu | grep ":67"

#如果DHCP服务启动失败,可以查看日志文件
tail -f /var/log/messages

Linux client uses DHCP to dynamically obtain IP

#方法一:
vim /etc/sysconfig/network-scripts/ifcfg-ens33
DEVICE=ens33
ONBOOT=yes
BOOTPROTO=dhcp

ifdown ens33 ; ifup ens33

#方法二:
dhclient -d ens33

查看租约文件 
less /var/lib/dhcpd/dhcpd.lease

DHCP experiment

Insert picture description here

Claim

PC1 and PC2 can obtain IP addresses through DHCP relay LSW2 and Linux server Cloud1

Change the network adapter mode in the virtual machine settings

Insert picture description here
Insert picture description here

Change the network card and gateway of the virtual machine

Insert picture description here
Insert picture description here

Switch SW2 and Layer 3 switch SW1 configuration

Insert picture description here
Insert picture description here

Open relay

Insert picture description here

View connected type

Insert picture description here

Install DHCP

Insert picture description here

Copy the configuration file template and configure

Insert picture description here
Insert picture description here

Open dhcp service

Insert picture description here
Insert picture description here

Turn on the DHCP of PC1 and PC2

View Results

It is found that both PC1 and PC2 have been assigned an IP address, and both are within the set range
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/m0_53497201/article/details/114243051
Recommended