fortigate ipsec vpn建立和troubleshooting 版本 1.0 作者...

26
FortiGate IPSEC VPN 建立和 Troubleshooting 版本 1.0 时间 2015 年 3 月 作者 王东 ([email protected]) 支持的版本 用于本文的测试版本: FortigateVM, FortiOS 5.0.11/4.3.18 build0689 (MR3 Patch 18) 状态 草稿

Upload: lethuy

Post on 16-Apr-2018

359 views

Category:

Documents


13 download

TRANSCRIPT

Page 1: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

FortiGate IPSEC VPN 建立和 Troubleshooting

版本 1.0

时间 2015 年 3 月

作者 王东 ([email protected])

支持的版本 用于本文的测试版本:

FortigateVM, FortiOS 5.0.11/4.3.18 build0689 (MR3

Patch 18)

状态 草稿

Page 2: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

目 录

FortiGate IPSEC VPN 建立和 Troubleshooting.......................................................................... 1

1.目的:...............................................................................................................................................3

2.Site to Site VPN 知识简介:................................................................................................... 3

3.测试环境:.......................................................................................................................................6

4.FortiGate Site to Site VPN 应用举例:................................................................................ 6

5.FortiGate Site to Site VPN Troubleshooting:................................................................16

5.Debug Flow 使用方法:...............................................................................................................23

6.结束语以及注意事项:...............................................................................................................26

Page 3: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

1.目的:

VPN 的功能:在公用网络上建立专用网络,进行加密通讯。在企业网络中有广泛

应用。VPN 网关通过对数据包的加密和数据包目标地址的转换实现远程访问。VPN

有多种分类方式,主要是按协议进行分类。VPN 可通过服务器、硬件、软件等多

种方式实现。VPN 具有成本低,并且易于使用的特点。

VPN 属于远程访问技术,简单地说就是利用公用网络架设专用网络。例如某公司

员工出差到外地,他想访问企业内网的服务器资源,这种访问就属于远程访问。

在传统的企业网络配置中,要进行远程访问,传统的方法是租用 DDN(数字数据

网)专线或帧中继,这样的通讯方案必然导致高昂的网络通讯和维护费用。对于

移动用户(移动办公人员)与远端个人用户而言,一般会通过拨号线路(Internet)

进入企业的局域网,但这样必然带来安全上的隐患。

按照协议划分,VPN 可以分为二层 VPN,如 PPTP,L2TP;三层 VPN 如 IPSEC,GRE

等。按照 VPN 的应用可以划分为两类,Site to Site VPN 和 Remote Access VPN。

民生银行分行目前按照应用划分有两种业务的 VPN,Site to Site VPN,拨号方

式的 SSL VPN 。为了进一步了解民生银行常见的 VPN 配置以及如何去 Debug 这

两 种 VPN 故 障 , 我 们 需 要 去 手 动 的 搭 建 VPN 环 境 以 及 了 解 如 何 去

Troubleshooting 上述 VPN 的问题。

2.Site to Site VPN 知识简介:

1) IPSec VPN 两种工作模式:

站点到站点 VPN 连接的是两个网络。实现两个网络内的计算机互访。默认情况下,

站点到站点 VPN 连接是请求拨号连接,只有当网络流量必须通过此接口转发(需

要转发 IP 数据包到对应的远程网络)时才建立连接。此时呼叫路由器(VPN 客

户端)初始化这个连接,应答路由器(VPN 服务器)侦听连接请求,接收来自呼

叫路由器的连接请求,并根据请求建立连接,并且在空闲一定时间。可以配置连

接为永久连接方式,此时,VPN 服务器会保持此连接的连接状态,如果连接中断

则立即重新初始化连接。此 VPN 适用于公司总部与分部之间的数据加密传输,常

见网络结构如下图所示:

Page 4: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

2) IPSec VPN 介绍:

IPSec 加密和认证方式:

IPSEC 是一套比较完整成体系的 VPN 技术,它规定了一系列的协议标准。如果不

深入探究IPSEC的过于详细的内容,我们对于IPSEC大致按照以下几个方面理解。

VPN 只是 IPSec 的一种应用方式,IPSec 其实是 IP Security 的简称,它的目的

是为 IP 提供高安全性特性,VPN 则是在实现这种安全特性的方式下产生的解决

方案。IPSec 是一个框架性架构,具体由两类协议组成:

1: AH 协议(Authentication Header,使用较少):可以同时提供数据完整性确

认、数据来源确认、防重放等安全特性;AH 常用摘要算法(单向 Hash 函数)MD5

和 SHA1 实现该特性。

2: ESP 协议(Encapsulated Security Payload,使用较广):可以同时提供数

据完整性确认、数据加密、防重放等安全特性;ESP 通常使用 DES、3DES、AES

等加密算法实现数据加密,使用 MD5 或 SHA1 来实现数据完整性。

为何AH使用较少呢?因为AH无法提供数据加密,所有数据在传输时以明文传输,

而 ESP 提供数据加密;其次 AH 因为提供数据来源确认(源 IP 地址一旦改变,AH

校验失败),所以无法穿越 NAT。当然,IPSec 在极端的情况下可以同时使用 AH

