兩個 AWS 實例之間的 Strongswan VPN 隧道無法連接

兩個 AWS 實例之間的 Strongswan VPN 隧道無法連接

我正在嘗試使用 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

(簡單)拓撲如下:

[ 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 (這是來自俄勒岡州,但在弗吉尼亞北部實例上是相同的,只是左|右值相反)

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 更新然後 ipsec 重新啟動

5)嘗試在confif設定下新增nat_traversal = yes(請注意,這應該不重要,因為ipsec狀態均使用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時,它不需要我對每個實例的路由表進行任何手動修改。

以下是俄勒岡州 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)我沒有正確遵循邁克爾的配置說明。我還將 rightsourceip 和 leftsourceip 配置在一起,從而使兩個實例都相信它們都是發起者。我確保一個是發起者,一個是請求者;這解決了 IKE 問題。

2)我發現我還必須明確設定 esp 參數。即使已經有預設值 (aes128-sha1,3des-sha1),仍然需要設定 esp 參數,以便實例知道使用 esp 或 ah(但不能同時使用兩者)。我最後使用了 aes128-sha1-modp2048。

希望這篇文章可以幫助下一個 Linux 新手進行設定!

乾杯!

編輯#4:問題(沒有真正)解決

在對與 Strongswan 相關的單獨問題進行故障排除時,我更改了“leftfirewall”參數,進行了測試,但沒有修復我的單獨問題,然後預先恢復到原始配置(註釋掉 leftfirewall)。然後我注意到我現在無法 ping 通隧道。在瘋狂地花了幾個小時試圖弄清楚發生了什麼之後,我註解掉了 esp 參數,看看會發生什麼:我現在可以再次 PING 穿過隧道! <- 所以,有可能有一些 ipsec 幽靈在對我耍花招,並且 esp 參數並不是真正修復 TS_UNACCEPTABLE 錯誤(儘管其他在線資源指出 esp 參數是修復...)

編輯#5:問題完全解決

我最終將所有內容都轉移到測試環境中並從頭開始。我使用最新版本(5.3.2)而不是 Ubuntu 儲存庫中的舊版本(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"

答案1

在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

答案2

問題已解決。

1)我沒有正確遵循邁克爾的配置說明。我還將 rightsourceip 和 leftsourceip 配置在一起,從而使兩個實例都相信它們都是發起者。我確保一個是發起者,一個是請求者;這解決了 IKE 問題。

2)我發現我還必須明確設定 esp 參數。即使已經有預設值 (aes128-sha1,3des-sha1),仍然需要設定 esp 參數,以便實例知道使用 esp 或 ah(但不能同時使用兩者)。我最後使用了 aes128-sha1-modp2048。

相關內容