Analysis of Linux Principles and Configuration of DHCP and FTP in Linux

DHCP allocation method

Use DHCP service to assign addresses
  • Automatically allocate addresses for a large number of clients and provide centralized management
  • Reduce management and maintenance costs and improve network configuration efficiency
The address information that can be allocated mainly includes
  • The IP address and subnet mask of the network card
  • Corresponding network address, broadcast address
  • Default gateway address
  • DNS server address
Three distribution methods
  • Automatic allocation: the client is permanently used after being allocated an IP address from the DHCP server
  • Manual allocation: the IP address is specified by the DHCP server administrator
  • Dynamic allocation: release the IP after the client is used up, for other clients to use

Install DHCP server

Configure DHCP relay 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.100.254 255.255.255.0
dhcp select relay
dhcp relay server-ip 192.168.100.20
Configure DHCP server


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

yum install -y dhcp
cat /etc/dhcp/dhcpd.conf    #查看主配置文件
cat /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example  #查看示例配置文件
Configure the content of the main configuration file
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;	 #最大租约为 1 小时,单位为秒
option domain-name "example.org";  #指定默认域名
option domain-name-servers 8.8.8.8; #指定 DNS 服务器地址
ddns-update-style none;  #禁用 DNS 动态更新

#subnet网段声明(作用于整个子网段,部分配置参数优先级高于全局配置参数)
subnet 192.168.100.0 netmask 255.255.255.0 {    	#声明要分配的网段地址
   range 192.168.100.1 192.168.100.128;     #设置地址池
   option routers 192.168.100.254;      #指定默认网关地址
}
subnet 192.168.1.0 netmask 255.255.255.0 {
   range 192.168.1.1 192.168.1.128;
   option routers 192.168.100.254;
}
subnet 192.168.2.0 netmask 255.255.255.0 {
    range 192.168.2.1 192.168.2.128;
    option routers 192.168.100.254;
}

#host主机声明(给单机分配固定的 IP 地址)
host hostname {										#指定需要分配固定 IP地址的客户机名称
  hardware ethernet 00:c0:c3:22:46:81;				#指定该主机的 MAC地址
  fixed-address 192.168.10.100;						#指定保留给该主机的 IP地址
}

#后面内容可都删除

#关上防火墙
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
operating

Insert picture description here

Insert picture description here

Insert picture description here

Layer 2 switch configuration
Insert picture description here

Configuration of dhcp relay in ensp
Insert picture description here

Insert picture description here

Configure the network card and reload the network card configuration
Insert picture description here

Insert picture description here

Install dhcp, view and copy configuration files
Insert picture description here

Insert picture description here
Edit the main configuration file
Insert picture description here
Insert picture description here

Turn off the firewall and check if dhcp is on

Insert picture description here

Insert picture description here
Test in ensp
Insert picture description here

Insert picture description here

FTP file transfer experiment

  • FTP service-the protocol used to transfer files
  • The FTP server uses TCP protocol 20 and 21 ports to communicate with the client by default. Port
    20 is used to establish data connections and transfer file data.
    Port 21 is used to establish control connections and transmit FTP control commands.
  • FTP data connection is divided into active mode and passive mode.
    Active mode: the server actively initiates the data connection.
    Passive mode: the server passively waits for the data connection.
Install the package
yum install -y vsftpd
cd /etc/vsftpd/
cp vsftpd.conf vsftpd.conf.bak

Insert picture description here
Insert picture description here

Set up the FTP service accessed by anonymous users (maximum permissions)
#修改配置文件
vim /etc/vsftpd/vsftpd.conf
anonymous_enable=YES            #开启匿名用户访问。默认已开启
write_enable=YES                #开放服务器的写权限(若要上传,必须开启)。默认已开启
anon_umask=022                  #设置匿名用户所上传数据的权限掩码(反掩码)。默认已开启
anon_upload_enable=YES          #允许匿名用户上传文件。默认已注释,需取消注释
anon_mkdir_write_enable=YES     #允许匿名用户创建(上传)目录。默认已注释,需取消注释
anon_other_write_enable =YES    #允许删除、重命名、覆盖等操作。需添加

#为匿名访问ftp的根目录下的 pub子目录设置最大权限,以便匿名用户上传数据
chmod 777 /var/ftp/pub/

#开启服务,关闭防火墙和增强型安全功能
systemctl start vsftpd
systemctl stop firewalld
setenforce 0

Insert picture description here

Insert picture description here

Insert picture description here

Anonymous access test
在Windows系统打开 开始 菜单,输入 cmd 命令打开命令提示符
#建立ftp连接
ftp 192.168.249.10
#匿名访问,用户名为ftp,密码为空,直接回车即可完成登录
ftp> pwd			#匿名访问ftp的根目录为Linux系统的/var/ftp/目录
ftp> ls				#查看当前目录
ftp> cd pub			#切换到pub 目录
ftp> get 文件名		#下载文件到当前Windows本地目录
ftp> put 文件名		#上传文件到ftp目录
ftp> quit			#退出

Insert picture description here
Insert picture description here

Insert picture description here

Set local user authentication to access ftp, and prohibit switching to directories other than ftp (the root directory of the default login is the home directory of the local user)
#修改配置文件
vim /etc/vsftpd/vsftpd.conf
local_enable=Yes        		 #启用本地用户
anonymous_enable=NO     		 #关闭匿名用户访问
write_enable=YES        		 #开放服务器的写权限(若要上传,必须开启)
anon_umask=077          		 #可设置仅宿主用户拥有被上传的文件的权限(反掩码)
chroot_local_user=YES   		 #将访问禁锢在用户的宿主目录中
allow_writeable_chroot=YES		 #允许被限制的用户主目录具有写权限

重启服务
systemctl restart vsftpd


修改匿名用户、本地用户登录的默认根目录(这个在配置文件里填上即可)
anon_root=/var/www/html			#anon_root 针对匿名用户
local_root=/var/www/html		#local_root 针对系统用户

Insert picture description here

Insert picture description here
The access is restricted to the user's home directory, and the restricted user's home directory is allowed to have write permissions.
Insert picture description here
Restart the service
Insert picture description here

For operations under win10, users are restricted and are not allowed to access directories other than the host's home directory

Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/shengmodizu/article/details/113950654