和 ESP 实现最完整的安全特性,但是此种方案极其少见。

IPSec 封装模式:

介绍完 IPSec VPN 的场景和 IPSec 协议组成,再来看一下 IPSec 提供的两种封装

模式(传输 Transport 模式和隧道 Tunnel 模式)

Page 5: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

可以发现传输模式和隧道模式的区别:

1.传输模式在 AH、ESP 处理前后 IP 头部保持不变,主要用于 End-to-End 的应用

场景。

2.隧道模式则在 AH、ESP 处理之后再封装了一个外网 IP 头,主要用于

Site-to-Site 的应用场景。

对于 IPsec 中 IKE 协商的第一阶段,可以有主模式和积极模式两种协商模式选

择,这取决于使用的场合,通常来讲,默认的时候都是用的主模式,如在 Cisco

设备中使用命令行进行预共享密钥的配置时,如果不指定为 aggressive-mode

的时候,就默认为主模式。

但是不是所有的场合都适合使用主模式,比如对于对端的链接无法使用固定 ip

地址来确定时(如 adsl),只能使用域名来定义,这个时候,主模式就不能用,

只能使用积极模式。这也是由主模式和积极模式的细节区别决定的。

IKEv1 主模式和积极模式的区别:

1、交换消息的数量:主模式为 6条,而积极模式只有 3条,而且形式上也不同。

主模式中,每两条是对称的,也就是对等体都向对方发送相同类型字段的消息,

这样的消息交换共分为三次,一共是 6条;

而在积极模式中,首先由 sa 的发起者发送一条消息给 sa 的接受者,sa 的接受

者收到第一条消息以后,会将自己的 sa 协商消息附上签名认证信息后发回给 sa

的发起者,这是第二条信息,第三条信息再由 sa 的发起者发送给 sa 的接受者,

这条信息中包含了sa的发起者的签名认证信息。这有点类似于TCP的三次握手。

2、对于 NAT 穿越的支持:这也要视对等体双方的认证方式而定,主要的区别在

预共享密钥的情况下。

如果是预共享密钥的情况下,主模式是不支持 NAT 穿越的,而积极模式可以支持

NAT 穿越。

而在证书认证的情况下,主模式和积极模式都是支持 NAT 穿越的。

3.对于对等体标识的使用:对于主模式,在对等体标识的配置使用上,只能使用

ip 地址进行标识;而对于积极模式,则可以使用 ip 地址或者域名进行对等体的

标识。

这也是由于主模式和积极模式的消息交换机制所决定的。主模式中,第 1、2条

信息中,双方交换了一些协商信息,如加密算法、认证算法(hash)、DH 组、认

证机制等;在双方交换的第 3、4 条消息中,双方交换了公共密钥,在交换了公

共密钥之后,就可以根据 DH 算法生成后续所需的密钥了(SKEYID),其中包括给

数据加密的对称密钥。这在 DH 算法中,需要用到双方定义的预共享密钥。而在

一个设备有多个对等体的情况下,设备需要使用 ID 信息(如域名信息)来判定

对应的对等体的预共享密钥,而这个 ID 信息是在消息 5、6中双方才进行交换的,

所以设备这时候只能使用 IP 地址进行对等体预共享密钥的匹配。所以主模式中

无法使用域名信息来进行对等体标识。

Page 6: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

而对于积极模式,由于其在第一条信息交换时就发送了对应的 ID 信息,sa 的接

收方可以根据该 ID 信息匹配对应的预共享密钥,从而计算对应的 SKEYID。故积

极模式是可以使用 IP 地址或者域名来进行对等体标识的。但是由于积极模式中,

是在加密身份信息的安全 sa 建立之前就进行了身份信息的交换,所以交换的消

息都是明文的,ID 信息也是明文的,这带来了安全隐患。

4、对于 DH 组的协商:在主模式中,双方使用消息 1、2进行了所使用的 DH 组的

协商,但是在积极模式中,双方没有协商就进行了 DH 信息的交换,所以 DH 组是

确定的。

5、协商速度及协商能力:由于信息交换的数量较少,所以积极模式下,协商的

速度更快,但是协商能力不如主模式。

3.测试环境:

Windowns2003-------FGTVM-103--------FGTVM-104------Ubuntu

Windows2003 是启用 FTP 服务器, Ubuntu 是远程客户端。我们将在 FGTVM-103

和 FGTVM-104 之间搭建 Site to Site 的 VPN 并且进行测试。对于 IPSec

VPN ,FortiGate 支持接口 VPN 和策略 VPN 两种,本次测试基于民生银行大部分

使用 v4.0.18 版本,因此本文介绍均已策略 VPN 为例。

4.FortiGate Site to Site VPN 应用举例:

1) 当远程网关为静态 IP 地址的时候:

在 FGTVM-103 上,虚拟专用网->创建第一阶段,输入第一阶段的 VPN 名称,选择

远程网关为静态 IP,输入正确的对端网关地址和接口 IP,如下图所示:

Page 7: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

