Ipsec

嘗試將有效的 IPSec/L2TP 配置從 OpenSWAN 複製到 StrongSWAN

  • July 23, 2014

我有一個適用於 RA 的 OpenSWAN 實施,使用 IPsec 傳輸和 l2tp 作為隧道,在 AWS 中執行。該實例有一個私有 IP,一個公共 EIP 映射到它。

left我對andleftsubnet參數使用私有 ip,在leftid.

我現在正在嘗試配置從同一客戶端到執行 StrongSWAN (4.5.2) 的新端點的 IPSec 連接。我試圖盡可能地將配置從 openswan 複製到 strongswan。目前,我只是嘗試設置 IPSec(還不擔心 l2tp),並且在第 2 階段遇到問題(第 1 階段完成正常)。

配置上的區別是:

--- openswan.conf       2014-07-18 11:48:01.740966015 +0200
+++ strongswan.conf     2014-07-18 11:46:58.927569703 +0200
@@ -1,11 +1,14 @@
+version 2.0
+
config setup
-       protostack=netkey
+       charonstart=no
+       interfaces="%none"
       nat_traversal=yes
-       virtual_private=%v4:192.168.10.0/24
       oe=off
-       nhelpers=0
-       interfaces=%defaultroute
+       virtual_private="%v4:192.168.11.0/24"
+
+conn %default
+       keyexchange=ikev1

conn remote-access
       forceencaps=yes
       type=transport
       ike=3des-sha1
-       phase2alg=3des-sha1

當我從客戶端建立連接時,我得到以下資訊:

003 "myconn" #1: NAT-Traversal: Result using RFC 3947 (NAT-Traversal): both are NATed
108 "myconn" #1: STATE_MAIN_I3: sent MI3, expecting MR3
004 "myconn" #1: STATE_MAIN_I4: ISAKMP SA established {auth=OAKLEY_PRESHARED_KEY cipher=aes_128 prf=oakley_sha group=modp2048}
117 "myconn" #2: STATE_QUICK_I1: initiate

並在伺服器日誌中

"remote-access"[3] 105.1.1.1 #2: NAT-Traversal: Result using RFC 3947: both are NATed
"remote-access"[3] 105.1.1.1 #2: Peer ID is ID_IPV4_ADDR: '192.168.2.2'
"remote-access"[4] 105.1.1.1 #2: deleting connection "remote-access" instance with peer client.ip.addr {isakmp=#0/ipsec=#0}
"remote-access"[4] 105.1.1.1:4500 #2: sent MR3, ISAKMP SA established
"remote-access"[4] 105.1.1.1:4500 #2: cannot respond to IPsec SA request because no connection is known for 54.1.1.1/32===10.0.0.2:4500[54.1.1.1]:17/1701...105.1.1.1.1:4500[192.168.2.2]:17/%any==={192.168.2.2/32}
"remote-access"[4] 105.1.1.1:4500 #2: sending encrypted notification INVALID_ID_INFORMATION to 105.1.1.1:4500

192.168.2.2 是客戶端的私有 IP,105.1.1.1 是它通過 NAT 轉換到的公共 IP。

我搜尋了“無法響應 IPsec SA 請求,因為沒有已知的連接”,並且只在https://lists.strongswan.org/pipermail/users/2011-July/001885.html找到了與 strongswan 相關的 1 個,以及這個,但這些建議都不起作用(在對等方上調整 rightid 或在 strongswan 伺服器上添加 leftsourceip)。

我連接到 strongswan 的對等/客戶端是 libreswan 3.7

編輯這裡的配置

EC中的StrongSWAN:

conn remote-access authby=secret pfs=no left=10.0.0.2 leftid=54..1.1.1 leftsubnet=10.0.0.2/32 leftnexthop=%defaultroute leftprotoport=17/1701 right=%any rightid=%any rightsubnetwithin=0.0.0.0/0 rightprotoport=17/%any type=transport forceencaps=yes auto=add ike=3des-sha1 dpddelay=15 dpdtimeout=45 dpdaction=clear auth=esp esp=aes256-sha1,3des-sha1!

此主機上的機密文件:

54.1.1.1 %any : PSK "XXX"

我的本地 RA 客戶端配置:

conn myconn authby=secret pfs=no rekey=yes keyingtries=3 type=transport left=%defaultroute leftprotoport=17/1701 right=54.1.1.1 rightprotoport=17/1701 auto=add phase2=esp phase2alg=3des-md5;modp1024 forceencaps=yes

秘密:

0.0.0.0 %any 54.1.1.1 : PSK "XXX"

我最近在本地客戶端上添加了 phase2 參數和 forceencaps。

前面顯示的差異在我連接到的 2 個基於 EC2 的主機之間。“myconn”連接來自我的工作站,我有 2 個 conns,1 個用於 openswan 對等體(有效),一個副本用於 strongswan 對等體(無效)。我認為對左/右配置使用相同的方法會產生有效的配置。

這是使用 openswan 的工作配置。一些影響此配置工作的參數正在使用rightsubnetwithinphase2alg(phase2alg 可以根據需要進行調整,我最初使用的是 3des-sha1,但後來調整了)。

範例配置

/etc/ipsec.conf

config setup
   plutostderrlog= "/var/log/pluto.err"
   protostack=netkey
   nat_traversal=yes
   virtual_private=%v4:192.168.10.0/24
   oe=off
   nhelpers=0
   interfaces=%defaultroute

conn remote-access
   auto=add
   left=10.0.0.2
   leftid=54.1.1.1
   leftsubnet=10.0.0.2/32
   leftnexthop=%defaultroute
   leftprotoport=17/1701
   rightprotoport=17/%any
   right=%any
   rightid=%any
   rightsubnetwithin=0.0.0.0/0
   forceencaps=yes
   authby=secret
   pfs=no
   type=transport
   auth=esp
   ike=3des-sha1
   phase2alg=3des-sha1
   dpdaction=clear
   dpddelay=60
   dpdtimeout=500

/etc/ipsec.secrets

54.1.1.1 %any : PSK "Your_PSK"

這讓 IPSec 傳輸起來。

引用自:https://serverfault.com/questions/613589