在linux系统中设置ftp服务器的防火墙通常需要使用如iptables或firewalld等工具。以下是使用这些工具的详细步骤:
使用iptables设置防火墙
- 检查现有的iptables规则:
sudo iptables -L -n -v
- 清除现有的iptables规则:
sudo iptables -F sudo iptables -X
- 设置默认策略:
sudo iptables -P INPUT DROP sudo iptables -P FORWARD DROP sudo iptables -P OUTPUT ACCEPT
- 允许FTP端口的数据包通过:
sudo iptables -A INPUT -p tcp --dport 21 -j ACCEPT # 允许FTP命令端口 sudo iptables -A INPUT -p tcp --dport 20 -j ACCEPT # 允许FTP数据端口
- 保存iptables规则:
sudo iptables-save > /etc/iptables/rules.v4
- 重启iptables服务:
sudo systemctl restart iptables
使用firewalld设置防火墙
- 安装firewalld:
sudo apt-get install firewalld
对于基于RPM的系统(如centos、Fedora):
sudo yum install firewalld
- 启动firewalld服务:
sudo systemctl start firewalld
- 设置开机自启动:
sudo systemctl enable firewalld
- 添加FTP服务到防火墙:
sudo firewall-cmd --permanent --add-service=ftp sudo firewall-cmd --reload
- 查看当前防火墙状态:
sudo firewall-cmd --list-all