输入共享秘钥,保持这个秘钥在两端一致,我们先测试主模式,在高级选项中选

择相应的加密算法,验证方法和 DH 组,并且保证两端一致。并且启用对等体状

态探测,如下图所示:

点击创建第二阶段,选择第一阶段名称,如下图所示:

Page 8: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

在高级选项中选择相应的加密算法,验证方法和 DH 组,并且保证两端一致。并

且启用保持存活,如下图所示:

在 FGTVM-104 上,同样做上述的配置,通过 CLI,可以看到命令如下:

FGTVM-104 # show vpn ipsec phase1

config vpn ipsec phase1

edit "test-static-ip"

set interface "port2"

set proposal des-md5 des-sha1

set remote-gw 10.10.10.1

set psksecret ENC

TG9jYYnbaRy/SZughEPuXyYfGcJEWPMgPe+j4tQ+G8BI+ZDtjbwBe7TrQscw2z1bYTqqI

4U1W+LPWeMAxzwhfafPKvSAEke8Oj/7YEOr8MsbUJHG

next

end

FGTVM-104 # show vpn ipsec phase2

config vpn ipsec phase2

edit "test-static-ip"

set keepalive enable

set phase1name "test-static-ip"

set proposal des-md5 des-sha1

next

end

回到策 FGT 策略界面,创建相应的 IPSEC 策略,由于是我们是基于 Port2 建立

的 IPSec VPN,因此在目的接口处选择 Port2,源接口我们则输入内网 IP 端,动

作选择 IPSEC,并且选择建立好的 VPN 实例,如下图所示:

Page 9: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

同样的策略建立在 FGTVM-104 上,通过 CLI,我们看到配置如下:

FGTVM-104 # show firewall policy 3

config firewall policy

edit 3

set srcintf "port3"

set dstintf "port2"

set srcaddr "all"

set dstaddr "all"

set action ipsec

set schedule "always"

set service "ANY"

set inbound enable

set outbound enable

set vpntunnel "test-static-ip"

next

end

在 VPN 监控器->IPSec 监控,点击启用,如下图所示,VPN 已经成功建立:

Page 10: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

通过关掉 Policy 1,2,让两端后的主机通过 IPSec 隧道走,在 Win2003 Server

启用 FTP,在 Unbuntu 上模拟客户端,模拟 FTP 和 Ping 流量,我们通过策略流量

统计,可以看到流量通过 Policy 3 走的,

Page 11: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

2) 当远程网关为拨号用户的时候:

在 FGTVM-103 上,虚拟专用网->创建第一阶段,输入第一阶段的 VPN 名称,选择

远程网关为连接用户,输入正确的对端网关地址和接口 IP,此墙模拟数据中心,

选择接受对等体 ID:test,如下图所示:

输入共享秘钥,保持这个秘钥在两端一致,这次我们测试野蛮模式,在高级选项

中选择相应的加密算法,验证方法和 DH 组,并且保证两端一致。并且启用对等

体状态探测,如下图所示:

Page 12: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

在 FGTVM-103 上,虚拟专用网->创建第一阶段,输入第一阶段的 VPN 名称,选择

远程网关为连接用户,输入正确的对端网关地址和接口 IP,此墙模拟数据中心,

选择接受对等体 ID:test,如下图所示:

在 FGTVM-103 上,虚拟专用网->创建第二阶段,输入第二阶段的 VPN 名称,选择

第一阶段实例,选择正确的加密算法和认证方法,启用保持存活,如下图所示:

Page 13: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

在 FGTVM-104 上,虚拟专用网->创建第一阶段,输入第一阶段的 VPN 名称,选择

远程网关为静态 IP,输入正确的对端数据中心的网关地址,此墙模拟远程拨号用

户端,指明本地 ID:test,如下图所示:

在 FGTVM-104 上,虚拟专用网->创建第二阶段,输入第二阶段的 VPN 名称,选择

第一阶段实例,选择正确的加密算法和认证方法,启用保持存活。注意:在快速

模式选择器下,此处一定要指明源地址和目的地址 ,此处的含义是指明隧道内的

路由,源指的是出访的 IP 段,目的是被访问的 IP 段,如果设置成 0.0.0.0/0

则隧道无法Up,而如果地址设置不对,通过Debug flow要访问的地址则会被Deny

by forward policy, 配置如下图所示:

Page 14: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

回到策 FGVM-103/104 上的策略界面,创建相应的 IPSEC 策略,由于是我们是基

于 Port2 建立的 IPSec VPN,因此在目的接口处选择 Port2,源接口我们则输入内

网 IP 端,动作选择 IPSEC,并且选择建立好的 VPN 实例,如下图所示:

在 FGTVM-104,拨号端启用 IPSEC,分别在 FGTVM-103 数据中心和 FGTVM-104 拨

号端, 观察 IPSEC 监控器,此时,拨号 VPN 已经成功建立.

Page 15: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

通过关掉 Policy 1,2,让两端后的主机通过 IPSec 隧道走,在 Win2003 Server

启用 FTP,在 Unbuntu 上模拟客户端,模拟 FTP 和 Ping 流量,我们通过策略流量

