搭建FTP服务器(主动模式和被动模式)
项目环境:
- 防火墙与SELinux开启/关闭(需/无需做权限配置)
- 局域网内,可参考该环境。
- centos7,两台(服务端/客户端)
基本环境准备
- 安装vsftpd软件
[root@chenshuyi ~]# yum install -y vsftpd
已加载插件:fastestmirror
Repository base is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.aliyun.com
软件包 vsftpd-3.0.2-28.el7.x86_64 已安装并且是最新版本
无须任何处理
- 关掉防火墙以及selinux(服务端和客户端)
[root@chenshuyi ~]# systemctl stop firewalld
[root@chenshuyi ~]# setenforce 0
- 启动vsftp,一个简单的ftp服务器就搭建好了,缺省的配置文件足以让我们在客户端访问服务器
- 以至于以下配置,仅做参考。
当你开启你的防火墙时:
- 允许该服务应用通过防火墙
[root@chenshuyi ~]# firewall-cmd --add-service=ftp --permanent
Warning: ALREADY_ENABLED: ftp
success
[root@chenshuyi ~]# firewall-cmd --reload #重启防火墙
- 设置SELinux
[root@chenshuyi ~]# setenforce 0 #先临时关闭
[root@chenshuyi ~]# setsebool -P tftp_home_dir 1
[root@chenshuyi ~]# setsebool -P tftp_anon_write 1
[root@chenshuyi ~]# setsebool -P ftpd_anon_write 1
[root@chenshuyi ~]# setsebool -P ftpd_use_passive_mode 1
[root@chenshuyi ~]# setsebool -P allow_ftpd_full_access 1
[root@chenshuyi ~]# setenforce 1 #开启
[root@chenshuyi ~]# getsebool -a | grep ftpd #查看ftpd权限
ftpd_anon_write --> on
ftpd_connect_all_unreserved --> off
ftpd_connect_db --> off
ftpd_full_access --> on
ftpd_use_cifs --> off
ftpd_use_fusefs --> off
ftpd_use_nfs --> off
ftpd_use_passive_mode --> on
[root@chenshuyi ~]# getsebool -a | grep tftp
tftp_anon_write --> on
tftp_home_dir --> on
- 目录权限
[root@chenshuyi ~]# chmod -R 777 /var/ftp/pub #FTP目录
- 仅允许局域网段访问
[root@chenshuyi var]# echo "vsftpd:1.1.1.0/24:allow" >> /etc/hosts.allow
- 好了就帮到这了,我要去干饭了,详细可见biuayi.cn这个网站的FTP篇。