首先安装vsftpd:
yum -y install vsftpd
启动服务:
systemctl start vsftpd.service
配置文件目录在:/etc/vsftpd/vsftpd.conf
默认情况下,他是开启匿名访问的:
安装ftp
yum -y install ftp
客户端使用主动模式:
主要命令:
ftp ip地址
passive
运行
[root@bogon ~]# ftp 192.168.65.81
Connected to 192.168.65.81 (192.168.65.81).
220 (vsFTPd 3.0.2)
Name (192.168.65.81:root): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> passive
Passive mode off.
ftp> ls
200 PORT command successful. Consider using PASV.
425 Failed to establish connection.
ftp>
服务端iptables配置
iptables -I INPUT -p tcp --dport 21 -j ACCEPT
iptables -I INPUT -p tcp --dport 22 -j ACCEPT
iptables -I INPUT -p icmp -j ACCEPT
iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -j REJECT
查看iptables链
[root@bogon ~]# iptables -nL
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:21
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@bogon ~]#
按照上面的配置方式使用客户端被动模式时出现下面的情形:
[root@bogon ~]# ftp 192.168.65.81
Connected to 192.168.65.81 (192.168.65.81).
220 (vsFTPd 3.0.2)
Name (192.168.65.81:root): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
ftp>
ftp> ls
227 Entering Passive Mode (192,168,65,81,69,202).
ftp: connect: 拒绝连接
ftp>
方法一:为vsftp指定数据端口,并通过iptables开放相应需要传输的端口段
vim /etc/vsftpd/vsftpd.conf
配置iptables
iptables -I INPUT -p tcp --dport 50000:60000 -j ACCEPT
就可以了:
[root@localhost ~]# ftp 192.168.201.81
Connected to 192.168.201.81 (192.168.201.81).
220 (vsFTPd 3.0.2)
Name (192.168.201.81:root): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,201,81,223,165).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 6 Jun 09 2021 pub
226 Directory send OK.
ftp>
方法二:使用连接追踪模块。
iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#临时
modprobe nf_conntrack_ftp
#开机自启
vim /etc/sysconfig/iptables-config
IPTABLES_MODULES="nf_conntrack_ftp"
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://it1995.blog.csdn.net/article/details/123837184
内容来源于网络,如有侵权,请联系作者删除!