统计,可以看到流量通过 Policy 3 走的。

Page 16: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

5. FortiGate Site to Site VPN Troubleshooting:

1) 当远程网关为静态 IP 地址的时候:

在 CLI 下,打开 VPN Debug 调试开关,在我们第一次选择主模式的时候,在 IPSec

隧道成功建立后,我们可以看到如下的信息,包括主模式第一阶段协商信息,包

含的具体加密和认证算法,第二阶段的协商信息和 DPD 对等体信息:

FGTVM-103 # diagnose debug application ike -1

FGTVM-103 # diagnose debug enable

FGTVM-103 # ike 0:test-static-ip: link is idle 3

10.10.10.1->10.10.10.2:500 dpd=1 seqno=12a

ike 0:test-static-ip:2: send IKEv1 DPD probe, seqno 298

ike 0:test-static-ip:2: enc

Page 17: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

62620E7ADD6A25AAC880B2730378AE53081005016D0B3C43000000500B000014E7BCB

89326AFC43A5FD606C321AE205C000000200000000101108D2862620E7ADD6A25AAC8

80B2730378AE530000012A

ike 0:test-static-ip:2: out

62620E7ADD6A25AAC880B2730378AE53081005016D0B3C43000000545ECA153442EFD

44F3F48F46832268C8D49B80AABEF8ED78097517AD2A7372794AA5916C31120843719

0784F278B30AF80591735F52F9A3E1

ike 0:test-static-ip:2: sent IKE msg (R-U-THERE):

10.10.10.1:500->10.10.10.2:500, len=84,

id=62620e7add6a25aa/c880b2730378ae53:6d0b3c43

ike 0: comes 10.10.10.2:500->10.10.10.1:500,ifindex=3....

ike 0: IKEv1 exchange=Informational

id=62620e7add6a25aa/c880b2730378ae53:c22d8d94 len=84

ike 0:test-static-ip:test-static-ip: IPsec SA connect 3

10.10.10.1->10.10.10.2:500

ike 0:test-static-ip:test-static-ip: using existing connection

ike 0:test-static-ip:test-static-ip: config found

ike 0:test-static-ip:test-static-ip: IPsec SA connect 3

10.10.10.1->10.10.10.2:500 negotiating

ike 0:test-static-ip:2: cookie

62620e7add6a25aa/c880b2730378ae53:b4c0b9d6

ike 0:test-static-ip:2:test-static-ip:488: initiator selectors 0

0:0.0.0.0/0.0.0.0:0:0->0:0.0.0.0/0.0.0.0:0:0

ike 0:test-static-ip:2:

ike 0:test-static-ip:2: sent IKE msg (quick_i1send):

10.10.10.1:500->10.10.10.2:500, len=380,

id=62620e7add6a25aa/c880b2730378ae53:b4c0b9d6

ike 0: comes 10.10.10.2:500->10.10.10.1:500,ifindex=3....

ike 0: IKEv1 exchange=Quick

id=62620e7add6a25aa/c880b2730378ae53:b4c0b9d6 len=356

ike 0:test-static-ip:2:test-static-ip:488: responder selectors

0:0.0.0.0/0.0.0.0:0->0:0.0.0.0/0.0.0.0:0

ike 0:test-static-ip:2:test-static-ip:488: my proposal:

ike 0:test-static-ip:2:test-static-ip:488: proposal id = 1:

ike 0:test-static-ip:2:test-static-ip:488: protocol id = IPSEC_ESP:

ike 0:test-static-ip:2:test-static-ip:488: PFS DH group = 5

ike 0:test-static-ip:2:test-static-ip:488: trans_id = ESP_DES

ike 0:test-static-ip:2:test-static-ip:488: encapsulation =

ENCAPSULATION_MODE_TUNNEL

ike 0:test-static-ip:2:test-static-ip:488: type = AUTH_ALG,

val=MD5

ike 0:test-static-ip:2:test-static-ip:488: trans_id = ESP_DES

ike 0:test-static-ip:2:test-static-ip:488: encapsulation =

ENCAPSULATION_MODE_TUNNEL

Page 18: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

ike 0:test-static-ip:2:test-static-ip:488: type = AUTH_ALG,

val=SHA1

ike 0:test-static-ip:2:test-static-ip:488: incoming proposal:

ike 0:test-static-ip:2:test-static-ip:488: proposal id = 1:

ike 0:test-static-ip:2:test-static-ip:488: protocol id = IPSEC_ESP:

ike 0:test-static-ip:2:test-static-ip:488: PFS DH group = 5

ike 0:test-static-ip:2:test-static-ip:488: trans_id = ESP_DES

ike 0:test-static-ip:2:test-static-ip:488: encapsulation =

ENCAPSULATION_MODE_TUNNEL

ike 0:test-static-ip:2:test-static-ip:488: type = AUTH_ALG,

val=MD5

ike 0:test-static-ip:2: enc

62620E7ADD6A25AAC880B2730378AE5308102001B4C0B9D60000003000000014F206F

3157CA583F06457A223666CEBF0

ike 0:test-static-ip:2: out

