admin管理员组

文章数量:1530847

2024年7月26日发(作者:)

FGT与Strongswan建立IPSEC VPN

FGT与Strongswan建立IPSEC VPN

版本

时间

作者

状态

V1

2020 年 4月

王祥

FGT与Strongswan建立IPSEC VPN

目录

1.

网络拓扑 ................................................................................................................................. 3

2.

设备版本 ................................................................................................................................. 3

3.

在Centos7上安装Strongswan .............................................................................................. 3

4.

Strongswan配置 ..................................................................................................................... 4

4.1.

4.2.

4.3.

4.4.

4.5.

4.6.

特别说明 .......................................................................................................................... 4

Strongswan配置 .............................................................................................................. 5

几个参数介绍 .................................................................................................................. 7

Strongswan日志 .............................................................................................................. 8

系统配置 ........................................................................................................................ 10

启动Strongswan服务 ................................................................................................... 11

5.

FGT配置 ................................................................................................................................ 12

6.

状态检查 ............................................................................................................................... 14

7.

Strongswan日志查看 ........................................................................................................... 15

FGT与Strongswan建立IPSEC VPN

1. 网络拓扑

拓扑说明:

FGT 访问 Strongswan时,NAT Gateway做源NAT;

NAT Gateway同时映射了FGT port1接口udp 500和4500端口给Strongswan;

2. 设备版本

FortiGate: v6.2.7

Strongswan:v5.7.2

3. 在Centos7上安装Strongswan

安装epel源:yum install epel-release

安装strongswan:yum install strongswan

安装完成查看Strongswan版本

Strongswan更新的版本可通过官网下载,然后源码安装

Strongswan官网:/

Strongswan参数参考:/projects/strongswan/wiki/Swanctlconf

FGT与Strongswan建立IPSEC VPN

4. Strongswan配置

4.1. 特别说明

1. 上述截图出处:

/projects/strongswan/wiki/UserDocumentation

2. 当使用swanctl和starter时,需要的配置文件是完全不同的;

3. 当使用swanctl时,启动的服务是strongswan-swanctl;使用starter时,启动服务

是strongswan;

4. 向配置迁移:

/projects/strongswan/wiki/Fromipsecconf

5. 本文后续配置均是基于swanctl。

FGT与Strongswan建立IPSEC VPN

4.2. Strongswan配置

Strongswan配置参数:

/projects/strongswan/wiki/Swanctlconf

或者man

Strongswan配置用例:

/projects/strongswan/wiki/UsableExamples

从配置可以看从strongswan会读取当前conf.d目录下以.conf结尾的配

置文件

[root@localhost ~]# grep -Ev '#|^$' /etc/strongswan/swanctl/

