
- 一、检查防火墙策略
- 关闭防火墙 *** 作如下:
- 防火墙放行端口 *** 作如下:
- 二、安装ftp
- 三、启动ftp服务端并修改配置文件
- 四、使用ftp进行下载和上传测试
注意事项:
搭建ftp服务器,一定要注意防火墙策略和selinux
ftp服务端和ftp客户端是两个概念,ftp客户端可以访问ftp服务端,反之不行,若两边都安装ftp服务端和ftp客户端软件即可双向访问。
ftp走21和22端口,很多时候都是因为防火墙策略问题倒置不能正常使用,所以先进行防火墙检查,关闭防火墙或者在开启的的防火墙中放行21,22端口(防火墙一般默认放行22端口)
关闭防火墙 *** 作如下:linux6: 防火墙状态: service iptables status 关闭防火墙: service iptables stop 禁用防火墙: chkconfig iptables off linux7: 防火墙状态: systemctl status firewalld.service 关闭防火墙: systemctl stop firewalld.service 禁用防火墙: systemctl disable firewalld.service防火墙放行端口 *** 作如下:
1、防火墙放行21端口: iptables -I INPUT 5 -p tcp --dport 21 -j ACCEPT #要先启动ftp服务,然后在防火墙中放行端口,在重启防火墙 2、查看21端口状态: netstat -na --ip|grep 21 #这时候可能还看不见,因为ftp服务没有启动 3、防火墙添加ftp模块: vi /etc/sysconfig/iptables-config 添加以下内容: IPTABLES_MODULES="ip_nat_ftp ip_conntrack_ftp" 4、重启防火墙: linux6: service iptables restart linux7: firewall-cmd --reload 5、查看防火墙端口规则 iptables -nL --line-number
客户端可以使用nc命令测试fpt服务器端口
nc -v 192.168.27.10 21二、安装ftp
1、检查ftp服务是否安装
rpm -qa|grep ftp
2、在服务端安装软件vsftp(已经配置了本地yum源)
yum install -y vsftpd.x86_64
3、在客户端安装软件ftp(已经配置了本地yum源)
yum install -y ftp三、启动ftp服务端并修改配置文件
1、服务端启动vsftp
linux6: service vsftpd start linux7: systemctl start vsftp.service
2、修改配置文件:
使用普通用户连接fpt服务器只能上传不能下载,需要修改下面参数才能连接ftp服务器进行下载
注:selinux在关闭状态下不能修改该参数,需要将selinux启动后才能修改
selinux开启关闭请参考:点击这里
# setsebool -P ftpd_use_fusefs on # sestatus -b | grep ftp allow_ftpd_anon_write off allow_ftpd_full_access off allow_ftpd_use_cifs off allow_ftpd_use_nfs off ftp_home_dir on ftpd_connect_db off ftpd_use_fusefs off ftpd_use_passive_mode off httpd_enable_ftp_server off tftp_anon_write off tftp_use_cifs off tftp_use_nfs off
特别注意:默认ftp服务器是不允许root用户直接访问的,也强烈不建议这么做,若有特殊要求必须使用root用户访问ftp服务器,
修改服务器端配置文件 vi /etc/vsftpd/ftpusers 注释root vi /etc/vsftpd/user_list 注释root service vsftpd restart
四、使用ftp进行下载和上传测试selinux在启动状态下是不允许root用户直接登录ftp服务端,需将selinux关闭即可
上传测试:
# ftp 192.168.27.10 Connected to 192.168.27.10 (192.168.27.10). 220 (vsFTPd 2.2.2) Name (192.168.27.10:root): root 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> put test.txt local: shuaige remote: shuaige 227 Entering Passive Mode (192,168,27,10,42,185). 150 Ok to send data. 226 Transfer complete. ftp>
下载测试:
# ftp 192.168.27.10 Connected to 192.168.27.10 (192.168.27.10). 220 (vsFTPd 2.2.2) Name (192.168.27.10:root): root 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> dir 227 Entering Passive Mode (192,168,27,10,78,212). 150 Here comes the directory listing. -rw-r--r-- 1 1100 1100 0 Nov 06 08:09 lihua 226 Directory send OK. ftp> get lihua local: lihua remote: lihua 227 Entering Passive Mode (192,168,27,10,75,193). 150 Opening BINARY mode data connection for lihua (0 bytes). 226 Transfer complete. ftp>
上传多个文件:mput
下载多个文件:mget
关闭交互模式:prompt
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)