Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

Serv-U FTP 深度解析:PORT 主動模式與 PASV 被動模式的連線機制與防火牆穿透實戰

編輯:關於伺服器

FTP 雙通道架構回顧

  • 命令通道:TCP 21,持久連線,傳遞指令/回應
  • 資料通道:臨時建立,三大功能——上傳、下載、目錄列表

兩大模式核心差異:誰發起資料通道連線?

模式別名資料通道發起方流程說明
PORT主動/標準伺服器 (從 TCP 20)Client 送 `PORT h1,h2,h3,h4,p1,p2` 告知自開埠 N → Server 從 20 主動連 Client:N
PASV被動ClientClient 送 `PASV` → Server 回 `227 Entering Passive Mode (h1,h2,h3,h4,p1,p2)` 告知自開埠 M → Client 主動連 Server:M

Serv-U 實戰配置指南

預設行為

安裝預設同時啟用 PORT 與 PASV,最大相容性。

關閉 PASV(僅支援 PORT)

Domains → `your.domain` → Settings → Advanced → 取消勾選 Allow passive mode data transfers。

限制 PASV 埠範圍(穿透防火牆關鍵)

Local Server → Settings → Advanced → PASV port range 填入 `60000-60020`(建議 ≤20 埠)。同步於邊界防火牆/路由器開放此範圍。

IE 啟用 PASV

工具 → 網際網路選項 → 進階 → 勾選 使用被動 FTP (相容防火牆/DSL),需 IE 6.0+。

NAT 環境下的經典陷阱與解決

陷阱 1:PASV 回報私有 IP

227 Entering Passive Mode (192,168,0,108,8,51)  # 實際為 192.168.0.108:2099

公網 Client 無法連線私有 IP。解決:Serv-U Domain → `Enabledynamicdns` → 申請動態域名 (如 tz0.com) 填入 Key → Settings → Advanced → `Allow passive mode data transfers` IP 欄留空 (撥號) 或填固定公網 IP。Serv-U 將自動查詢公網 IP 並回報給 Client。

陷阱 2:PORT 模式 Client 端防火牆攔截

Server 從 TCP 20 主動連 Client 高位埠,Client 端個人防火牆/NAT 常阻擋。建議:優先引導 Client 使用 PASV,或於 Client 端開放入站高位埠。

防火牆策略對照

角色PORT 模式風險PASV 模式風險
Client 端防火牆高:需允許「外部主動連入」高位埠低:Client 主動發起外連,通常允許
Server 端防火牆低:僅 TCP 20/21中:需開放大範圍高位埠 (PASV port range)

最佳實踐總結

  1. 雙模式並啟,最大相容
  2. PASV 限制埠範圍 (≤20) + 防火牆同步開放
  3. NAT 後必設 Dynamic DNS 修正回報 IP
  4. Client 端推薦 PASV,避免 PORT 入站阻擋
  5. IE 設定:取消「啟用資料夾檢視」+ 勾選「使用被動 FTP」強制 PASV
Copyright © Windows教程網 All Rights Reserved