FortiGate 實戰課程

由資深架構師帶領的深度技術解析

Concept

一、核心概念

VXLAN over IPsec 是一種結合了 Layer 2 延伸能力與 Layer 3 加密安全性的混合技術。它允許我們透過網際網路(Internet)將兩個地理位置不同的區域網路(LAN)連接起來,讓兩端的設備感覺就像是在同一個實體交換器上(同一個 Subnet),同時利用 IPsec 確保資料在公網傳輸時不被竊聽或竄改。

生活化比喻:跨海大橋上的裝甲運鈔車

想像台北總公司和高雄分公司各有一棟辦公大樓,我們希望這兩棟樓的員工可以直接「走」到對方的辦公室,就像中間有一條專屬走廊(Layer 2 連通)。

  • VXLAN (專屬貨櫃):我們把要傳送的資料(文件、電腦)裝進一個特製的「VXLAN 貨櫃」裡。這個貨櫃標示了這屬於哪個部門(VNI),不管運到哪裡,打開來都是原本的樣子。
  • Internet (公共高速公路):貨櫃必須經過公共的高速公路,這裡充滿了各種車輛,且不安全。
  • IPsec (裝甲運鈔車):因為 VXLAN 貨櫃本身是透明的(無加密),任何人都能看到裡面的東西。所以,我們把整個「VXLAN 貨櫃」再塞進一輛堅固的「IPsec 裝甲運鈔車」裡。

結果:外人只看得到裝甲車在跑(IPsec ESP),看不到裡面裝了什麼,而到達目的地後,卸下裝甲,取出貨櫃,裡面的資料完好如初。

Mechanism

二、運作原理

技術細節

這個架構涉及雙重封裝(Double Encapsulation)。原始的 Ethernet Frame 先被封裝進 VXLAN 標頭中,然後整個 VXLAN 封包被視為 Payload,再次被封裝進 IPsec ESP 通道中。

  • Step 1 (原始資料): PC 發出標準 Ethernet Frame。
  • Step 2 (VXLAN 封裝): FortiGate 將 Frame 封裝,加上 UDP Header (Port 4789) 與 VXLAN Header (包含 VNI ID)。
  • Step 3 (IPsec 封裝): 因為設定了 IPsec Tunnel,FortiGate 將上述整個封包加密,加上 ESP Header 與新的 Outer IP Header。
  • Step 4 (傳輸): 加密封包透過 Internet 路由至對端 FortiGate。

關鍵參數與挑戰

⚠️ 關鍵挑戰:MTU (Maximum Transmission Unit)

雙重封裝會吃掉大量的 Payload 空間!
VXLAN Overhead: 約 50 Bytes
IPsec Overhead: 約 50-80 Bytes (視加密演算法而定)
建議設定: 將虛擬介面的 MTU 調降至 1350 - 1370 Bytes,並啟用 TCP MSS Clamping,否則大封包會被丟棄 (Fragment)。

  • UDP Port: 4789 (VXLAN 標準埠號)
  • VNI (VXLAN Network Identifier): 類似 VLAN ID,但在 VXLAN 中有 24-bit 長度 (可支援 1600 萬個網段)。
  • Software Switch: 在 FortiGate 上,通常需要將 VXLAN 介面與實體 LAN Port 橋接 (Bridge) 在一起。
Visuals

三、架構視覺化

1. 邏輯拓撲圖 (Network Topology)

說明:Site A 與 Site B 透過 Internet 連接,底層是 IPsec VPN,上層跑 VXLAN,將內部 VLAN 10 打通。

graph LR subgraph Site_A [台北總公司] PC_A[PC A
192.168.10.10] -- VLAN 10 --> LAN_A[Port2
Soft Switch] LAN_A -- Bridge --> VXLAN_A[VXLAN Int] VXLAN_A -- Encapsulate --> FGT_A[FortiGate A
WAN: 1.1.1.1] end FGT_A == "IPsec Tunnel (Encrypted)" ==> Internet((Internet)) subgraph Site_B [高雄分公司] Internet == "IPsec Tunnel (Encrypted)" ==> FGT_B[FortiGate B
WAN: 2.2.2.2] FGT_B -- Decapsulate --> VXLAN_B[VXLAN Int] VXLAN_B -- Bridge --> LAN_B[Port2
Soft Switch] LAN_B -- VLAN 10 --> PC_B[PC B
192.168.10.20] end classDef device fill:#f9f,stroke:#333,stroke-width:2px; classDef pc fill:#bbf,stroke:#333,stroke-width:2px; class FGT_A,FGT_B device; class PC_A,PC_B pc;