62620E7ADD6A25AAC880B2730378AE5308102001B4C0B9D600000034B15CC1A0FFE09

73A17099862EB04F3F4048C006C04F95C92

ike 0:test-static-ip:2: sent IKE msg (quick_i2send):

10.10.10.1:500->10.10.10.2:500, len=52,

id=62620e7add6a25aa/c880b2730378ae53:b4c0b9d6

ike 0:test-static-ip:2:test-static-ip:488: replay protection enabled

ike 0:test-static-ip:2:test-static-ip:488: SA life soft seconds=1751.

ike 0:test-static-ip:2:test-static-ip:488: SA life hard seconds=1800.

ike 0:test-static-ip:2:test-static-ip:488: IPsec SA selectors #src=1

#dst=1

ike 0:test-static-ip:2:test-static-ip:488: src 0 4 0:0.0.0.0/0.0.0.0:0

ike 0:test-static-ip:2:test-static-ip:488: dst 0 4 0:0.0.0.0/0.0.0.0:0

ike 0:test-static-ip:2:test-static-ip:488: add IPsec SA:

SPIs=4bedab26/eabe7dd1

ike 0:test-static-ip:2:test-static-ip:488: IPsec SA dec spi 4bedab26 key

8:42EC9666448411DE auth 16:603FCCA13E7EC6E5A20FD102252D460A

ike 0:test-static-ip:2:test-static-ip:488: IPsec SA enc spi eabe7dd1 key

8:5EC4791F3276BC53 auth 16:FC1C08919A69755E7396D08F619B52B3

ike 0:test-static-ip:2:test-static-ip:488: added IPsec SA:

SPIs=4bedab26/eabe7dd1

ike 0:test-static-ip:2:test-static-ip:488: sending SNMP tunnel UP trap

ike 0:test-static-ip: link is idle 3 10.10.10.1->10.10.10.2:500 dpd=1

seqno=12d

ike shrank heap by 126976 bytes

ike 0:test-static-ip: link is idle 3 10.10.10.1->10.10.10.2:500 dpd=1

seqno=12e

ike 0:test-static-ip:2: send IKEv1 DPD probe, seqno 302

通过对 Port2 抓包,我们可以看到主模式两端协商时候的报文,如下图所示:

Page 19: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

FGTVM-103 # diagnose sniffer packet port2 'udp and port 500 ' 4

interfaces=[port2]

filters=[udp and port 500 ]

4.773001 port2 -- 10.10.10.2.500 -> 10.10.10.1.500: udp 84

4.774457 port2 -- 10.10.10.1.500 -> 10.10.10.2.500: udp 84

4.774999 port2 -- 10.10.10.2.500 -> 10.10.10.1.500: udp 84

4.780238 port2 -- 10.10.10.1.500 -> 10.10.10.2.500: udp 84

9.788970 port2 -- 10.10.10.2.500 -> 10.10.10.1.500: udp 84

9.791798 port2 -- 10.10.10.1.500 -> 10.10.10.2.500: udp 84

9.792249 port2 -- 10.10.10.2.500 -> 10.10.10.1.500: udp 84

9.796773 port2 -- 10.10.10.1.500 -> 10.10.10.2.500: udp 84

24.663223 port2 -- 10.10.10.2.500 -> 10.10.10.1.500: udp 84

24.665410 port2 -- 10.10.10.1.500 -> 10.10.10.2.500: udp 84

24.665898 port2 -- 10.10.10.2.500 -> 10.10.10.1.500: udp 84

24.671011 port2 -- 10.10.10.1.500 -> 10.10.10.2.500: udp 84

通过查看事件日志,可以看到 IPSec 协商的过程,如下图所示:

Page 20: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

2)当远程网关为拨号用户的时候:

在 CLI 下,打开 VPN Debug 调试开关,在我们第一次选择主模式的时候,在 IPSec

隧道成功建立后,我们可以看到如下的信息,包括野蛮模式第一阶段协商信息,

包含的具体加密和认证算法,第二阶段的协商信息和 DPD 对等体信息:

ike 0:dialup-user:5:dailup-user:2831: responder selectors

0:10.32.1.0/255.255.255.0:0->0:10.30.1.0/255.255.255.0:0

ike 0:dialup-user:5:dailup-user:2831: my proposal:

ike 0:dialup-user:5:dailup-user:2831: proposal id = 1:

ike 0:dialup-user:5:dailup-user:2831: protocol id = IPSEC_ESP:

ike 0:dialup-user:5:dailup-user:2831: PFS DH group = 5

ike 0:dialup-user:5:dailup-user:2831: trans_id = ESP_DES

ike 0:dialup-user:5:dailup-user:2831: encapsulation =

ENCAPSULATION_MODE_TUNNEL

ike 0:dialup-user:5:dailup-user:2831: type = AUTH_ALG, val=MD5

ike 0:dialup-user:5:dailup-user:2831: trans_id = ESP_DES

ike 0:dialup-user:5:dailup-user:2831: encapsulation =

ENCAPSULATION_MODE_TUNNEL

ike 0:dialup-user:5:dailup-user:2831: type = AUTH_ALG, val=SHA1

