centos

centos下vsftp如何配置防火墙规则

小樊
44
2025-07-08 12:16:55
栏目: 智能运维

在CentOS系统下配置VSFTPD(Very Secure FTP Daemon)的防火墙规则,通常需要使用firewalldiptables。以下是使用这两种工具进行配置的步骤:

使用 firewalld

  1. 启动并启用 firewalld 服务

    sudo systemctl start firewalld
    sudo systemctl enable firewalld
    
  2. 开放FTP端口: VSFTPD默认使用以下端口:

    • 20(数据连接)
    • 21(控制连接)

    使用firewalld开放这些端口:

    sudo firewall-cmd --permanent --add-port=20/tcp
    sudo firewall-cmd --permanent --add-port=21/tcp
    
  3. 重新加载防火墙配置

    sudo firewall-cmd --reload
    
  4. 验证端口是否开放

    sudo firewall-cmd --list-all
    

使用 iptables

  1. 启动并启用 iptables 服务

    sudo systemctl start iptables
    sudo systemctl enable iptables
    
  2. 开放FTP端口: 使用iptables开放端口20和21:

    sudo iptables -A INPUT -p tcp --dport 20 -j ACCEPT
    sudo iptables -A INPUT -p tcp --dport 21 -j ACCEPT
    
  3. 保存 iptables 规则: CentOS 7及以上版本使用firewalld,但如果你使用的是CentOS 6或其他版本,可以使用以下命令保存规则:

    sudo service iptables save
    
  4. 重启 iptables 服务

    sudo systemctl restart iptables
    
  5. 验证端口是否开放

    sudo iptables -L -n | grep 20
    sudo iptables -L -n | grep 21
    

注意事项

通过以上步骤,你应该能够在CentOS系统下成功配置VSFTPD的防火墙规则。

0
看了该问题的人还看了