debian

Debian FTP服务器防火墙设置

小樊
34
2025-09-22 19:08:05
栏目: 云计算

Debian FTP Server Firewall Configuration Guide

Configuring a firewall for an FTP server on Debian involves allowing the necessary ports for FTP traffic (control and data) while ensuring security—especially for passive mode connections. Below are step-by-step instructions using UFW (Uncomplicated Firewall) and iptables, the two most common firewall tools for Debian.

1. Prerequisites

Before configuring the firewall, ensure:


2. Using UFW (Recommended for Simplicity)

UFW simplifies firewall management with user-friendly commands. Follow these steps:

Install UFW

sudo apt update
sudo apt install ufw

Enable UFW

sudo ufw enable

Confirm enabling with Y when prompted.

Allow FTP Ports

Reload UFW

Apply changes without rebooting:

sudo ufw reload

Verify Rules

Check the status to ensure rules are applied:

sudo ufw status verbose

You should see entries for ports 21/tcp, 20/tcp, and your passive mode range.


3. Using iptables (Advanced Users)

For users needing more granular control, iptables offers low-level rule management.

Install iptables

sudo apt update
sudo apt install iptables

Configure Rules

Add rules to allow FTP traffic:

Save Rules

Debian does not save iptables rules by default. Use iptables-persistent to retain them across reboots:

sudo apt install iptables-persistent
sudo netfilter-persistent save

Confirm saving with Y.

Set Startup Script (Optional)

For systems without iptables-persistent, create a startup script:

sudo nano /etc/network/if-pre-up.d/iptables

Add the following content:

#!/bin/sh
/sbin/iptables-restore < /etc/iptables/rules.v4

Make the script executable:

sudo chmod +x /etc/network/if-pre-up.d/iptables

Verify Rules

Check applied rules:

sudo iptables -L -n -v

Ensure entries for ports 21, 20, and your passive mode range exist.


4. Key Considerations


By following these steps, you can secure your Debian FTP server while ensuring reliable connectivity for clients. Adjust port ranges and security settings based on your network environment and requirements.

0
看了该问题的人还看了