ike 0:dialup-user:5:dailup-user:2831: incoming proposal:

ike 0:dialup-user:5:dailup-user:2831: proposal id = 1:

ike 0:dialup-user:5:dailup-user:2831: protocol id = IPSEC_ESP:

ike 0:dialup-user:5:dailup-user:2831: PFS DH group = 5

ike 0:dialup-user:5:dailup-user:2831: trans_id = ESP_DES

ike 0:dialup-user:5:dailup-user:2831: encapsulation =

ENCAPSULATION_MODE_TUNNEL

ike 0:dialup-user:5:dailup-user:2831: type = AUTH_ALG, val=MD5

ike 0:dialup-user:5: enc

D482C1C213210D20F6F24AEF0412C16F08102001DAC21B3F00000030000000140E8C3

AFFACBD49F783112574434824EF

Page 21: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

ike 0:dialup-user:5: out

D482C1C213210D20F6F24AEF0412C16F08102001DAC21B3F0000003443FCA3B423486

F1830006298DCDA5D50D8FA4E3B827146C3

ike 0:dialup-user:5: sent IKE msg (quick_i2send):

10.10.10.2:500->10.10.10.1:500, len=52,

id=d482c1c213210d20/f6f24aef0412c16f:dac21b3f

ike 0:dialup-user:5:dailup-user:2831: replay protection enabled

ike 0:dialup-user:5:dailup-user:2831: SA life soft seconds=1777.

ike 0:dialup-user:5:dailup-user:2831: SA life hard seconds=1800.

ike 0:dialup-user:5:dailup-user:2831: IPsec SA selectors #src=1 #dst=1

ike 0:dialup-user:5:dailup-user:2831: src 0 4

0:10.32.1.0/255.255.255.0:0

ike 0:dialup-user:5:dailup-user:2831: dst 0 4

0:10.30.1.0/255.255.255.0:0

ike 0:dialup-user:5:dailup-user:2831: add IPsec SA:

SPIs=eabe7de3/4bedab36

ike 0:dialup-user:5:dailup-user:2831: IPsec SA dec spi eabe7de3 key

8:B70533EA87630DF2 auth 16:4BF44CF1796E4F5103173CCCF9B0BC4E

ike 0:dialup-user:5:dailup-user:2831: IPsec SA enc spi 4bedab36 key

8:3533AAD6ADFDE1FB auth 16:0D577F511C693B2998E84DE8645D148C

ike 0:dialup-user:5:dailup-user:2831: added IPsec SA:

SPIs=eabe7de3/4bedab36

ike 0:dialup-user:5:dailup-user:2831: sending SNMP tunnel UP trap

ike 0:dialup-user: link is idle 3 10.10.10.2->10.10.10.1:500 dpd=1

seqno=2d8

ike 0: comes 10.10.10.1:500->10.10.10.2:500,ifindex=3....

ike 0: IKEv1 exchange=Informational

id=d482c1c213210d20/f6f24aef0412c16f:15a0d12f len=84

ike 0: in

D482C1C213210D20F6F24AEF0412C16F0810050115A0D12F00000054236453B46D650

E6EB7086991354E4DC169C2E0ABE7D7F1F4F48EC93BD47B66A37A7988F19F2CB2C5F9

BF36A095D06F7703C33A6A08A81B5F

ike 0:dialup-user:5: dec

D482C1C213210D20F6F24AEF0412C16F0810050115A0D12F000000540B000014264B8

09DF63F6E18E470930CCEF6697C000000200000000101108D28D482C1C213210D20F6

F24AEF0412C16F0000032FE846B903

ike 0:dialup-user:5: notify msg received: R-U-THERE

ike 0:dialup-user:5: enc

D482C1C213210D20F6F24AEF0412C16F08100501FE004BE7000000500B000014F7492

C06F5E2B19894DD185FB0B06ABD000000200000000101108D29D482C1C213210D20F6

F24AEF0412C16F0000032F

ike 0:dialup-user:5: out

D482C1C213210D20F6F24AEF0412C16F08100501FE004BE700000054C033617A637FE

8743366FC60D369DB23436194B3B52C1BFF2711F2F30254622E3815E9E456B2F225B8

Page 22: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

6F02F1A5AC408775BB4775ADA93657

ike 0:dialup-user:5: sent IKE msg (R-U-THERE-ACK):

10.10.10.2:500->10.10.10.1:500, len=84,

id=d482c1c213210d20/f6f24aef0412c16f:fe004be7

ike 0:dialup-user: link is idle 3 10.10.10.2->10.10.10.1:500 dpd=1

seqno=2d9

ike shrank heap by 126976 bytes

diagnose debug ike 0: comes

10.10.10.1:500->10.10.10.2:500,ifindex=3....

ike 0: IKEv1 exchange=Informational

id=d482c1c213210d20/f6f24aef0412c16f:4d956083 len=84

通过对 Port2 抓包,我们可以看到主模式两端协商时候的报文,如下图所示:

FGTVM-104 # diagnose sniffer packet port2 'udp' 4

interfaces=[port2]

