如何在需要访问 FTP 和 SFTP 服务器的客户端计算机上设置防火墙规则?
客户端机器上的默认策略是拒绝所有连接(传入和传出)
有 (UFW) 规则允许:
20/tcp ALLOW OUT Anywhere # FTP Data
21/tcp ALLOW OUT Anywhere # FTP Command
22 ALLOW OUT Anywhere # SSH, SFTP
990 ALLOW OUT Anywhere # FTPS
989 ALLOW OUT Anywhere # FTPS
在客户端机器上运行良好,可以连接到 FTP/FTPS,并在那里进行身份验证,但是当 FTP 客户端请求目录树列表时,会发生错误:
错误:无法检索目录列表
连接日志:
Status: Resolving address of xxx.xxx.xxx.xxx
Status: Connecting to 1xx.1xx.2xx.1xx:21...
Status: Connection established, waiting for welcome message...
Status: Initializing TLS...
Status: Verifying certificate...
Status: TLS connection established.
Status: Logged in
Status: Retrieving directory listing...
Command: PWD
Response: 257 "/" is your current location
Command: TYPE I
Response: 200 TYPE is now 8-bit binary
Command: PASV
Response: 227 Entering Passive Mode (1xx,1xx,2xx,1xx,1xx,2xx)
Command: MLSD
Error: Connection timed out after 20 seconds of inactivity
Error: Failed to retrieve directory listing
如果防火墙关闭则没有错误,因此问题与防火墙配置有关。
需要添加什么规则(最好是 UFW 规则)才能使防火墙以默认禁止规则运行但允许 FTP 和 SFTP 连接?
答案1
在/etc/proftpd/proftpd.conf
取消标记:PassivePorts 65000 66000(选择被动端口跨度)
在ufw
开放端口范围
sudo ufw allow 65000:66000/tcp