Android12 或以上系统(IKEv2)
2025/10/29大约 4 分钟
Android12 或以上系统(IKEv2)
重要
本文基于 Sumsung One UI 5.1 (Android13) 系统编写。
网络需求
通过 Android12 或以上系统客户端(IKEv2)连接 FortiGate 的 IPSec,并访问 VPN 内部资源。
重要
通过 IKEv2 预共享密钥的方式认证(无用户密码认证)。
网络拓扑

配置步骤
FortiGate 配置
配置 FortiGate 的接口 IP。

进入 FortiGate 的 VPN → IPSec 隧道页面,点击新建按钮,新建 IPSec 隧道。

填写 VPN 名称,模版选择自定义,点击下一步。

按照下图修改配置,其他配置保持默认即可,点击确认下发配置。


对应的 CLI 如下:
第一阶段配置: config vpn ipsec phase1-interface edit "Android_IKEv2" set type dynamic set interface "port2" set ike-version 2 set peertype any set net-device disable set mode-cfg enable set ipv4-dns-server1 10.10.12.2 set proposal aes128-sha256 aes256-sha256 aes128gcm-prfsha256 aes256gcm-prfsha384 chacha20poly1305-prfsha256 set dpd on-idle set ipv4-start-ip 10.10.100.1 set ipv4-end-ip 10.10.100.100 set psksecret xxxxxxxx set dpd-retryinterval 60 next end 第二阶段配置: config vpn ipsec phase2-interface edit "Android_IKEv2" set phase1name "Android_IKEv2" set proposal aes128-sha1 aes256-sha1 aes128-sha256 aes256-sha256 aes128gcm aes256gcm chacha20poly1305 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 "Android_IKEv2" set srcintf "Android_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客户端配置
打开设置 → 连接 → 更多连接设置 → VPN(找不到可以使用搜索功能),点击“添加 VPN 配置文件”。

类型选择 IKEv2/IPSec PSK,填写名称、服务器地址、IPSec 预共享密钥,注意必须填写 IPSec 标识符(随意填写即可),点击保存按钮保存连接。

结果验证
点击创建的 VPN 连接,点击连接按钮。连接成功后,点击查看连接状态,可以看到连接的具体信息。


在 FortiGate 侧查看连接状态。

FortiGate # diagnose vpn ike gateway list vd: root/0 name: Android_IKEv2_0 version: 2 interface: port2 4 addr: 202.103.12.2:4500 -> 202.103.23.2:35653 tun_id: 10.10.100.1/::10.0.0.29 remote_location: 0.0.0.0 network-id: 0 created: 8s ago peer-id: fortigate peer-id-auth: 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 20/20/20 ms IPsec SA: created 1/1 established 1/1 time 0/0/0 ms id/spi: 5 24e28229fbb0aabf/af590cf99666b224 direction: responder status: established 8-8s ago = 20ms proposal: aes128-sha256 child: no SK_ei: ebe7fafddd9a3afa-d25d578817491d46 SK_er: d498cfd72bc78306-5d96c828c054dc49 SK_ai: db2fe8a3c377d068-043cb17abe4a50dc-0b6a7406d9136909-d8f071b76a03d411 SK_ar: 0816650a93fb45f2-620c1f63caa107c3-bdf507a33957e29e-e22ec78cdf616f11 PPK: no message-id sent/recv: 0/2 lifetime/rekey: 86400/86121 DPD sent/recv: 00000000/00000000 peer-id: fortigate FortiGate # diagnose vpn tunnel list list all ipsec tunnel in vd 0 ------------------------------------------------------ name=Android_IKEv2_0 ver=2 serial=25 202.103.12.2:4500->202.103.23.2:35653 tun_id=10.10.100.1 tun_id6=::10.0.0.29 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=Android_IKEv2 index=0 proxyid_num=1 child_num=0 refcnt=5 ilast=0 olast=11 ad=/0 stat: rxp=63 txp=0 rxb=3644 txb=0 dpd: mode=on-idle on=1 idle=60000ms retry=3 count=0 seqno=1 natt: mode=silent draft=0 interval=10 remote_port=35653 proxyid=Android_IKEv2 proto=0 sa=1 ref=2 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=20683 type=00 soft=0 mtu=1422 expire=43175/0B replaywin=2048 seqno=1 esn=0 replaywin_lastseq=0000003f qat=0 rekey=0 hash_search_len=1 life: type=01 bytes=0/0 timeout=43187/43200 dec: spi=02cf6ed7 esp=aes key=16 e9a35403758eddeaa21370e37e36ea8d ah=sha256 key=32 54a6e676edae65bb37a0f4a6605b8fcfde743af1f229d29624abbbd4cc8bf8ec enc: spi=cbf93f37 esp=aes key=16 4e475164fbf9ac1be9c81497cd8ff98f ah=sha256 key=32 682b3b42a8f121a227f70a8952cc92110371f06f32309e5a0c7bb43a48677667 dec:pkts/bytes=126/7288, enc:pkts/bytes=0/0 npu_flag=00 npu_rgwy=202.103.23.2 npu_lgwy=202.103.12.2 npu_selid=1b dec_npuid=0 enc_npuid=0 ------------------------------------------------------ name=Android_IKEv2 ver=2 serial=22 202.103.12.2:0->0.0.0.0:0 tun_id=10.0.0.9 tun_id6=::10.0.0.9 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=43054304 olast=43054304 ad=/0 stat: rxp=7209 txp=12 rxb=427332 txb=832 dpd: mode=on-idle on=0 idle=60000ms 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=27(Android_IKEv2) ...使用客户端访问 VPN 内网资源(Ping 和 HTTP 访问)。

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