filters=[udp]

2.523345 port2 -- 10.10.10.1.500 -> 10.10.10.2.500: udp 84

2.527325 port2 -- 10.10.10.2.500 -> 10.10.10.1.500: udp 84

7.522805 port2 -- 10.10.10.1.500 -> 10.10.10.2.500: udp 84

7.524831 port2 -- 10.10.10.2.500 -> 10.10.10.1.500: udp 84

7.525277 port2 -- 10.10.10.1.500 -> 10.10.10.2.500: udp 84

7.529951 port2 -- 10.10.10.2.500 -> 10.10.10.1.500: udp 84

42.629151 port2 -- 10.10.10.1.500 -> 10.10.10.2.500: udp 84

42.633953 port2 -- 10.10.10.2.500 -> 10.10.10.1.500: udp 84

47.636196 port2 -- 10.10.10.1.500 -> 10.10.10.2.500: udp 84

47.638191 port2 -- 10.10.10.2.500 -> 10.10.10.1.500: udp 84

47.638614 port2 -- 10.10.10.1.500 -> 10.10.10.2.500: udp 84

Page 23: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

通过查看事件日志,可以看到 IPSec 协商的过程,如下图所示:

5.Debug Flow 使用方法:

常用的 Debug Flow 可以查看为什么流量穿过防火墙,如何去匹配策略,为什么

丢弃,被什么 Policy 阻断,为什么流量穿过 VPN 不通,我们仅仅举个 VPN 的例

子:

FGTVM-103 # diagnose debug flow filter addr 10.30.1.10

FGTVM-103 # diagnose debug flow filter

vf: any

proto: any

host addr: 10.30.1.10-10.30.1.10

Host saddr: any

Host daddr: any

port: any

sport: any

dport: any

FGTVM-103 # diagnose debug flow show console enable

show trace messages on console

FGTVM-103 # diagnose debug flow show function-name enable

show function name

FGTVM-103 # diagnose debug enable

Page 24: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

FGTVM-103 # diagnose debug flow trace start 10

FGTVM-103 # id=36871 trace_id=161 func=resolve_ip_tuple_fast line=3799

msg="vd-root received a packet(proto=17,

10.30.1.10:138->10.30.1.255:138) from port3."

id=36871 trace_id=161 func=resolve_ip_tuple line=3939 msg="allocate a

new session-000016f2"

id=36871 trace_id=161 func=vf_ip4_route_input line=1601 msg="find a

route: gw-10.30.1.255 via root"

id=36871 trace_id=161 func=fw_local_in_handler line=278

msg="iprope_in_check() check failed, drop"

id=36871 trace_id=162 func=resolve_ip_tuple_fast line=3799 msg="vd-root

received a packet(proto=1, 10.30.1.10:512->10.32.1.99:8) from port3."

id=36871 trace_id=162 func=resolve_ip_tuple line=3939 msg="allocate a

new session-000016f3"

id=36871 trace_id=162 func=vf_ip4_route_input line=1601 msg="find a

route: gw-10.10.10.2 via port2"

id=36871 trace_id=162 func=fw_forward_handler line=555 msg="Allowed by

Policy-3: encrypt"

id=36871 trace_id=162 func=ipsec_tunnel_output4 line=818 msg="enter

IPsec tunnel-data-center_0"

id=36871 trace_id=162 func=ipsec_output_finish line=210 msg="send to

10.10.10.2 via intf-port2"

id=36871 trace_id=162 func=esp_output4 line=519 msg="encrypted, and send

to 10.10.10.2 with source 10.10.10.1"

id=36871 trace_id=163 func=resolve_ip_tuple_fast line=3799 msg="vd-root

received a packet(proto=1, 10.32.1.99:512->10.30.1.10:0) from port2."

id=36871 trace_id=163 func=resolve_ip_tuple_fast line=3839 msg="Find an

existing session, id-000016f3, reply direction"

id=36871 trace_id=163 func=vf_ip4_route_input line=1601 msg="find a

route: gw-10.30.1.10 via port3"

id=36871 trace_id=164 func=resolve_ip_tuple_fast line=3799 msg="vd-root

received a packet(proto=1, 10.30.1.10:512->10.32.1.99:8) from port3."

id=36871 trace_id=164 func=resolve_ip_tuple_fast line=3839 msg="Find an

existing session, id-000016f3, original direction"

id=36871 trace_id=164 func=ipsec_tunnel_output4 line=818 msg="enter

IPsec tunnel-data-center_0"

id=36871 trace_id=164 func=ipsec_output_finish line=210 msg="send to

10.10.10.2 via intf-port2"

id=36871 trace_id=164 func=esp_output4 line=519 msg="encrypted, and send

to 10.10.10.2 with source 10.10.10.1"

id=36871 trace_id=165 func=resolve_ip_tuple_fast line=3799 msg="vd-root

Page 25: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

received a packet(proto=1, 10.32.1.99:512->10.30.1.10:0) from port2."

id=36871 trace_id=165 func=resolve_ip_tuple_fast line=3839 msg="Find an

existing session, id-000016f3, reply direction"

