问题描述

部署完vsftpd后使用虚拟用户登入成功后查看目录提示425 Security: Bad IP connecting.,报错内容如下:

[root@host-172-17-2-118 ~]# ftp 172.17.2.118
Connected to 172.17.2.118 (172.17.2.118).
220 (vsFTPd 3.0.2)
Name (172.17.2.118:root): admin
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,1,22,39,115).
425 Security: Bad IP connecting.

排查思路

既然能登入ftp,说明网络连接和用户应该没有问题

  1. 查看vsftpd.conf 配置中的目录是否存在,用户属主是否正确。
  2. 使用ftp 127.0.0.1登入尝试是否能获取目录信息。

定位问题

尝试使用ftp 127.0.0.1登入ftp后使用dir发现是能获取到目录和文件信息的,所以判断还是网络层面出了问题,检查端口和防火墙后发现问题原因可能没那么简单;通过查询各类资料,在一篇阿里云的文章中找到了答案:https://developer.aliyun.com/article/601945
大概的意思是因为我们的服务器是运行在OpenStack上,访问服务器的IP都经过了NAT(类似于阿里云的专有网络),在被动模式下客户端获取到的是实例的私网IP,导致无法进行通信(具体原因可查看上述文章)。

解决步骤

编辑vsftpd.conf关闭IPv6,并指定服务器外网访问地址(我这里是OpenStack,所以指定实例的弹性IP)

listen=YES
listen_ipv6=NO
pasv_address=172.17.2.118
  • 其中pasv_address需要指定弹性公网IP。

验证

[root@host-172-17-2-118 vsftpd]# ftp 172.17.2.118
Connected to 172.17.2.118 (172.17.2.118).
220 (vsFTPd 3.0.2)
Name (172.17.2.118:root): admin
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 (172,17,2,118,39,98).
150 Here comes the directory listing.
drwxrwxrwx    2 1004     0            8192 Apr 02  2021 089
226 Directory send OK.