include conf.d/*.conf

新建配置文件:

vim /etc/strongswan/swanctl/conf.d/

connections {

#IPSEC名称

vpn1 {

#IKE版本,1表示IKEv1,2表示IKEv2

version = 1

#本地IPSEC VPN地址

local_addrs = 192.168.90.39

#对端IPSEC VPN地址

remote_addrs = 192.168.90.37

#IPSEC阶段一加密集

proposals = aes128-sha1-modp2048

# 野蛮模式yes,主动模式no,默认是no

aggressive = yes

#dpd检测间隔

dpd_delay = 5s

#DPD检测超时时间

dpd_timeout = 15s

#本地认证

local{

#认证方式:psk 预共享秘钥

auth = psk

#本地id

FGT与Strongswan建立IPSEC VPN

id = 192.168.90.39

}

# 对端认证

remote{

#对端id

id = 192.168.91.32

auth = psk

}

#IPSEC阶段二设置

children {

#阶段二名称,如果有多条感兴趣流,可以写多个,如vpn2{xxx}

vpn1 {

#阶段二加密集

esp_proposals = aes128-sha1-modp2048

#本地感兴趣流

local_ts = 192.16.2.0/24

#对端感兴趣流

remote_ts = 192.16.1.0/24

#IPSEC隧道模式

mode = tunnel

# 当dpd检测失败时会立即重新发起IKE协商

dpd_action = restart

#当加载配置时执行的动作

start_action = trap

}

}

}

}

#秘钥设置

secrets {

# IKE preshared secret section for a specific secret.

ike-vpn1 {

#共享秘钥的值

secret = "fortinet"

#该共享秘钥属于谁,如果id为空或者id = %any,表示匹配所有

id = 192.168.91.32

}

}

FGT与Strongswan建立IPSEC VPN

4.3. 几个参数介绍

start_action:当加载配置时执行的动作

默认none:被动模式,流量不能出发协商;

trap:流量可以触发协商,当对端主动断开后,流量依然可以出发协商;

start:当启动服务时主动发起协商,但当对端主动断开后,不会再发起协商,流

量也不会触发协商;

手动发起IPSEC协商命令:swanctl --initiate --child (阶段二的名称)

local{

id = 192.168.90.39 #本地ID

}

remote{

id = 192.168.91.32 #对端ID

}

secrets {

ike-vpn1 {

#该共享秘钥属于谁

id = 192.168.91.32

}

}

id即IPSEC中的身份,默认是通过IP地址标识;

如果在有NAT的环境下,设备的IP地址是会转换,因此可以指定id,如

id=192.168.91.32;

也可以使用fqnd类型,如fqdn:test1;同样对端也要设置对应的类型和id,若 id = %any

表示可以匹配所有。

ike-vpn1是secrets中的一组秘钥,其中设置的id要合remote中的id对应,才能匹

配的上;若id为空或者id = %any,表示匹配所有。

FGT与Strongswan建立IPSEC VPN

4.4. Strongswan日志

日志设置参考:

man 中LOGGER CONFIGURATION章节;

vim /etc/strongswan/

在charon{}中添加设置文件日志,如果不配置,默认日志会输出到/var/log/messages

charon {

#filelog是关键字,定义类型日志

filelog {

#名称

charon {

#日志文件名称

path = /var/log/

# 日志时间格式

time_format = %b %e %T

# 日志中显示ike名称

ike_name = yes

# 是否覆盖日志文件

append = no

# 默认的日志级别

default = 1

# 刷新每一行到硬盘

flush_line = yes

# 定义更高的子类日志级别,覆盖default对应子类的值

cfg = 4

ike = 2

}

}

}

FGT与Strongswan建立IPSEC VPN

日志级别:/projects/strongswan/wiki/LoggerConfiguration

FGT与Strongswan建立IPSEC VPN

4.5. 系统配置

关闭防火墙

systemctl stop firewalld

systemctl disable firewalld

关闭Selinux:

[root@localhost ~]# setenforce 0 #临时关闭

[root@localhost ~]# getenforce #查看Selinux状态

Permissive

永久关闭Selinux:

vim /etc/selinux/config

[root@localhost ~]# grep dis /etc/selinux/config

# disabled - No SELinux policy is loaded.

SELINUX=disabled

如果不关闭Selinux,Strongswan启动将无法启动。

转发相关

cat >> /etc/ << EOF

## 开启转发

_forward=1

ding=1

## 禁止重定向,比如禁止ICMP重定向报文

_redirects = 0

_redirects = 0

EOF

sysctl –p

FGT与Strongswan建立IPSEC VPN

4.6. 启动Strongswan服务

启动strongswan服务,并使其开机启动

[root@localhost ~]# systemctl start strongswan-swanctl

[root@localhost ~]# systemctl enable strongswan-swanctl

FGT与Strongswan建立IPSEC VPN

5. FGT配置

配置IPSEC

config vpn ipsec phase1-interface

edit "to-strongswan"

set interface "port1"

set mode aggressive

set peertype any

set net-device disable

set proposal aes128-sha1

#如果strongswan指定了id和id-类型,FGT端也要明确指定

set localid-type address

set auto-negotiate disable

set dpd on-idle

set dpd-retrycount 3

set dpd-retryinterval 5

set dhgrp 14

set remote-gw 192.168.90.39

set psksecret fortinet

next

end

config vpn ipsec phase2-interface

edit "to-strongswan"

set phase1name "to-strongswan"

set proposal aes128-sha1

set replay disable

set src-subnet 192.16.1.0 255.255.255.0

set dst-subnet 192.16.2.0 255.255.255.0

next

end

配置策略

config firewall policy

edit 1

set name "test1"

set srcintf "port2"

set dstintf "to-strongswan"

set srcaddr "all"

set dstaddr "all"

set action accept

FGT与Strongswan建立IPSEC VPN

set schedule "always"

set service "ALL"

next

edit 2

set name "test2"

set srcintf "to-strongswan"

set dstintf "port2"

set srcaddr "all"

set dstaddr "all"

set action accept

set schedule "always"

set service "ALL"

next

end

配置路由

config router static

edit 1

set dst 192.16.3.0 255.255.255.0

set device "to-strongswan"

next

end

FGT与Strongswan建立IPSEC VPN

6. 状态检查

FGT IPSEC状态

Strongswan IPSEC状态

IKEv1 主模式/野蛮模式,IKEv2测试都能正常建立连接。

但是,Strongswan使用野蛮模式 PSK认证提示不安全,默认不允许建立连接。

需要在vim /etc/strongswan/中添加如下选项:

i_dont_care_about_security_and_use_aggressive_mode_psk = yes

FGT与Strongswan建立IPSEC VPN

7. Strongswan日志查看

通过tail -f /var/log/观察IPSEC日志信息输出,来判断IPSEC的问题

①当发给Strongswan加密集不一致时,其日志信息

②当身份id不匹配时,其日志信息:

③当共享秘钥不匹配时,其日志信息:

④当感兴趣流不匹配时,其日志信息:

本文标签: 日志配置协商