Strongswan搭建IPSecVPN

概述:

Strongswan是一款开源的IPSecVPN解决方案,支持ikev1和ikev2密钥交换协议。

场景:

在StrongSwan的官网上提供了很多测试场景,依次点击官网TestScenarios->The strongSwan test suites,即可查看(点击直接访问)。
列表中我们选择ike最新版本ikev2,在本文中我们对工作中最常使用的net2net-psknet2net-rsa进行实验模拟。

基本环境搭建:

根据拓扑图搭建实验环境,配置IP地址保证基本联通性。需要注意一点,网关moon和sun需要开启路由转发功能ip_forward

安装Strongswan:

可以选择源码编译安装或者使用apt/yum仓库进行安装:

Copy
apt install strongswan -y #Debian/ubuntu,本文使用ubuntu16.04 yum install strongswan -y #Centos
配置Strongswan:
Copy
相关端口:udp:500 udp:4500 相关配置文件: /etc/ipsec.conf #IPsec配置文件 /etc/ipsec.secret #密钥认证配置文件 /etc/ipsec.d #用于存放认证证书等文件 /etc/strongswan.conf #Strongswan配置文件 /etc/strongswan.d #Strongswan子配置文件 相关管理命令: ipsec start/stop/restart/reload #启动/停止/重启/重载 Daemon; ipsec up/down <connection name> #建立/断开 指定conn链接; ipsec status/statusall/listall #IPsec相关查看命令;
配置net2net-psk

配置网关moonsunipsec.confipsec.secretsstrongswan.conf这三个配置文件<参考官网测试场景net2net-psk>:

Copy
########## Strongswan配置文件说明,以网关moon为例 ########## # /etc/ipsec.conf - strongSwan IPsec configuration file config setup conn %default #设定所有链接默认配置; ikelifetime=60m #设定ISAKMP/IKE SA重新协商时间 keylife=20m # rekeymargin=3m keyingtries=1 authby=secret #设定认证方法,secret和psk都是预共享密钥认证; keyexchange=ikev2 #设定密钥交换协议 mobike=no conn net-net #自定义conn链接 left=192.168.0.1 leftsubnet=10.1.0.0/16 leftid=@moon.strongswan.org leftfirewall=yes #自动在iptables的forward链中增加规则 right=192.168.0.2 rightsubnet=10.2.0.0/16 rightid=@sun.strongswan.org auto=add #add载入conn但不启动,route载入conn并安装kernel—traps同样不启动,start载入并启动,ignore忽略此conn; # /etc/ipsec.secrets - strongSwan IPsec secrets file @moon.strongswan.org @sun.strongswan.org : PSK 0sv+NkxY9LLZvwj4qCC2o/gGrWDF2d21jL @moon.strongswan.org %any : PSK 0x45a30759df97dc26a15b88ff @sun.strongswan.org : PSK "This is a strong password" : PSK 'My "home" is my "castle"!' 192.168.0.1 : PSK "Andi's home" # /etc/strongswan.conf - strongSwan configuration file charon { load = random nonce aes sha1 sha2 curve25519 hmac stroke kernel-netlink socket-default updown multiple_authentication = no }
Copy
root@fw1-moon:~# iptables -nvL {leftfirewall=yes 不加也能通并且私网地址} Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 ACCEPT all -- eth0 * 10.2.0.0/24 10.1.0.0/24 policy match dir in pol ipsec reqid 2 proto 50 0 0 ACCEPT all -- * eth0 10.1.0.0/24 10.2.0.0/24 policy match dir out pol ipsec reqid 2 proto 50 root@fw1-moon:~# ip route show table 220 10.2.0.0/24 via 192.168.0.2 dev eth0 proto static src 10.1.0.1
配置net2net-rsa
posted @   Beavan  阅读(7252)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示