AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 699741
Accepted
lobi
lobi
Asked: 2015-06-18 10:04:30 +0800 CST2015-06-18 10:04:30 +0800 CST 2015-06-18 10:04:30 +0800 CST

两个 AWS 实例之间的 Strongswan VPN 隧道无法连接

  • 772

我正在尝试在两个运行 Ubuntu 14.04.2 LTS 的 Amazon AWS EC2 实例之间使用 StrongSwan 5.1.2 设置 VPN 隧道。在使用 StrongSwan 之前,我在 Amazon RedHat AMI 上使用了 open(libre)swan,效果很好。出于某种原因,我什至无法让 IKE 在这里为 StrongSwan 工作。我三次检查了我的 AWS 配置,一切看起来都不错,所以肯定是 StrongSwan 配置有问题。

正如您将在下面看到的,我得到的错误是"Error writing to socket: Invalid argument"。我在网上看了,真的找不到解决办法。我确信我的 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

(简单)拓扑如下:

[ Instance #1 within N.Virginia VPC <-> Public internet <-> Instance #2 within Oregon VPC ]

我验证了以下 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)

下面是/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.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

下面是 /etc/ipsec.secrets *(显然,对于其他实例相反):

54.X.X.X 52.Y.Y.Y : 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 的调试输出这里的问题似乎是“错误写入套接字:无效参数;在我尝试了一切之后,我继续得到同样的错误:

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

以下是我迄今为止尝试过的:

1) 已验证的第 3 层

2)重新启动的机器

3) 尝试添加 leftid=

4) 尝试进行 ipsec update 然后 ipsec restart

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,没用

请帮忙!谢谢!

编辑#1:

迈克尔的回复清除了原来的问题,但是我有一个与路由相关的新问题。两个 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 实例之间的路由问题(很可能是由于 strongswan 配置或实例路由表),因为俄勒冈子网中的 10.194.0.80 主机能够接收来自俄勒冈 VPN 实例的响应。路由表 + 实例上的跟踪路由:

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 时,它不需要我对每个实例的路由表进行任何手动修改。

这是 Oregon 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

我有点难过。

编辑#2:

看起来 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)

看起来这是与儿童安全协会有关的问题:

aws1oexternal-aws1nvexternal:   child:  10.194.0.0/16 === 10.198.0.0/16 TUNNEL, dpdaction=restart
Security Associations (1 up, 0 **connecting**):

/var/log/系统日志:

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

***编辑#3:问题已解决(嗯,实际上请参见下面的编辑#4...)****

问题已解决。

1) 我没有正确遵循 Michael 的配置说明。我还一起配置了 rightsourceip 和 leftsourceip,从而使两个实例都认为它们都是发起者。我确保一个是发起者,一个是请求者;这解决了 IKE 问题。

2)我发现我还必须明确设置 esp 参数。即使已经有默认值(aes128-sha1,3des-sha1),仍然必须设置 esp 参数,以便实例知道使用 esp OR ah(但不能同时使用两者)。我最终使用了 aes128-sha1-modp2048。

希望这篇文章能帮助下一个 linux 新手设置它!

干杯!

编辑#4:问题(不是真的)解决了

在对与 strongswan 相关的单独问题进行故障排除时,我更改了“leftfirewall”参数,经过测试,没有解决我的单独问题,然后预先恢复到 orig 配置(注释掉 leftfirewall)。然后我注意到我现在无法ping通隧道。在疯狂了几个小时试图弄清楚发生了什么之后,我注释掉了 esp 参数以查看会发生什么:我现在可以再次 PING Across the TUNNEL!<- 所以,有可能有一些 ipsec 鬼在我身上跑来跑去,并且 esp 参数并不是真正修复 TS_UNACCEPTABLE 错误的方法(尽管其他在线资源表明 esp 参数是修复...)

编辑#5:问题完全解决

我最终将所有内容都转移到了测试环境中,并从头开始。我使用最新版本(5.3.2)而不是Ubuntu repo(5.1.2)中的旧版本从源代码安装。这解决了我上面遇到的问题,并使用 netcat(很棒的工具!!)在 VPN 隧道上的多个子网之间验证了第 7 层连接。

另外:不需要为 VPC 启用 DNS 主机名(因为我被亚马逊错误地误导),仅供参考>

希望这一切都有帮助!!!!!!!

附加编辑 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"

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"
vpn
  • 2 2 个回答
  • 15109 Views

2 个回答

  • Voted
  1. Best Answer
    Michael - sqlbot
    2015-06-18T16:53:54+08:002015-06-18T16:53:54+08:00

    在 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
    
    • 8
  2. lobi
    2015-06-26T11:11:08+08:002015-06-26T11:11:08+08:00

    问题已解决。

    1) 我没有正确遵循 Michael 的配置说明。我还一起配置了 rightsourceip 和 leftsourceip,从而使两个实例都认为它们都是发起者。我确保一个是发起者,一个是请求者;这解决了 IKE 问题。

    2)我发现我还必须明确设置 esp 参数。即使已经有默认值(aes128-sha1,3des-sha1),仍然必须设置 esp 参数,以便实例知道使用 esp OR ah(但不能同时使用两者)。我最终使用了 aes128-sha1-modp2048。

    • 1

相关问题

  • 无法通过 Ubuntu VPN 访问外部网络

  • 用 D-LINK DFL-CPG310 防火墙替换 Cisco Pix 防火墙

  • 最好的点对点 VPN?

  • WAN 上的 VLAN

  • 通过 VPN 连接什么是远程服务器 IP?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve