Windows 原生客户端接入 IPSec(IKEv2)
Windows 原生客户端接入 IPSec(IKEv2)
重要
本文基于 Windows 11 专业版 22H2 编写。
网络需求
通过 Windows 原生客户端(IKEv2)连接 FortiGate 的 IPSec,并访问 VPN 内部资源。
重要
Windows 系统使用 IKEv2,必须配合证书认证(客户端验证服务器的证书,服务器不认证客户端的证书)。
网络拓扑

配置步骤
证书颁发
通过证书颁发机构为 FortiGate 颁发证书(这里我们使用 FortiAuthenticator 为例)的注意事项。
重要
Windows 系统使用 IKEv2,必须配合证书认证(客户端验证服务器的证书,服务器不认证客户端的证书),而且对颁发的证书有严格要求:
- CA 向 FortiGate 颁发的证书的 CN 必须和 Windows 客户端连接时填写的服务器 IP 地址或 FQDN 一致(例如此例中,客户端使用 IP 地址 202.103.12.2 连接 VPN,则 CA 向 FortiGate 颁发的证书的 CN 值必须为 202.103.12.2)。
- CA 向 FortiGate 颁发的证书的 EKU(Extended Key Usages)必须包含 Server Authentication 属性。
- 客户端必须导入 CA 证书并加入受信任的根证书颁发机构。
为 FortiGate 颁发证书,并导入 FortiGate(导入过程可参考 系统管理 → 系统设置 → 证书管理章节)。


下载 CA 证书,并导入 Windows PC 的受信任根证书颁发机构列表中。

FortiGate 配置
配置 FortiGate 的接口 IP。

创建本地 VPN 用户和用户组,参考 用户与认证 → 本地用户和用户组章节(如需使用远程认证,请参考 用户与认证 → LDAP 认证 → LDAP 认证配置与排错或 用户与认证 → Radius 认证 → Radius 认证配置与排错章节)。

config user local edit "vpn_user" set type password set passwd xxxxxxxx next end
config user group edit "VPN" set member "vpn_user" next end该种方式的 IPSec 需要使用 CLI 方式配置,分别配置 IPSec 一阶段和二阶段。
IPSec一阶段配置: config vpn ipsec phase1-interface edit "Windows_IKEv2" set type dynamic set interface "port2" set ike-version 2 //IKE协议2 set authmethod signature //认证模式为证书认证 set peertype any set net-device disable set mode-cfg enable //开启为客户端分配IP set ipv4-dns-server1 10.10.1.2 //为客户端分配的DNS地址 set proposal aes128-sha1 aes256-sha256 set dhgrp 2 set eap enable //需要开启EAP做用户密码认证 set eap-identity send-request //开启EAP主动发送认证请求 set authusrgrp "VPN" //选择认证的用户组 set certificate "FortiGate" //选择服务器证书为导入的FortiGate证书 set ipv4-start-ip 10.10.100.1 set ipv4-end-ip 10.10.100.100 //客户端分配地址范围 next end IPSec二阶段配置: config vpn ipsec phase2-interface edit "Windows_IKEv2" set phase1name "Windows_IKEv2" set proposal aes128-sha1 aes256-sha1 set pfs disable set keepalive enable next end配置防火墙策略,允许客户端访问内网 VPN 资源。

VPN资源地址对象: config firewall address edit "LAN_10.10.1.0/24" set subnet 10.10.1.0 255.255.255.0 next end 客户端地址对象: config firewall address edit "VPN_10.10.100.0/24" set subnet 10.10.100.0 255.255.255.0 next end 防火墙策略: config firewall policy edit 1 set name "Windows_IKEv2" set srcintf "Windows_IKEv2" set dstintf "port3" set action accept set srcaddr "VPN_10.10.100.0/24" set dstaddr "LAN_10.10.1.0/24" set schedule "always" set service "ALL" next end
客户端配置
打开设置 → 网络和 Internet → VPN,点击新建按钮。

配置 VPN 提供商为 Windows,配置连接名称和服务器 IP(或 FQDN),“VPN 类型”选择“IKEv2”,“登录信息的类型”选择“用户名和密码”,填写用户名和密码信息,点击保存按钮。

结果验证
在客户端 VPN 点击连接按钮,然后查看连接状态,可以看到 VPN 连接已建立。


在 FortiGate 侧查看连接状态。

