IPSec VPN 是企業跨地點安全互聯的標準方案。本文以 Cisco IOS CLI 為例,詳細拆解 IKE 階段 1、IPSec 階段 2、ACL 流量匹配、Crypto Map 介面套用全流程,含雙端對稱配置關鍵點與驗證指令。
G0/0 IP 192.168.1.1,內網 10.1.0.0/16G0/0 IP 192.168.1.2,內網 10.2.0.0/16Cisco123!! R1
crypto ikev2 proposal AES256/SHA256
encryption aes-gcm-256
integrity sha256
group 14
crypto ikev2 policy IKEV2_POL
proposal AES256/SHA256
match fvrf any
crypto ikev2 keyring KEY_RING
peer R2
address 192.168.1.2
pre-shared-key Cisco123!
crypto ikev2 profile IKEV2_PROF
match identity remote address 192.168.1.2 255.255.255.255
identity local address 192.168.1.1
authentication remote pre-share
authentication local pre-share
keyring local KEY_RING
dpd 10 5 on-demand
R2 對稱配置(IP 互換、peer name 互換)。
關鍵:IKEv2 取代舊版 IKEv1,支援非對稱認證、EAP、MOBIKE、更強加密套件。
! 兩端完全相同
crypto ipsec transform-set ESP_AES256_SHA256 esp-gcm 256
mode tunnel
esp-gcm 256:GCM 模式同時提供加密與認證(AEAD),效能優於 ESP-AES+SHA 組合。tunnel(站對站),transport(主機對主機/傳輸模式)。set pfs group14 在 crypto map 中啟用,每次 Phase 2 重新金鑰交換 DH Group 14。! R1:保護 10.1.0.0/16 ↔ 10.2.0.0/16
access-list 101 permit ip 10.1.0.0 0.0.255.255 10.2.0.0 0.0.255.255
! R2:鏡像 ACL
access-list 101 permit ip 10.2.0.0 0.0.255.255 10.1.0.0 0.0.255.255
原則:ACL 僅做流量分類,**不** 過濾封包(無 deny 隱性規則)。來源/目的必須與對端 ACL 鏡像對稱。
! R1
crypto map VPN_MAP 10 ipsec-ikev2
set peer 192.168.1.2
set transform-set ESP_AES256_SHA256
set pfs group14
match address 101
interface GigabitEthernet0/0
crypto map VPN_MAP
R2 對稱:set peer 192.168.1.1、同一 transform-set、同一 ACL 編號(內容鏡像)。
| 目的 | 指令 | 關鍵輸出 |
|---|---|---|
| IKE SA 狀態 | show crypto ikev2 sa | STATE: READY、ENCR: AES-GCM-256、AUTH: PSK |
| IPSec SA 狀態 | show crypto ipsec sa | inbound/outbound SPI、剩餘位元組/時間、封包計數 |
| ACL 命中統計 | show access-lists 101 | match 計數器遞增確認流量進入 VPN |
| 介面 Crypto Map | show crypto map interface G0/0 | Map name、peer、transform、ACL 綁定確認 |
| 除錯即時日誌 | debug crypto ikev2 / debug crypto ipsec | 階段 1/2 交換細節,**僅維護窗口短時開啟** |
crypto ikev2 nat-traversal(預設開啟)。ip tcp adjust-mss 1360、ip mtu 1400。interface Tunnel0
ip address 10.255.255.1 255.255.255.252
tunnel source GigabitEthernet0/0
tunnel destination 192.168.1.2
tunnel mode ipsec ipv4
tunnel protection ipsec profile IPSEC_PROF
crypto ipsec profile IPSEC_PROF
set transform-set ESP_AES256_SHA256
set ikev2-profile IKEV2_PROF
VTI 將 VPN 視為路由介面,支援動態路由協議(OSPF/BGP)跑在隧道上,管理更直觀,建議新部署優先採用。