debian

Debian FTPServer的防火墙设置指南

小樊
54
2025-07-01 04:05:32
栏目: 智能运维

在Debian系统上设置FTPServer的防火墙可以通过使用 ufw(Uncomplicated Firewall)或 iptables 来实现。以下是使用这两种方法的详细步骤:

使用ufw设置防火墙

  1. 安装ufw(如果尚未安装):

    sudo apt update
    sudo apt install ufw
    
  2. 启用ufw

    sudo ufw enable
    
  3. 允许FTP流量

    • 允许FTP控制端口(21):
      sudo ufw allow 21/tcp
      
    • 允许FTP数据传输端口(20):
      sudo ufw allow 20/tcp
      
    • 允许FTP被动模式端口范围(例如30000-31000):
      sudo ufw allow 30000:31000/tcp
      
  4. 重新加载防火墙规则

    sudo ufw reload
    
  5. 检查防火墙状态

    sudo ufw status
    

使用iptables设置防火墙

  1. 安装iptables(如果尚未安装):

    sudo apt update
    sudo apt install iptables
    
  2. 配置iptables规则

    sudo iptables -A INPUT -p tcp --dport 21 -j ACCEPT  # 允许FTP控制端口
    sudo iptables -A INPUT -p tcp --dport 20 -j ACCEPT  # 允许FTP数据传输端口
    sudo iptables -A INPUT -p tcp --dport 30000:31000 -j ACCEPT  # 允许FTP数据传输端口范围
    sudo iptables -A INPUT -i lo -j ACCEPT  # 允许本地回环接口
    sudo iptables -m state --state ESTABLISHED,RELATED -j ACCEPT  # 允许已建立的连接
    sudo iptables -j REJECT --reject-with icmp-host-prohibited  # 拒绝其他所有输入
    
  3. 保存iptables规则

    sudo iptables-save /etc/iptables/rules.v4
    
  4. 启用iptables服务

    sudo systemctl enable iptables
    sudo systemctl start iptables
    
  5. 检查防火墙状态

    sudo iptables -L -v -n
    

注意事项

通过以上步骤,你应该能够在Debian系统上成功配置FTPServer的防火墙,确保FTP流量能够通过。

0
看了该问题的人还看了