2. 封包封裝流程 (Packet Walk)

說明:展示從 PC A 發出封包到 PC B 接收的過程中,封包表頭的變化。

sequenceDiagram participant User as PC A (192.168.10.10) participant FGTA as FortiGate A participant Internet participant FGTB as FortiGate B participant Dest as PC B (192.168.10.20) User->>FGTA: 原始封包 [Src:10.10, Dst:10.20 | Payload] Note over FGTA: 進入 Soft Switch,
轉發至 VXLAN 介面 Note over FGTA: 加上 VXLAN Header
[UDP 4789 | VNI 100 | Orig Packet] Note over FGTA: 進入 IPsec Phase 1
加上 ESP 加密標頭 FGTA->>Internet: 加密封包 [IPsec ESP | VXLAN | Orig Packet] Internet->>FGTB: 路由傳送 Note over FGTB: IPsec 解密與驗證 Note over FGTB: 剝除 VXLAN Header
取出原始封包 Note over FGTB: 透過 Soft Switch
轉發至 LAN Port FGTB->>Dest: 原始封包 [Src:10.10, Dst:10.20 | Payload]
Use Case

四、實務應用場景:災難備援 (DR) 與 vMotion

情境: 某金融企業需要將台北資料中心 (DC) 的虛擬機 (VMware ESXi) 在緊急狀況下無痛遷移到高雄異地備援中心。為了不中斷服務,且避免修改應用程式的 IP 設定,兩地的伺服器網段必須完全一致 (192.168.10.0/24)。

優點 (Pros)

  • 無痛遷移: 伺服器 IP 無需變更,vMotion 可跨 WAN 運作。
  • 安全性高: 所有 L2 流量皆由 IPsec AES-256 加密保護。
  • 部署彈性: 與電信商無關 (ISP Independent),只要有 Internet 即可建立。

缺點 (Cons)

  • 廣播風暴: L2 廣播封包會穿越 WAN,消耗頻寬 (需做 Broadcast Suppression)。
  • 效能耗損: 雙重封裝增加 CPU 負擔與封包大小 (Fragment 風險)。
  • 除錯困難: 封包被層層包覆,Sniffer 抓包較難直接分析。

設定範例 (Configuration Example)

以下以 Site A (台北) 為例,Site B 設定需對稱調整。

Step 1: 建立 IPsec VPN (Interface Mode)

config vpn ipsec phase1-interface
    edit "to-SiteB"
        set interface "wan1"
        set peertype any
        set net-device disable
        set proposal aes256-sha256
        set remote-gw 2.2.2.2
        set psksecret your-secret-password
    next
end

config vpn ipsec phase2-interface
    edit "to-SiteB"
        set phase1name "to-SiteB"
        set proposal aes256-sha256
        set auto-negotiate enable
    next
end

Step 2: 建立 VXLAN 介面 (綁定在 IPsec 上)

config system vxlan
    edit "vxlan10"
        set interface "to-SiteB"  <-- 綁定在 VPN 介面
        set vni 100               <-- 兩端 VNI 必須一致
        set dstport 4789
        set remote-ip "192.168.254.2" <-- 對端的內部 Loopback 或虛擬 IP (依架構而定)
    next
end

註:由於是透過 IPsec Tunnel,這裡的 remote-ip 有時在 Point-to-Point VPN 架構下可省略,或指向對端 VPN 介面 IP。

Step 3: 建立 Software Switch (橋接實體與 VXLAN)

config system switch-interface
    edit "br-vlan10"
        set vdom "root"
        set member "port2" "vxlan10" <-- 將實體 Port2 與 VXLAN 綁在一起
    next
end

config system interface
    edit "br-vlan10"
        set ip 192.168.10.254 255.255.255.0
        set allowaccess ping
    next
end

Step 4: 設定防火牆政策 (允許 VPN 與 LAN 流量)

config firewall policy
    edit 1
        set name "Allow-VPN-Traffic"
        set srcintf "br-vlan10" "to-SiteB"
        set dstintf "br-vlan10" "to-SiteB"
        set action accept
        set srcaddr "all"
        set dstaddr "all"
        set schedule "always"
        set service "ALL"
    next
end
Quiz

五、隨堂測驗