我试图在运行Ubuntu 14.04.2 LTS的两个Amazon AWS EC2实例之间使用StrongSwan 5.1.2build立VPN隧道。 在使用StrongSwan之前,我在Amazon RedHat AMI上使用了open(libre)swan,它运行良好。 出于某种原因,我甚至无法让IKE在StrongSwan上class。 我三重检查了我的AWSconfiguration,这一切都看起来不错,所以这一定是StrongSwanconfiguration的问题。
正如你将看到下面,我得到的错误是“错误写入套接字:无效的参数” 。 我在网上看了,真的找不到解决办法。 我确信我的strongswan ipsec.confconfiguration不正确。
以下是我正在处理的内容:
Instance #1: N.Virginia - 10.198.0.164 with public EIP 54.XXX Instance #2: Oregon - 10.194.0.176 with public EIP 52.YYY
(简单)拓扑结构如下所示:
[ Instance #1 within N.Virginia VPC <-> Public internet <-> Instance #2 within Oregon VPC ]
我validation了以下AWSconfiguration是正确的:
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)
下面是/etc/ipsec.conf (这是来自俄勒冈州,但是在N.Virginia实例上是一样的,除了左边的值是相反的) :
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.YYY (EIP) leftsubnet=10.194.0.0/16 right=54.XXX (EIP) rightsubnet=10.198.0.0/16 auto=start authby=secret type=tunnel mobike=no dpdaction=restart
下面是/etc/ipsec.secrets *(对于其他实例,显然是相反的):
54.XXX 52.YYY : PSK "Key_inserted_here"
以下是/etc/strongswan.conf:
charon { load_modular = yes plugins { include strongswan.d/charon/*.conf } }
下面是/etc/sysctl.conf:
net.ipv4.ip_forward=1 net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.all.send_redirects = 0
这里是从/ var / log / syslog的debugging输出看来这里的问题是“错误写入套接字:无效的参数;我尝试了一切后,我继续得到这个相同的错误 :
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.XXX[500] to 52.YYY[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.XXX[500] to 52.YYY[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
以下是我迄今为止所尝试的:
1)validation图层3
2)重新启动机器
3)尝试添加leftid =
4)尝试执行ipsec更新,然后ipsec重新启动
5)尝试在confif setup下添加nat_traversal = yes(注意,这应该不重要,因为使用IKEv2validationipsec statusall,根据文档自动使用nat_traversal)
6)尝试省略virtual_private < – 根据AWS openswan文档使用,所以我将其包含在strongswanconfiguration中。
7)尝试禁用/etc/sysctl.conf中的net.ipv4.conf.all.send_redirects = 0和net.ipv4.conf.all.accept_redirects = 0
8)试图使用私有IP而不是EIPs。 我不再收到套接字错误,但显然这两个IP不能互相通信对等…
9)尝试添加到strongswan.conf中:load = aes des sha1 sha2 md5 gmp random nonce hmac stroke kernel-netlink socket-default updown
10)尝试使用leftfirewall =是的,没有工作
请帮忙! 谢谢!
迈克尔的回应清除了原来的问题,但是我有一个与路由有关的新问题。 两个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)
显然,这必须是两个VPN实例之间的路由问题(很可能是由于strongswanconfiguration或实例路由表),因为俄勒冈子网中的10.194.0.80主机能够接收来自Oregon 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
当我使用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
我有点难住。
看起来像VPN实例之间的路由可能不是问题:/ var / log / syslog显示从一个VPN实例公共IP到另一个VPN实例
Jun 23 19:57:49 ip-10-194-0-176 charon: 10[NET] received packet: from 54.XXX[4500] to 10.194.0.176[4500] (76 bytes)
看起来这是一个与儿童安全协会有关的问题:
aws1oexternal-aws1nvexternal: child: 10.194.0.0/16 === 10.198.0.0/16 TUNNEL, dpdaction=restart Security Associations (1 up, 0 **connecting**):
在/ 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
问题修复了。
1)我没有正确地遵循迈克尔的configuration方向。 我还一起configuration了一个rightsourceip和leftsourceip,从而导致两个实例都认为它们都是发起者。 我确保了一个是发起者,一个是请求者。 这固定了IKE问题。
2)我发现我也必须明确地设置esp参数。 即使已经有一个默认的(aes128-sha1,3des-sha1),esp参数仍然需要设置,以便实例知道使用esp或ah(但不是两者)。 我结束了使用aes128-sha1-modp2048。
希望这张贴有助于下一个Linux新手设置了这一点!
干杯!
在解决与strongswan相关的一个单独问题的同时,我更改了“leftfirewall”参数,经过testing,没有解决我的单独问题,然后又恢复到原始configuration(注释掉了leftfirewall)。 然后我注意到我现在无法穿越隧道。 经过几个小时的疯狂试图弄清楚发生了什么事情之后,我将esp参数注释掉,看看会发生什么事情:我现在可以重新穿越隧道了! < – 所以,有可能有一些ipsec的鬼魂在我身上玩耍的技巧,并且esp参数不是真正的TS_UNACCEPTABLE错误的修复(虽然其他资源在线状态esp参数是修复…)
我最终将所有的东西都转移到了testing环境中,从头开始。 我使用最新版本(5.3.2)从源代码安装,而不是Ubuntu回购(5.1.2)中的旧版本。 这清除了我在上面的问题,并通过VPN隧道在多个子网之间使用netcat(伟大的工具!!)validation了第7层连接。
另外:不需要为VPC启用DNS主机名(因为我错误地被亚马逊相信),FYI>
希望这一切都可以帮助!!!!!!
其他编辑2/11/2017:
根据JustEngland的要求,请复制下面的工作configuration(不提供某些细节以防止以任何方式进行识别):
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.yyy leftsourceip=10.198.0.124 right=52.xxx rightsubnet=10.194.0.0/16 auto=start type=tunnel # Add connections here. root@x:~# cat /etc/ipsec.secrets AAAA BBBB : PSK "Your Password"
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.xxx right=54.yyy rightsubnet=10.198.0.0/16 rightsourceip=10.198.0.124 auto=start type=tunnel root@x:~# cat /etc/ipsec.secrets BBBB AAAA : PSK "Your Password"
在VPC中,实例的公有IP地址永远不会绑定到实例的堆栈,所以您必须configuration内部专用地址和外部公用地址。 无效的参数大概是由于尝试直接从您的实例未知的公共IP地址获取stream量而引起的。
left=10.10.10.10 # instance private IP of local system leftsourceip=10.10.10.10 # instance private IP of local system leftid=203.xxx # elastic IP of local system leftsubnet=10.xxx/xx rightsubnet=10.xxx/xx right=198.xxx # elastic IP of remote system
问题修复了。
1)我没有正确地遵循迈克尔的configuration方向。 我还一起configuration了一个rightsourceip和leftsourceip,从而导致两个实例都认为它们都是发起者。 我确保了一个是发起者,一个是请求者。 这固定了IKE问题。
2)我发现我也必须明确地设置esp参数。 即使已经有一个默认的(aes128-sha1,3des-sha1),esp参数仍然需要设置,以便实例知道使用esp或ah(但不是两者)。 我结束了使用aes128-sha1-modp2048。