在Linux中为FTPServer设置防火墙规则,通常涉及使用iptables或firewalld这样的工具。以下是使用这两种工具设置防火墙规则的步骤:
iptables允许FTP数据连接: FTP使用两个端口:一个是控制连接(通常是21端口),另一个是数据连接(通常是20端口,但也可以是动态分配的端口)。
sudo iptables -A INPUT -p tcp --dport 21 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 20 -j ACCEPT
允许被动模式数据连接: 被动模式FTP使用动态端口范围(通常是49152到65535)。你需要允许这些端口的入站连接。
sudo iptables -A INPUT -p tcp --dport 49152:65535 -j ACCEPT
保存规则:
iptables规则在重启后会丢失,所以需要保存规则。
sudo iptables-save > /etc/iptables/rules.v4
firewalld启用FTP服务:
firewalld提供了更直观的方式来管理防火墙规则。
sudo firewall-cmd --permanent --add-service=ftp
sudo firewall-cmd --permanent --add-port=21/tcp
sudo firewall-cmd --permanent --add-port=20/tcp
sudo firewall-cmd --permanent --add-port=49152-65535/tcp
重新加载防火墙配置: 使更改生效。
sudo firewall-cmd --reload
通过以上步骤,你应该能够在Linux系统中为FTPServer设置基本的防火墙规则。