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隧道。