Windows Server 內建「路由和遠程存取服務」(RRAS) 可將服務器轉化為功能完整的軟路由,支援 NAT、VPN (PPTP/L2TP/SSTP/IKEv2)、DHCP Relay、OSPF/RIP/BGP 路由協議、防火牆策略。本文以圖文步驟詳解 RRAS 安裝、NAT 上網共享、介面綁定、靜態路由、動態路由協議啟用全流程,適用實驗室、分支機構、雲上虛擬設備場景。
向導完成後,RRAS 服務啟動,NAT 生效,內網機器設定閘道為 RRAS LAN IP 即可上網。
! 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" (如需撥號觸發)
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 等需引入協議
New-NetFirewallRule -DisplayName "RRAS VPN" -Direction Inbound -Protocol TCP -LocalPort 443 -Action AllowNew-NetFirewallRule -DisplayName "RRAS IKEv2" -Direction Inbound -Protocol UDP -LocalPort 500,4500 -Action Allow| 操作 | 命令/路徑 |
|---|---|
| 查看 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) |
netsh interface ipv4 set subinterface "WAN" mtu=1400 store=persistent 或 RRAS NAT 介面啟用 TCP MSS Clamping (Registry: HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\EnableTCPMSSClamping=1)。Windows RRAS 是「隨手可得」的軟路由利器,適合中小規模、異構環境、快速交付、實驗驗證場景。生產核心業務建議評估專用網絡設備,但 RRAS 作為邊緣節點、雲上 VPC 閘道、實驗室模擬器極具性價比。