NEC IX2015とAmazon EC2インスタンスをIPsecトンネルモードで接続してみました。ほぼ自分用の備忘録なんですが、不備などご指摘いただけると嬉しいです。
IX2015は動的IPのPPPoEに接続されています。EC2側のみ固定IPを確保できるため、IX2015からEC2に向かって接続します。EC2側の環境は以下です。
- Amazon Linux
- Openswan U2.6.27/K2.6.34.7-56.40.amzn1.x86_64 (netkey)
- sudo yum install openswanでインストール
- セキュリティグループで udp/500, udp/4500 を許可する
IX2015とOpenswanの両者がサポートしているパラメータを選択する必要があります。IX2015とOpenswanで省略時のデフォルト値が異なるため、明示的に指定した方がよいと思います。今回は以下の組み合わせで検証しています。
- IKE
- Authentication method is pre-shared
- Encryption algorithm is aes-128
- Hash algorithm is sha1
- DH group is modp1024
- IPsec
- Transform is ESP-AES-128-HMAC-SHA-96
IX2015では DH Group 1 (768bit) がデフォルトで選択されますが、Openswanではサポートされていないようです。明示的に DH Group 2 (1024bit) を選択する必要があります。他のビット長は検証していないので分かりません。
IX2015の設定
関連するコンフィグを抜粋します。
- 175.41.a.b はEC2インスタンスのグローバルIP(Elastic IP)です。
- 10.146.x.y はEC2インスタンスのプライベートIPです。
- 172.16.3.0/24はIX2015が属しているプライベートネットワークです。
ip route 10.146.x.y/32 Tunnel0.0 ip access-list ipsec-list permit ip src any dest any ike proposal ikeprop encryption aes hash sha group 1024-bit ike suppress-dangling ike policy ike-policy peer 175.41.a.b key-type secret 1 key ******** ikeprop ike keepalive ike-policy 30 6 ike nat-traversal policy ike-policy keepalive 30 ipsec autokey-proposal secprop esp-aes esp-sha ipsec autokey-map ipsec-policy ipsec-list peer 175.41.a.b secprop pfs 1024-bit ipsec local-id ipsec-policy 172.16.3.0/24 ipsec remote-id ipsec-policy 10.146.x.y interface FastEthernet0/0.1 encapsulation pppoe auto-connect ppp binding isp ip address ipcp ip tcp adjust-mss auto ip napt enable no shutdown interface Tunnel0.0 description ec2-ipsec tunnel mode ipsec ip unnumbered FastEthernet0/0.1 ip tcp adjust-mss auto ipsec policy tunnel ipsec-policy out no shutdown
ネゴシエーションの失敗はログで確認できます。また、show ike sa、show ipsec saでセキュリティアソシエーションを確認できます。
Openswanの設定
# /etc/ipsec.conf - Openswan IPsec configuration file
version 2.0
config setup
protostack=netkey
nat_traversal=yes
conn ec2ipsec
type=tunnel
authby=secret
auth=esp
ike=aes-sha1
phase2alg=aes-sha1
keyexchange=ike
pfs=yes
left=10.146.x.y
leftid=175.41.a.b
leftsubnet=10.146.x.y/32
right=%any
rightsubnet=172.16.3.0/24
auto=add
$ sudo /etc/init.d/ipsec start $ sudo ipsec verify Checking your system to see if IPsec got installed and started correctly: Version check and ipsec on-path [OK] Linux Openswan U2.6.27/K2.6.34.7-56.40.amzn1.x86_64 (netkey) Checking for IPsec support in kernel [OK] NETKEY detected, testing for disabled ICMP send_redirects [OK] NETKEY detected, testing for disabled ICMP accept_redirects [OK] Checking that pluto is running [OK] Pluto listening for IKE on udp 500 [OK] Pluto listening for NAT-T on udp 4500 [OK] Two or more interfaces found, checking IP forwarding [OK] Checking NAT and MASQUERADEing [N/A] Checking for 'ip' command [OK] Checking for 'iptables' command [OK] Opportunistic Encryption Support [DISABLED]
現時点で分かっている課題
EC2からはIX2015が属しているプライベートネットワーク(rightsubnet)にしかアクセスできません。ルーティングが入っていないためです。Openswanが確立したトンネルへのルートはkernelのルーティングテーブルに現れないため、追加する方法が分かりません。ip xfrm policyとか使えるのかな。
トンネルが途中で切れないか等は未確認です。