lob*_*obi 11 vpn ipsec amazon-web-services strongswan ubuntu-14.04
我正在尝试使用 StrongSwan 5.1.2 在运行 Ubuntu 14.04.2 LTS 的两个 Amazon AWS EC2 实例之间设置 VPN 隧道。在使用 StrongSwan 之前,我在 Amazon RedHat AMI 上使用了 open(libre)swan,效果很好。出于某种原因,我什至无法让 IKE 在这里为 StrongSwan 工作。我三重检查了我的 AWS 配置,一切看起来都很好,所以一定是 StrongSwan 配置有问题。
正如您将在下面看到的,我得到的错误是“写入套接字时出错:参数无效”。我在网上看过,真的找不到解决方案。我确信我的 strongswan ipsec.conf 配置不正确。
这是我正在使用的内容:
Instance #1: N.Virginia - 10.198.0.164 with public EIP 54.X.X.X
Instance #2: Oregon - 10.194.0.176 with public EIP 52.Y.Y.Y
Run Code Online (Sandbox Code Playgroud)
(简单)拓扑如下:
[ Instance #1 within N.Virginia VPC <-> Public internet <-> Instance #2 within Oregon VPC ]
Run Code Online (Sandbox Code Playgroud)
我验证了以下 AWS 配置是正确的:
Security groups permit all
IP information is correct
Src/Dest disabled on both instances
ACLs permit all
routes are present and correct (route to 10.x will point to that local instance in order to be routed out to the VPN tunnel)
Run Code Online (Sandbox Code Playgroud)
下面是/etc/ipsec.conf (这是来自俄勒冈州,但它在 N.Virginia 实例上是相同的,除了 left|right 值相反):
config setup
charondebug="dmn 2, mgr 2, ike 2, chd 2, job 2, cfg 2, knl 2, net 2, enc 2, lib 2"
conn aws1oexternal-aws1nvexternal
left=52.Y.Y.Y (EIP)
leftsubnet=10.194.0.0/16
right=54.X.X.X (EIP)
rightsubnet=10.198.0.0/16
auto=start
authby=secret
type=tunnel
mobike=no
dpdaction=restart
Run Code Online (Sandbox Code Playgroud)
下面是 /etc/ipsec.secrets *(显然,其他实例相反):
54.X.X.X 52.Y.Y.Y : PSK "Key_inserted_here"
Run Code Online (Sandbox Code Playgroud)
下面是/etc/strongswan.conf:
charon {
load_modular = yes
plugins {
include strongswan.d/charon/*.conf
}
}
Run Code Online (Sandbox Code Playgroud)
下面是/etc/sysctl.conf:
net.ipv4.ip_forward=1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
Run Code Online (Sandbox Code Playgroud)
这是 /var/log/syslog 的调试输出似乎这里的问题是“写入套接字时出错:参数无效;在我尝试了所有操作之后,我继续遇到相同的错误:
Jun 17 17:34:48 ip-10-198-0-164 charon: 13[IKE] retransmit 5 of request with message ID 0
Jun 17 17:34:48 ip-10-198-0-164 charon: 13[NET] sending packet: from 54.X.X.X[500] to 52.Y.Y.Y[500] (1212 bytes)
Jun 17 17:34:48 ip-10-198-0-164 charon: 03[JOB] next event in 75s 581ms, waiting]
Jun 17 17:34:48 ip-10-198-0-164 charon: 16[NET] sending packet: from 54.X.X.X[500] to 52.Y.Y.Y[500]
Jun 17 17:34:48 ip-10-198-0-164 charon: 13[MGR] checkin IKE_SA aws1vexternal-aws1oexternal[1]
Jun 17 17:34:48 ip-10-198-0-164 charon: 13[MGR] check-in of IKE_SA successful.
Jun 17 17:34:48 ip-10-198-0-164 charon: 16[NET] error writing to socket: Invalid argument
Jun 17 17:36:04 ip-10-198-0-164 charon: 03[JOB] got event, queuing job for execution
Jun 17 17:36:04 ip-10-198-0-164 charon: 03[JOB] no events, waiting
Jun 17 17:36:04 ip-10-198-0-164 charon: 08[MGR] checkout IKE_SA
Jun 17 17:36:04 ip-10-198-0-164 charon: 08[MGR] IKE_SA aws1vexternal-aws1oexternal[1] successfully checked out
Jun 17 17:36:04 ip-10-198-0-164 charon: 08[IKE] giving up after 5 retransmits
Jun 17 17:36:04 ip-10-198-0-164 charon: 08[IKE] establishing IKE_SA failed, peer not responding
Jun 17 17:36:04 ip-10-198-0-164 charon: 08[MGR] checkin and destroy IKE_SA aws1vexternal-aws1oexternal[1]
Jun 17 17:36:04 ip-10-198-0-164 charon: 08[IKE] IKE_SA aws1vexternal-aws1oexternal[1] state change: CONNECTING => DESTROYING
Jun 17 17:36:04 ip-10-198-0-164 charon: 08[MGR] check-in and destroy of IKE_SA successful
Run Code Online (Sandbox Code Playgroud)
以下是我迄今为止尝试过的:
1) 已验证的第 3 层
2)重启机器
3) 尝试添加 leftid=
4)尝试做ipsec更新然后ipsec重启
5) 尝试在 confif 设置下添加 nat_traversal=yes (注意这应该无关紧要,因为 ipsec statusall 使用 IKEv2 验证,根据文档自动使用 nat_traversal)
6) 尝试省略 virtual_private <-- 根据 AWS openswan 文档使用,因此我将其包含在 strongswan 配置中。
7) 尝试在 /etc/sysctl.conf 中禁用 net.ipv4.conf.all.send_redirects = 0 和 net.ipv4.conf.all.accept_redirects = 0
8) 尝试使用私有 IP 而不是 EIP。我不再收到套接字错误,但是显然这两个 IP 无法相互通信以进行对等...
9) 尝试将其添加到 strongswan.conf:load = aes des sha1 sha2 md5 gmp random nonce hmac stroke kernel-netlink socket-default updown
10) 尝试使用 leftfirewall=yes,没有用
请帮忙!谢谢!
迈克尔的回答清除了原来的问题,但是我有一个与路由相关的新问题。两个VPN实例都无法互相ping通。此外,当我尝试从任一子网中的随机实例 ping 到另一个随机实例或远端 VPN 实例时,我得到以下 ping 响应:
root@ip-10-194-0-80:~# ping 10.198.0.164
PING 10.198.0.164 (10.198.0.164) 56(84) bytes of data.
From 10.194.0.176: icmp_seq=1 Redirect Host(New nexthop: 10.194.0.176)
From 10.194.0.176: icmp_seq=2 Redirect Host(New nexthop: 10.194.0.176)
From 10.194.0.176: icmp_seq=3 Redirect Host(New nexthop: 10.194.0.176)
From 10.194.0.176: icmp_seq=4 Redirect Host(New nexthop: 10.194.0.176)
Run Code Online (Sandbox Code Playgroud)
显然,这肯定是两个 VPN 实例之间的路由问题(最有可能是由于 strongswan 配置或实例路由表),因为俄勒冈子网中的 10.194.0.80 主机能够接收来自俄勒冈 VPN 实例的响应。实例上的路由表 + traceroute:
root@ip-10-194-0-80:~# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.194.0.1 0.0.0.0 UG 0 0 0 eth0
10.194.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
root@ip-10-194-0-80:~# traceroute 10.198.0.164
traceroute to 10.198.0.164 (10.198.0.164), 30 hops max, 60 byte packets
1 10.194.0.176 (10.194.0.176) 0.441 ms 0.425 ms 0.409 ms^C
Run Code Online (Sandbox Code Playgroud)
当我使用 openswan 时,它不需要我对每个实例的路由表进行任何手动修改。
这是俄勒冈 VPN 实例的路由表:
root@ip-10-194-0-176:~# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.194.0.1 0.0.0.0 UG 0 0 0 eth0
10.194.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
Run Code Online (Sandbox Code Playgroud)
我有点难住了。
看起来 VPN 实例之间的路由可能不是问题:/var/log/syslog 显示从一个 VPN 实例公共 IP 接收到另一个 VPN 实例的数据包
Jun 23 19:57:49 ip-10-194-0-176 charon: 10[NET] received packet: from 54.X.X.X[4500] to 10.194.0.176[4500] (76 bytes)
Run Code Online (Sandbox Code Playgroud)
看起来这是一个与儿童安全协会有关的问题:
aws1oexternal-aws1nvexternal: child: 10.194.0.0/16 === 10.198.0.0/16 TUNNEL, dpdaction=restart
Security Associations (1 up, 0 **connecting**):
Run Code Online (Sandbox Code Playgroud)
/var/log/syslog:
Jun 23 19:52:19 ip-10-194-0-176 charon: 02[IKE] failed to establish CHILD_SA, keeping IKE_SA
Jun 23 19:52:48 ip-10-194-0-176 charon: 11[IKE] queueing CHILD_CREATE task
Jun 23 19:52:48 ip-10-194-0-176 charon: 11[IKE] activating CHILD_CREATE task
Jun 23 19:52:48 ip-10-194-0-176 charon: 06[IKE] establishing CHILD_SA aws1oexternal-aws1nvexternal
Jun 23 19:52:48 ip-10-194-0-176 charon: 10[IKE] received FAILED_CP_REQUIRED notify, no CHILD_SA built
Jun 23 19:52:48 ip-10-194-0-176 charon: 10[IKE] failed to establish CHILD_SA, keeping IKE_SA
Jun 23 19:52:49 ip-10-194-0-176 charon: 14[CFG] looking for a child config for 10.194.0.0/16 === 10.198.0.0/16
Jun 23 19:52:49 ip-10-194-0-176 charon: 14[CFG] found matching child config "aws1oexternal-aws1nvexternal" with prio 10
Jun 23 19:52:49 ip-10-194-0-176 charon: 14[IKE] configuration payload negotiation failed, no CHILD_SA built
Jun 23 19:52:49 ip-10-194-0-176 charon: 14[IKE] failed to establish CHILD_SA, keeping IKE_SA
Run Code Online (Sandbox Code Playgroud)
问题已解决。
1)我没有正确遵循迈克尔的配置说明。我还一起配置了 rightsourceip 和 leftsourceip,从而使两个实例都相信它们都是发起者。我确保一个是发起者,一个是请求者;这解决了 IKE 问题。
2)我发现我还必须明确设置 esp 参数。即使已经有一个默认值 (aes128-sha1,3des-sha1),仍然必须设置 esp 参数,以便实例知道使用 esp OR ah(但不能同时使用两者)。我最终使用了 aes128-sha1-modp2048。
希望这篇文章能帮助下一个 Linux 新手设置它!!
干杯!
在解决与 strongswan 相关的单独问题时,我更改了“leftfirewall”参数,经过测试,没有解决我的单独问题,然后事先恢复到原始配置(注释掉了 leftfirewall)。然后我注意到我现在无法ping通隧道。在疯狂了几个小时试图弄清楚发生了什么之后,我注释掉了 esp 参数,看看会发生什么:我现在可以再次穿越隧道!<- 所以,有可能有一些 ipsec 幽灵在我身边玩弄伎俩,而且 esp 参数并不是真正解决 TS_UNACCEPTABLE 错误的方法(尽管其他在线资源表明 esp 参数是解决方法...)
我最终将所有内容都移到了测试环境中并从头开始。我使用最新版本 (5.3.2) 而不是 Ubuntu 存储库 (5.1.2) 中的旧版本从源代码安装。这解决了我在上面遇到的问题,并在 VPN 隧道上的多个子网之间使用 netcat(很棒的工具!!)验证了第 7 层连接。
另外:这是不是需要启用了DNS VPC主机名(因为我是不正确导致亚马逊相信),FYI>
希望这一切有帮助!!!!!!!
2017 年 2 月 11 日附加编辑:
根据 JustEngland 的要求,复制以下工作配置(省略某些细节以防止以任何方式识别):
A面:
# ipsec.conf - strongSwan IPsec configuration file
# basic configuration
config setup
# Add connections here.
conn %default
ikelifetime= You choose; must match other side
keylife= You choose; must match other side
rekeymargin= You choose; must match other side
keyingtries=1
keyexchange= You choose; must match other side
authby=secret
mobike=no
conn side-a
left=10.198.0.124
leftsubnet=10.198.0.0/16
leftid=54.y.y.y
leftsourceip=10.198.0.124
right=52.x.x.x
rightsubnet=10.194.0.0/16
auto=start
type=tunnel
# Add connections here.
root@x:~# cat /etc/ipsec.secrets
A.A.A.A B.B.B.B : PSK "Your Password"
Run Code Online (Sandbox Code Playgroud)
B面:
# ipsec.conf - strongSwan IPsec configuration file
# basic configuration
config setup
conn %default
ikelifetime= You choose; must match other side
keylife= You choose; must match other side
rekeymargin= You choose; must match other side
keyingtries=1
keyexchange= You choose; must match other side
authby=secret
mobike=no
conn side-b
left=10.194.0.129
leftsubnet=10.194.0.0/16
leftid=52.x.x.x
right=54.y.y.y
rightsubnet=10.198.0.0/16
rightsourceip=10.198.0.124
auto=start
type=tunnel
root@x:~# cat /etc/ipsec.secrets
B.B.B.B A.A.A.A : PSK "Your Password"
Run Code Online (Sandbox Code Playgroud)
在 VPC 中,实例的公网 IP 地址永远不会绑定到实例的堆栈,因此您必须同时配置内部私有地址和外部公有地址。该无效参数的可能是通过直接从公网IP地址,这是不知道您的实例试图源交通造成的。
left=10.10.10.10 # instance private IP of local system
leftsourceip=10.10.10.10 # instance private IP of local system
leftid=203.x.x.x # elastic IP of local system
leftsubnet=10.x.x.x/xx
rightsubnet=10.x.x.x/xx
right=198.x.x.x # elastic IP of remote system
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13408 次 |
最近记录: |