ubuntu

Ubuntu FTP Server怎样设置防火墙

小樊
36
2025-04-22 12:07:58
栏目: 智能运维

在Ubuntu上设置FTP服务器的防火墙规则,通常涉及使用 ufw (Uncomplicated Firewall)或 iptables 。以下是使用这两种方法的步骤:

使用ufw配置防火墙

  1. 安装ufw(如果尚未安装):
sudo apt update
sudo apt install ufw
  1. 启用ufw
sudo ufw enable
  1. 允许FTP流量
sudo ufw allow 20/tcp
sudo ufw allow 21/tcp
sudo ufw allow 1024:1048/tcp
  1. 检查防火墙状态
sudo ufw status

使用iptables配置防火墙

  1. 安装iptables(如果尚未安装):
sudo apt-get install iptables
  1. 允许FTP流量
sudo iptables -A INPUT -p tcp --dport 20 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 21 -j ACCEPT
  1. 允许被动模式FTP
sudo iptables -A INPUT -p tcp --dport 1024:1048 -j ACCEPT
  1. 保存iptables规则
sudo apt-get install iptables-persistent
sudo netfilter-persistent save
  1. 查看iptables规则
sudo iptables -L -n

请注意,使用 ufw 方法通常更简单且易于管理。如果你的FTP服务器使用的是vsftpd,你还需要确保vsftpd的配置文件 /etc/vsftpd.conf 中的设置允许FTP流量通过防火墙。

0
看了该问题的人还看了