阿里云ECS Ubuntu StrongSwan对接 FortiGate s2s vpn:NAT-T 下 IPsec VPN安装对接步骤
技术  /  管理员 发布于 1小时前   4
背景: 公司app要对接一个非洲的支付平台业务, 对接他们的支付接口需要先对接他们的s2s vpn,他们还发来一个用于网络配置的已填写的 VPN 表单呢
我方架构: 香港阿里云ecs Ubuntu 20.4
开始安装:
公共前置:安装 strongswan + 开启内核 IP 转发 + iptables 主机侧规则
# 安装依赖包sudo apt updatesudo apt install strongswan libcharon-extra-plugins libstrongswan-extra-plugins iptables-persistent -y
# 开启内核IP转发sudo sysctl -w net.ipv4.ip_forward=1sudo sysctl -w net.ipv6.conf.all.forwarding=0
# 写入sysctl永久配置
sudo tee -a /etc/sysctl.conf <<EOF
net.ipv4.ip_forward = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
EOF
sudo sysctl -p
# iptables追加规则(追加不会中断现有API)
sudo iptables -A INPUT -p udp --dport 500 -s 41.223.132.146 -j ACCEPT
sudo iptables -A INPUT -p udp --dport 4500 -s 41.223.132.146 -j ACCEPT
sudo iptables -A INPUT -p esp -s 41.223.132.146 -j ACCEPT
sudo iptables -A FORWARD -s 172.23.8.234/32 -d 10.28.99.0/24 -j ACCEPT
sudo iptables -A FORWARD -s 10.28.99.0/24 -d 172.23.8.234/32 -j ACCEPT
# 保存iptables持久化
sudo netfilter-persistent save
ps:
阿里云ecs Ubuntu, 我这里是系统内防火墙是关闭的,
所以直接配置阿里云的安全组就可以了
# 启动strongswan-startersudo systemctl start strongswan-starter
sudo systemctl enable strongswan-starter
编写配置文件,(根据你发给对接方的vpn网络信息,对方会添加好, 对方也会给你发来一个预共享密钥)
/etc/ipsec.conf
/etc/ipsec.secrets
ps: 具体配置自行了解
# 加载配置sudo ipsec reload
# 拉起隧道sudo ipsec up sokagte-s2s
# 查看隧道状态sudo ipsec statusall
测试效果 (我这用telnet, ping对方禁止了)~# telnet 10.28.99.163 8280Trying 10.28.99.163...Connected to 10.28.99.163.Escape character is '^]'.HTTP/1.1 400 Bad requestConnection: CloseDate: Fri, 30 Oct 2026 01:30:41 GMTContent-Length: 0Connection closed by foreign host.
ps:
**结论:VPN 隧道完全正常!**
`telnet 10.28.99.163 8280` 拿到了 HTTP 400 返回,说明:
1. IPsec 加密转发成功
2. Fortigate 策略放行成功
3. 目标机器 `10.28.99.163` 的 **8280 端口服务正常监听并且响应成功
> 400 Bad Request 只是 HTTP 协议报错:telnet 直接发空数据给 Web 服务,服务识别不是合法 HTTP 请求,返回 400,**不是网络不通**。
监听:~# sudo tcpdump -i eth0 -n udp port 4500tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes09:30:41.195886 IP 172.23.8.234.4500 > 41.223.132.146.4500: UDP-encap: ESP(spi=0x7881f163,seq=0x8), length 120
ps:
**现在状态:业务流量已经成功加密进隧道了!**
抓包出现 `UDP-encap: ESP`,代表:
- 你的 `telnet 10.28.99.163 8280` 流量已经被 strongSwan 封装成 ESP、通过 NAT-T(udp/4500)发给 Fortigate
- 并且 **对端 Fortigate 有 ESP 回包发回来**(双向 ESP 都看到了)
在试一下curl, 成功后就可以对接对方的api了~# curl -v [http://10.28.99.163:8280/](http://10.28.99.163:8280/)- Trying 10.28.99.163:8280...- TCP_NODELAY set- Connected to 10.28.99.163 (10.28.99.163) port 8280 (#0)> > GET / HTTP/1.1> Host: 10.28.99.163:8280> User-Agent: curl/7.68.0> Accept: */*- Mark bundle as not supporting multiuse< HTTP/1.1 404 Not Found< Content-Type: application/xml; charset=UTF-8< Date: Fri, 30 Oct 2026 01:36:03 GMT< Transfer-Encoding: chunked<- Connection #0 to host 10.28.99.163 left intact
ps:
这条 curl 结果实锤:
**VPN 隧道、TCP 连通、应用层全部正常通了!**
test1 在
opencode + Oh-my-openagent,我的第一个免费的ai编程智能体管家:Sisyphus中评论 test..122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..Zita 在
Google AI Studio升级全栈 vibe coding体验,可直接构建带登录和数据库的应用中评论 111222..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号
