萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 網路安全 >  >> 路由器知識 >> 路由器介紹

Windows Server 軟路由 (RRAS) 部署指南:NAT、VPN、路由協議一站式配置

Windows Server 內建「路由和遠程存取服務」(RRAS) 可將服務器轉化為功能完整的軟路由,支援 NAT、VPN (PPTP/L2TP/SSTP/IKEv2)、DHCP Relay、OSPF/RIP/BGP 路由協議、防火牆策略。本文以圖文步驟詳解 RRAS 安裝、NAT 上網共享、介面綁定、靜態路由、動態路由協議啟用全流程,適用實驗室、分支機構、雲上虛擬設備場景。

一、 前置條件

  • Windows Server 2016/2019/2022 (Standard/Datacenter),雙網卡 (WAN/LAN) 或 多網卡。
  • 管理員權限登錄。
  • WAN 口:獲取公網 IP 或上游路由 IP (DHCP/靜態)。
    LAN 口:靜態 IP (如 192.168.10.1/24),做內網閘道。

二、 RRAS 安裝與基礎配置向導

  1. Server Manager → Add Roles and Features → Remote Access → Routing → Next → Install。
  2. 安裝完成,旗標通知 Open the Getting Started Wizard 或 Tools → Routing and Remote Access。
  3. 右鍵本地服務器名 → Configure and Enable Routing and Remote Access → Next。
  4. Configuration 選項選擇:
    • Network Address Translation (NAT):最常用,提供上網共享。
    • Virtual Private Network (VPN) access:撥入 VPN 服務器。
    • Custom configuration:高級自定義 (路由協議、多介面複雜策略)。
    本文選 NAT → Next。
  5. Internet Connection:選擇連接公網的介面 (WAN 口網卡),勾選 Enable security on the selected interface by setting up Basic Firewall (啟用基礎防火牆) → Next。
  6. IP Address Assignment:
    • Automatically:RRAS 內建 DHCP 分配器 (簡單場景)。
    • From a DHCP server:轉發至企業現有 DHCP 服務器 (推薦生產環境,統一 IP 管理)。
    選擇後者 → 指定 DHCP 服務器 IP → Next → Finish。

向導完成後,RRAS 服務啟動,NAT 生效,內網機器設定閘道為 RRAS LAN IP 即可上網。

三、 進階配置:管理主控台 (MMC) 精細操作

  1. 打開 Routing and Remote Access 主控台 (rrasmgmt.msc)。
  2. 展開 IPv4 → General,右鍵 New Routing Protocol:
    • NAT:若向導未啟用,手動添加 → 介面綁定。
    • OSPF / RIP / BGP:動態路由協議 (需 Enterprise/Datacenter 版)。

NAT 介面精細配置


! IPv4 → NAT → 右鍵 New Interface
! 內網介面 (LAN)
Interface: "Ethernet0 (LAN)"
Type: Private interface connected to private network
! 選項:啟用 DHCP Relay Agent (若用外部 DHCP)
! 選項:啟用 DNS Proxy (可選)

! 外網介面 (WAN)
Interface: "Ethernet1 (WAN)"
Type: Public interface connected to the Internet
! 關鍵:勾選 "Enable NAT on this interface"
! 地址池:若 WAN 為動態 IP,選 "Use this public interface IP"
! 若 WAN 多公網 IP,可配置 Address Pool 對應內網伺服器發布 (Port Mapping)

靜態路由配置


IPv4 → Static Routes → 右鍵 New Static Route
Interface: LAN / WAN
Destination: 10.10.20.0
Mask: 255.255.255.0
Gateway: 192.168.10.254 (下一跳)
Metric: 1
! 勾選 "Use this route to initiate demand-dial connections" (如需撥號觸發)

動態路由協議 (OSPF 例)


IPv4 → General → 右鍵 New Routing Protocol → OSPF
! OSPF 屬性
Process ID: 1
Router ID: 1.1.1.1 (手動指定穩定)
Area 0: 添加 LAN 介面 (Passive 可選)
Area 0: 添加 WAN 介面 (若 WAN 為點對點/廣播網)
Redistribution: 勾選 Static / Connected / BGP 等需引入協議

四、 VPN 服務器快速部署 (SSTP/IKEv2 推薦)

  1. RRAS 主控台 → 右鍵服務器 → Properties → Security:勾選 Allow custom IPSec policy for L2TP/IKEv2,配置預共享金鑰或證書。
  2. IPv4 → General → New Routing Protocol → VPN (或向導選 VPN)。
  3. 配置 IP Address Assignment:靜態地址池 (如 192.168.100.10-50) 或 DHCP Relay。
  4. Ports:確保 WAN Miniport (SSTP) (443)、WAN Miniport (IKEv2) (UDP 500/4500) 狀態為 Active。
  5. 防火牆放行:
    New-NetFirewallRule -DisplayName "RRAS VPN" -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow
    New-NetFirewallRule -DisplayName "RRAS IKEv2" -Direction Inbound -Protocol UDP -LocalPort 500,4500 -Action Allow
  6. 客戶端:Windows 內建 VPN 客戶端、iOS/macOS 原生 IKEv2、StrongSwan (Linux/Android) 均免客戶端直連。

五、 關鍵運維操作

操作命令/路徑
查看 NAT 會話表netsh routing ip nat show session
查看活動 VPN 連線RRAS 主控台 → Remote Access Clients / Get-RemoteAccessConnectionStatistics (PS)
查看路由表route print / Get-NetRoute / RRAS 主控台 IPv4 → Static Routes
重啟 RRAS 服務Restart-Service RemoteAccess -Force
匯出/匯入配置RRAS 主控台 → 右鍵服務器 → Export/Import Configuration (XML)

六、 避坑與最佳實務

  • 雙重 NAT 陷阱:上游已為路由器/光貓路由模式 → RRAS WAN 口拿私網 IP → 再做 NAT。解決:上游設橋接/Modem 模式,或 RRAS WAN 口設 DMZ/端口映射,或放棄 RRAS NAT 改用上游 NAT。
  • MTU/MSS 鉗制:VPN 隧道開銷導致大封包分片/丟失。介面啟用 netsh interface ipv4 set subinterface "WAN" mtu=1400 store=persistent 或 RRAS NAT 介面啟用 TCP MSS Clamping (Registry: HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\EnableTCPMSSClamping=1)。
  • 效能上限:軟路由 CPU 密集型 (NAT/加密/路由計算),高吞吐 (>1Gbps) 場景建議專用硬體路由器/防火牆 (ASIC/NPU 加速) 或 DPDK/VPP 數據平面方案。
  • 高可用:雙機熱備需配合 NLB/Keepalived/VRRP + 配置同步腳本,非原生支援。

Windows RRAS 是「隨手可得」的軟路由利器,適合中小規模、異構環境、快速交付、實驗驗證場景。生產核心業務建議評估專用網絡設備,但 RRAS 作為邊緣節點、雲上 VPC 閘道、實驗室模擬器極具性價比。

copyright © 萬盛學電腦網 all rights reserved