在CentOS系统下配置VSFTPD(Very Secure FTP Daemon)的防火墙规则,通常需要使用firewalld
或iptables
。以下是使用这两种工具进行配置的步骤:
firewalld
启动并启用 firewalld
服务:
sudo systemctl start firewalld
sudo systemctl enable firewalld
开放FTP端口: VSFTPD默认使用以下端口:
使用firewalld
开放这些端口:
sudo firewall-cmd --permanent --add-port=20/tcp
sudo firewall-cmd --permanent --add-port=21/tcp
重新加载防火墙配置:
sudo firewall-cmd --reload
验证端口是否开放:
sudo firewall-cmd --list-all
iptables
启动并启用 iptables
服务:
sudo systemctl start iptables
sudo systemctl enable iptables
开放FTP端口:
使用iptables
开放端口20和21:
sudo iptables -A INPUT -p tcp --dport 20 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 21 -j ACCEPT
保存 iptables
规则:
CentOS 7及以上版本使用firewalld
,但如果你使用的是CentOS 6或其他版本,可以使用以下命令保存规则:
sudo service iptables save
重启 iptables
服务:
sudo systemctl restart iptables
验证端口是否开放:
sudo iptables -L -n | grep 20
sudo iptables -L -n | grep 21
被动模式:如果你的FTP客户端使用被动模式(PASV),还需要开放一个范围较大的端口(通常是1024到65535)。你可以使用以下命令开放这个范围:
sudo firewall-cmd --permanent --add-port=1024-65535/tcp
sudo firewall-cmd --reload
或者使用iptables
:
sudo iptables -A INPUT -p tcp --dport 1024:65535 -j ACCEPT
sudo service iptables save
sudo systemctl restart iptables
SELinux:如果你的系统启用了SELinux,可能还需要配置SELinux策略以允许FTP连接。可以使用以下命令查看SELinux状态:
sestatus
如果SELinux处于 enforcing 模式,可以尝试临时将其设置为 permissive 模式以测试:
sudo setenforce 0
如果一切正常,可以配置SELinux策略以永久允许FTP连接。
通过以上步骤,你应该能够在CentOS系统下成功配置VSFTPD的防火墙规则。