id=36871 trace_id=166 func=resolve_ip_tuple_fast line=3799 msg="vd-root

received a packet(proto=1, 10.30.1.10:512->10.32.1.99:8) from port3."

id=36871 trace_id=166 func=resolve_ip_tuple_fast line=3839 msg="Find an

existing session, id-000016f3, original direction"

id=36871 trace_id=166 func=ipsec_tunnel_output4 line=818 msg="enter

IPsec tunnel-data-center_0"

id=36871 trace_id=166 func=ipsec_output_finish line=210 msg="send to

10.10.10.2 via intf-port2"

id=36871 trace_id=166 func=esp_output4 line=519 msg="encrypted, and send

to 10.10.10.2 with source 10.10.10.1"

id=36871 trace_id=167 func=resolve_ip_tuple_fast line=3799 msg="vd-root

received a packet(proto=1, 10.32.1.99:512->10.30.1.10:0) from port2."

id=36871 trace_id=167 func=resolve_ip_tuple_fast line=3839 msg="Find an

existing session, id-000016f3, reply direction"

id=36871 trace_id=168 func=resolve_ip_tuple_fast line=3799 msg="vd-root

received a packet(proto=1, 10.30.1.10:512->10.32.1.99:8) from port3."

id=36871 trace_id=168 func=resolve_ip_tuple_fast line=3839 msg="Find an

existing session, id-000016f3, original direction"

id=36871 trace_id=168 func=ipsec_tunnel_output4 line=818 msg="enter

IPsec tunnel-data-center_0"

id=36871 trace_id=168 func=ipsec_output_finish line=210 msg="send to

10.10.10.2 via intf-port2"

id=36871 trace_id=168 func=esp_output4 line=519 msg="encrypted, and send

to 10.10.10.2 with source 10.10.10.1"

id=36871 trace_id=169 func=resolve_ip_tuple_fast line=3799 msg="vd-root

received a packet(proto=1, 10.32.1.99:512->10.30.1.10:0) from port2."

id=36871 trace_id=169 func=resolve_ip_tuple_fast line=3839 msg="Find an

existing session, id-000016f3, reply direction"

id=36871 trace_id=170 func=resolve_ip_tuple_fast line=3799 msg="vd-root

received a packet(proto=1, 10.30.1.10:512->10.32.1.99:8) from port3."

id=36871 trace_id=170 func=resolve_ip_tuple_fast line=3839 msg="Find an

existing session, id-000016f3, original direction"

id=36871 trace_id=170 func=ipsec_tunnel_output4 line=818 msg="enter

IPsec tunnel-data-center_0"

id=36871 trace_id=170 func=ipsec_output_finish line=210 msg="send to

10.10.10.2 via intf-port2"

id=36871 trace_id=170 func=esp_output4 line=519 msg="encrypted, and send

to 10.10.10.2 with source 10.10.10.1"

id=36871 trace_id=171 func=resolve_ip_tuple_fast line=3799 msg="vd-root

received a packet(proto=1, 10.32.1.99:512->10.30.1.10:0) from port2."

Page 26: FortiGate IPSEC VPN建立和Troubleshooting 版本 1.0 作者 …support.fortinet.com.cn/uploadfile/2015/0527/20150527040541331.pdf · FortigateVM, FortiOS 5.0.11/4.3.18 build0689

6.结束语以及注意事项:

FortiGate 可以通过基于路由的 VPN 或政策。有两类型差别不大。在这两种情况

下,你指定阶段 1和阶段 2的设置。然而在实施的差异。基于路由的 VPN 虚拟网

络接口,采用 IPSec 加密或解密所需的任何交通,它的创建。这就是为什么基于

路由的 VPN 也被称为基于接口的 VPN。一种基于策略的 VPN 是通过一个特殊的安

全策略,将你指定在阶段 1和阶段 2设置加密实现。

对基于路由的 VPN IPSec,你创建的虚拟接口和连接到专用网络接口之间的安全

政策。在一个政策的虚拟接口是源。在其他政策虚拟接口是目的地。对于政策的

作用是接受。这将创建双向政策确保交通将在两个方向在 VPN流量。

基于策略的 VPN,一个安全策略使双向沟通。你必须选择 IPSec作为行动然后选

择你定义在第一阶段设置的 VPN隧道。然后你可以使入站和出站流量在政策需

要,或创建这种类型的多个政策来处理不同类型的交通方式。例如 HTTPS可能

不需要 FTP流量相同的水平扫描

你可以使用 IPSec VPN IPSec 监视器查看活动对隧道和启动或停止那些隧道。该

显示器提供的地址列表,代理 ID 和超时信息,所有活动的隧道,包括隧道模式

和基于路由(接口方式)隧道。

查看 IPSec VPN 监测监控,去 IPSec 监视器。拨号 VPN 拨号客户端列表,提供的

VPN 隧道建立的状态信息,和他们的 IP 地址。静态 IP 或动态 DNS 提供 IP VPN,

列表和解决 VPN 隧道状态信息,主动与否,到远程节点具有静态 IP 地址或域名。

你也可以启动和停止个别隧道从列表。