在 Debian 上配置 FTPServer(通常使用 vsftpd)和防火墻(如 UFW 或 iptables)涉及多個步驟。以下是詳細的配置指南:
首先,確保你已經安裝了 vsftpd。在 Debian/Ubuntu 上,可以使用以下命令安裝:
sudo apt update
sudo apt install vsftpd
編輯 vsftpd 的配置文件 /etc/vsftpd.conf
,確保以下設置:
local_enable=YES
write_enable=YES
chroot_local_user=YES
allow_writeable_chroot=YES
保存并退出編輯器,然后重啟 vsftpd 服務:
sudo systemctl restart vsftpd
安裝 UFW(如果尚未安裝):
sudo apt update
sudo apt install ufw
啟用 UFW:
sudo ufw enable
允許 FTP 流量:
允許控制連接(端口 21):
sudo ufw allow 21/tcp
允許數據連接(端口 20):
sudo ufw allow 20/tcp
允許被動模式端口范圍(例如 30000-31000):
sudo ufw allow 30000:31000/tcp
檢查 UFW 狀態:
sudo ufw status verbose
安裝 iptables(如果尚未安裝):
sudo apt update
sudo apt install iptables
配置 iptables 規則:
編輯 /etc/iptables/rules.v4
文件,添加以下規則:
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
# Allow loopback
-A INPUT -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
# Allow established and related connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow SSH
-A INPUT -p tcp --dport 22 -j ACCEPT
# Allow FTP control connection
-A INPUT -p tcp --dport 21 -j ACCEPT
# Allow FTP data connection
-A INPUT -p tcp --dport 20 -j ACCEPT
# Allow passive FTP data connection range
-A INPUT -p tcp --dport 20000:30000 -j ACCEPT
# Allow DNS
-A INPUT -p tcp --dport 53 -j ACCEPT
COMMIT
保存 iptables 規則:
sudo iptables-save /etc/iptables/rules.v4
加載 iptables 規則:
編輯 /etc/network/if-up.d/iptables
文件,添加以下內容:
#!/bin/sh
/sbin/iptables-restore < /etc/iptables/rules.v4
保存并退出編輯器,然后賦予執行權限:
sudo chmod +x /etc/network/if-up.d/iptables
啟用 iptables:
sudo systemctl enable iptables
sudo systemctl start iptables
使用 FTP 客戶端(如 FileZilla)連接到你的 Debian 服務器,確??梢猿晒ι蟼骱拖螺d文件。
以上步驟應該可以幫助你在 Debian 上成功配置 FTPServer 和防火墻。如果有任何問題,請參考相關文檔或尋求社區幫助。