FortiGate # diagnose vpn ike gateway list vd: root/0 name: Windows_IKEv2_0 version: 2 interface: port2 4 addr: 202.103.12.2:4500 -> 202.103.23.2:64916 tun_id: 10.10.100.1/::10.0.0.15 remote_location: 0.0.0.0 network-id: 0 created: 281s ago eap-user: vpn_user 2FA: no assigned IPv4 address: 10.10.100.1/0.0.0.0 nat: peer PPK: no IKE SA: created 1/1 established 1/1 time 50/50/50 ms IPsec SA: created 1/1 established 1/1 time 0/0/0 ms id/spi: 28 1a1ac0eb795737c0/45eb750afe25ce3f direction: responder status: established 281-281s ago = 50ms proposal: aes128-sha1 child: no SK_ei: d4088e142220d3f2-24c73e8bd23cc361 SK_er: 23dad2bdacf52ae7-ea3e3f1ad62e48cd SK_ai: 2db36c765a403317-66950b37f90fc178-3ff9a0a4 SK_ar: 919125e418fb94dc-d1978545c2da767a-e5f32bb9 PPK: no message-id sent/recv: 0/6 lifetime/rekey: 86400/85848 DPD sent/recv: 00000000/00000000 FortiGate # diagnose vpn tunnel list list all ipsec tunnel in vd 0 ------------------------------------------------------ name=Windows_IKEv2_0 ver=2 serial=10 202.103.12.2:4500->202.103.23.2:64916 tun_id=10.10.100.1 tun_id6=::10.0.0.15 dst_mtu=1500 dpd-link=on weight=1 bound_if=4 lgwy=static/1 tun=intf mode=dial_inst/3 encap=none/9128 options[23a8]=npu rgwy-chg rport-chg frag-rfc run_state=0 role=primary accept_traffic=1 overlay_id=0 parent=Windows_IKEv2 index=0 proxyid_num=1 child_num=0 refcnt=5 ilast=0 olast=0 ad=/0 stat: rxp=813 txp=280 rxb=61158 txb=30402 dpd: mode=on-idle on=1 idle=20000ms retry=3 count=0 seqno=1 natt: mode=silent draft=0 interval=10 remote_port=64916 proxyid=Windows_IKEv2 proto=0 sa=1 ref=74 serial=1 add-route src: 0:0.0.0.0-255.255.255.255:0 dst: 0:10.10.100.1-10.10.100.1:0 SA: ref=3 options=20483 type=00 soft=0 mtu=1422 expire=42903/0B replaywin=2048 seqno=119 esn=0 replaywin_lastseq=0000032d qat=0 rekey=0 hash_search_len=1 life: type=01 bytes=0/0 timeout=43188/43200 dec: spi=24832a57 esp=aes key=16 7b7328d6fe3ee6230a5072fea98c57d0 ah=sha1 key=20 1fa4bee8e25fd477e8e79ea28291695d84c4d783 enc: spi=60f3ab06 esp=aes key=16 aaaf1aca419bf8dd8743f2c267f97b70 ah=sha1 key=20 50b086fddc0810e3dc5f204c8889f236e18d5663 dec:pkts/bytes=1626/122316, enc:pkts/bytes=560/81074 npu_flag=00 npu_rgwy=202.103.23.2 npu_lgwy=202.103.12.2 npu_selid=f dec_npuid=0 enc_npuid=0 ------------------------------------------------------ name=Windows_IKEv2 ver=2 serial=2 202.103.12.2:0->0.0.0.0:0 tun_id=10.0.0.2 tun_id6=::10.0.0.2 dst_mtu=0 dpd-link=on weight=1 bound_if=4 lgwy=static/1 tun=intf mode=dialup/2 encap=none/552 options[0228]=npu frag-rfc role=primary accept_traffic=1 overlay_id=0 proxyid_num=0 child_num=1 refcnt=3 ilast=42973370 olast=42973370 ad=/0 stat: rxp=3292 txp=280 rxb=241855 txb=30402 dpd: mode=on-idle on=0 idle=20000ms retry=3 count=0 seqno=0 natt: mode=none draft=0 interval=0 remote_port=0 run_tally=0在 FortiGate 侧查看路由 kernel 表,可以看到 FortiGate 已经自动添加了到客户端的路由。
FortiGate # get router info kernel ... tab=254 vf=0 scope=0 type=1 proto=11 prio=1 0.0.0.0/0.0.0.0/0->10.10.100.1/32 pref=0.0.0.0 gwy=10.10.100.1 dev=20(Windows_IKEv2) ...使用客户端访问 VPN 内网资源(Ping 和 HTTP 访问)。

重要
实际测试 Windows 使用 IKEv2,无法使用隧道分割功能,VPN 建立后,所有流量被送入 VPN 隧道。