NEC IX ルータを用いて、AWSとVPN接続をする方法を説明します。AWSのVPNはCisco ASAやFortigateのような有名な機器はサンプル設定が出力されますが、NEC IXの場合はサンプル設定がありません。このような場合は、Cisco ASAなどの他機種のサンプル設定を読み解き、同等設定をNEC IXに投入すれば、AWSとIPsecを確立する事ができます。
動作確認環境
以下の構成で動作確認を行います。

最終的な設定の全文は以下の通りです
AWS側の設定
サービス一覧
サービス一覧の画面から「ネットワーキングとコンテンツ配信」「VPC」を選択します。

VPCとサブネット
「VPC」や「サブネット」を作成します。「VPC」や「サブネット」の作成方法は説明を省略します。

カスタマーゲートウェイ
カスタマーゲートウェイはAWSのインターネット側の設定です。「カスタマーゲートウェイ」を作成します。

「名前」「ルーティング」「IPアドレス」を入力します。「ルーティング」は動的を選び、「IPアドレス」はオンプレミス側のNEC IXに付与されるグローバルIPアドレスを入力します。

NEC IX側でshow ip interfaceコマンドなどを使用し、確かにAWSに投入した設定と一致している事を再確認します。

仮想プライベートゲートウェイ
仮想プライベートゲートウェイはAWSの内向きの設定で、どのVPCと紐づけるかの定義です。「仮想プライベートゲートウェイ」を作成します。

「名前タグ」にわかりやすい名前を入力し、「仮想プライベートゲートウェイの作成」を押下します。

対象の「仮想プライベートゲートウェイ」を選択した状態で、「アクション」「VPCにアタッチ」を選びます。

VPCを選択し、「はい、アタッチします」を押下します。

状態が「attaching」に変わった事を確認します。

サイト間のVPN接続
IPsecに関するパラメタを定義します。最小限の設定ならば、前述の「カスタマーゲートウェイ」と「仮想プライベートゲートウェイ」の紐付けのみです。
「VPNの作成」を押下します。

「名前タグ」「仮想プライベートゲートウェイ」「カスタマーゲートウェイ」を入力します。「仮想プライベートゲートウェイ」「カスタマーゲートウェイ」は前述の設定をプルダウンから選びます。
これ以外のパラメタはデフォルトで差し支えございません。

画面下へとスクロールし、「VPN」の作成を押下します。

「サイト間のVPN接続」の作成後、対象を選択した状態で、「設定のダウンロード」を押下します。

何らかの機種のサンプル設定を見ながら、NEC IXの設定を作成します。NEC IXの設定は例示されていないので、最も多数派と思われるCisco IOSの設定例を参考にしつつ、NEC IXの設定を作成する方法を例示します。
「Cisco Systems, Inc.」「CSRv AMI」「IOS 12.4+」を選択し、「ダウンロード」を押下します。

NEC IXの設定
IPsec Phase 1 (IKE)
Cisco IOSのサンプル設定からIPsec Phase 1に関する設定を読み取ります。Tunnel#1とTunnel#2の2つのトンネルが確立されます。
AWS側のグローバルIPアドレスと事前共有鍵は毎回ランダムに生成されますので、本記事をコピペしないよう注意ください。
crypto isakmp policy 200 encryption aes 128 authentication pre-share group 2 lifetime 28800 hash sha exit ! crypto keyring keyring-vpn-0e88bfbe4ce7ff72a-0 local-address <interface_name/private_IP_on_outside_interface> pre-shared-key address 18.182.91.31 key hngyiJd8N5pulvK9QDMXZ02BDDLCz10K exit ! crypto isakmp profile isakmp-vpn-0e88bfbe4ce7ff72a-0 local-address <interface_name/private_IP_on_outside_interface> match identity address 18.182.91.31 keyring keyring-vpn-0e88bfbe4ce7ff72a-0 exit
crypto isakmp policy 201 encryption aes 128 authentication pre-share group 2 lifetime 28800 hash sha exit ! crypto keyring keyring-vpn-0e88bfbe4ce7ff72a-1 local-address <interface_name/private_IP_on_outside_interface> pre-shared-key address 52.198.204.130 key HDGT8vg_Wvlkte1PKllP26ZK4k1vX8VE exit ! crypto isakmp profile isakmp-vpn-0e88bfbe4ce7ff72a-1 local-address <interface_name/private_IP_on_outside_interface> match identity address 52.198.204.130 keyring keyring-vpn-0e88bfbe4ce7ff72a-1 exit
これに相当するNEC IXの設定は以下の通りです。
IKEのプロポーザルはCiscoのサンプル設定に合わせていますが、実はAWSのデフォルト設定は殆どのパラメタで動くようになっています。初期設定では、例えばAWS側のフェーズ1暗号化アルゴリズムはAES128, AES256, AES128-GCM-16, AES256-GCM-16で交渉しますので、NEC IX側はほぼ全ての設定でAWSとネゴシエートする事ができます。もし、これがセキュアでないと思うならば、AWS側の設定をより堅牢に変更する事も可能です。
ike proposal ike-prop encryption aes hash sha group 1024-bit ! ike policy ike-policy1 peer 18.182.91.31 key hngyiJd8N5pulvK9QDMXZ02BDDLCz10K ike-prop ike policy ike-policy2 peer 52.198.204.130 key HDGT8vg_Wvlkte1PKllP26ZK4k1vX8VE ike-prop
IPsec Phase 2
Cisco IOSのサンプル設定からIPsec Phase 2に関する設定を読み取ります。トンネルに付与されるIPアドレスは毎回ランダムに生成されますので、本記事をコピペしないよう注意ください。
crypto ipsec transform-set ipsec-prop-vpn-0e88bfbe4ce7ff72a-0 esp-aes 128 esp-sha-hmac mode tunnel exit ! crypto ipsec profile ipsec-vpn-0e88bfbe4ce7ff72a-0 set pfs group2 set security-association lifetime seconds 3600 set transform-set ipsec-prop-vpn-0e88bfbe4ce7ff72a-0 exit ! interface Tunnel1 ip address 169.254.128.174 255.255.255.252 ip virtual-reassembly tunnel source <interface_name/private_IP_on_outside_interface> tunnel destination 18.182.91.31 tunnel mode ipsec ipv4 tunnel protection ipsec profile ipsec-vpn-0e88bfbe4ce7ff72a-0 ! This option causes the router to reduce the Maximum Segment Size of ! TCP packets to prevent packet fragmentation. ip tcp adjust-mss 1379 no shutdown exit
crypto ipsec transform-set ipsec-prop-vpn-0e88bfbe4ce7ff72a-1 esp-aes 128 esp-sha-hmac mode tunnel exit ! crypto ipsec profile ipsec-vpn-0e88bfbe4ce7ff72a-1 set pfs group2 set security-association lifetime seconds 3600 set transform-set ipsec-prop-vpn-0e88bfbe4ce7ff72a-1 exit ! interface Tunnel2 ip address 169.254.251.134 255.255.255.252 ip virtual-reassembly tunnel source <interface_name/private_IP_on_outside_interface> tunnel destination 52.198.204.130 tunnel mode ipsec ipv4 tunnel protection ipsec profile ipsec-vpn-0e88bfbe4ce7ff72a-1 ! This option causes the router to reduce the Maximum Segment Size of ! TCP packets to prevent packet fragmentation. ip tcp adjust-mss 1379 no shutdown exit
これに相当するNEC IXの設定は以下の通りです。
IPsecのプロポーザルはCiscoのサンプル設定に合わせていますが、実はAWSのデフォルト設定は殆どのパラメタで動くようになっています。
ip access-list sec-list permit ip src any dest any ! ipsec autokey-proposal ipsec-prop esp-aes esp-sha lifetime time 3600 ! ipsec autokey-map ipsec-map1 sec-list peer 18.182.91.31 ipsec-prop pfs 1024-bit ipsec autokey-map ipsec-map2 sec-list peer 52.198.204.130 ipsec-prop pfs 1024-bit ! interface Tunnel0.0 tunnel mode ipsec ip address 169.254.128.174/30 ip tcp adjust-mss auto ipsec policy tunnel ipsec-map1 df-bit ignore pre-fragment out no shutdown ! interface Tunnel1.0 tunnel mode ipsec ip address 169.254.251.134/30 ip tcp adjust-mss auto ipsec policy tunnel ipsec-map2 df-bit ignore pre-fragment out no shutdown
IPsec phase1 (IKE)のsa(security association)が成功している事を確認します。
nec-ix01(config)# show ike sa ISAKMP SA - 2 configured, 2 created Local address is 42.144.XX.XX, port is 500 Remote address is 18.182.91.31, port is 500 IKE policy name is ike-policy1 Direction is initiator Initiator's cookie is 0x06b07ec7b7de4ad4 Responder's cookie is 0x517402b244c97ffc Exchange type is main mode State is established Authentication method is pre-shared Encryption algorithm is aes-128 Hash algorithm is sha1 DH group is modp1024, lifetime is 25933 seconds #ph1 success: 1, #ph1 failure: 0 #ph1 hash err: 0, #ph1 timeout: 0, #ph1 resend: 0 #ph2 success: 1, #ph2 failure: 0 #ph2 hash err: 0, #ph2 timeout: 0, #ph2 resend: 0 Local address is 42.144.XX.XX, port is 500 Remote address is 52.198.204.130, port is 500 IKE policy name is ike-policy2 Direction is initiator Initiator's cookie is 0xf8ec59e5f88c6cf3 Responder's cookie is 0xde52144e1da66f15 Exchange type is main mode State is established Authentication method is pre-shared Encryption algorithm is aes-128 Hash algorithm is sha1 DH group is modp1024, lifetime is 25942 seconds #ph1 success: 1, #ph1 failure: 0 #ph1 hash err: 0, #ph1 timeout: 0, #ph1 resend: 0 #ph2 success: 1, #ph2 failure: 0 #ph2 hash err: 0, #ph2 timeout: 0, #ph2 resend: 0
IPsec phase2 のsa(security association)が成功している事を確認します。
nec-ix01(config)# show ipsec sa
IPsec SA - 2 configured, 4 created
Interface is Tunnel0.0
Key policy map name is ipsec-map1
Tunnel mode, 4-over-4, autokey-map
Local address is 42.144.XX.XX
Remote address is 18.182.91.31
Outgoing interface is GigaEthernet0.0
Interface MTU is 1438, path MTU is 1500
Inbound:
ESP, SPI is 0x5678373f(1450719039)
Transform is ESP-AES-128-HMAC-SHA-96
Remaining lifetime is 725 seconds
Replay detection support is on
Outbound:
ESP, SPI is 0xc7e05214(3353367060)
Transform is ESP-AES-128-HMAC-SHA-96
Remaining lifetime is 725 seconds
Replay detection support is on
Perfect forward secrecy is 1024-bit
Interface is Tunnel1.0
Key policy map name is ipsec-map2
Tunnel mode, 4-over-4, autokey-map
Local address is 42.144.XX.XX
Remote address is 52.198.204.130
Outgoing interface is GigaEthernet0.0
Interface MTU is 1438, path MTU is 1500
Inbound:
ESP, SPI is 0x5d2a7bbe(1563065278)
Transform is ESP-AES-128-HMAC-SHA-96
Remaining lifetime is 734 seconds
Replay detection support is on
Outbound:
ESP, SPI is 0xc80d5094(3356315796)
Transform is ESP-AES-128-HMAC-SHA-96
Remaining lifetime is 734 seconds
Replay detection support is on
Perfect forward secrecy is 1024-bit
トンネルの対向へpingが届く事を確認します。
nec-ix01(config)# ping 169.254.128.173 count 3 PING 169.254.128.174 > 169.254.128.173 56 data bytes 64 bytes from 169.254.128.173: icmp_seq=0 ttl=254 time=25.558 ms 64 bytes from 169.254.128.173: icmp_seq=1 ttl=254 time=46.619 ms 64 bytes from 169.254.128.173: icmp_seq=2 ttl=254 time=21.361 ms --- 169.254.128.173 ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip (ms) min/avg/max = 21.361/31.179/46.619 nec-ix01(config)# nec-ix01(config)# nec-ix01(config)# ping 169.254.251.133 count 3 PING 169.254.251.134 > 169.254.251.133 56 data bytes 64 bytes from 169.254.251.133: icmp_seq=0 ttl=254 time=17.906 ms 64 bytes from 169.254.251.133: icmp_seq=1 ttl=254 time=27.189 ms 64 bytes from 169.254.251.133: icmp_seq=2 ttl=254 time=43.732 ms --- 169.254.251.133 ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip (ms) min/avg/max = 17.906/29.609/43.732 nec-ix01(config)#
IPsecのチューニング
IPsecのその他チューニングのパラメタを確認します。Cisco IOSには以下のようなチューニングが施されています。
crypto ipsec df-bit clear ! crypto isakmp keepalive threshold 10 retry 10 ! crypto ipsec security-association replay window-size 128 ! crypto ipsec fragmentation before-encryption
必須設定ではないですが、可能な限り真似してみます。
ike keepalive ike-policy1 10 10 ike keepalive ike-policy2 10 10
BGP
Cisco IOSのサンプル設定からBGPに関する設定を読み取ります。何をadvertiseするかは環境依存の所が大きかと思いますので、コピペしないよう注意ください
router bgp 65000
neighbor 169.254.128.173 remote-as 64512
neighbor 169.254.128.173 activate
neighbor 169.254.128.173 timers 10 30 30
address-family ipv4 unicast
neighbor 169.254.128.173 remote-as 64512
neighbor 169.254.128.173 timers 10 30 30
neighbor 169.254.128.173 default-originate
neighbor 169.254.128.173 activate
neighbor 169.254.128.173 soft-reconfiguration inbound
! To advertise additional prefixes to Amazon VPC, copy the 'network' statement
! and identify the prefix you wish to advertise. Make sure the prefix is present
! in the routing table of the device with a valid next-hop.
network 0.0.0.0
exit
exit
router bgp 65000
neighbor 169.254.251.133 remote-as 64512
neighbor 169.254.251.133 activate
neighbor 169.254.251.133 timers 10 30 30
address-family ipv4 unicast
neighbor 169.254.251.133 remote-as 64512
neighbor 169.254.251.133 timers 10 30 30
neighbor 169.254.251.133 default-originate
neighbor 169.254.251.133 activate
neighbor 169.254.251.133 soft-reconfiguration inbound
! To advertise additional prefixes to Amazon VPC, copy the 'network' statement
! and identify the prefix you wish to advertise. Make sure the prefix is present
! in the routing table of the device with a valid next-hop.
network 0.0.0.0
exit
exit
どのようなprefixをNEC IXからAWSへadvertiseするかは環境依存かと思いますので、環境に応じて適宜の変更をお願いします。設定例は以下の通りです。
router bgp 65000
neighbor 169.254.128.173 remote-as 64512
neighbor 169.254.128.173 timers 10 30
neighbor 169.254.251.133 remote-as 64512
neighbor 169.254.251.133 timers 10 30
address-family ipv4 unicast
originate-default always
network 192.168.1.0/24
BGP neighborを確立できた事を確認します。また、AWSからprefixを受信できた事を確認します。
nec-ix01(config)# show ip route
IP Routing Table - 6 entries, 2 hidden, 2040 frees
Entries: 4 Connected, 1 Static, 0 RIP, 0 OSPF, 1 BGP
Codes: C - Connected, S - Static, R - RIP, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, B - BGP
* - Candidate default, s - Summary
Timers: Age
S* 0.0.0.0/0 [0/1] via 42.144.40.1, GigaEthernet0.0, 1:29:30
42.0.0.0/8 is subnetted, 1 subnets
C 42.144.40.0/22 [0/1] is directly connected, GigaEthernet0.0, 1:29:30
169.254.0.0/16 is subnetted, 2 subnets
C 169.254.128.172/30 [0/1] is directly connected, Tunnel0.0, 0:08:48
C 169.254.251.132/30 [0/1] is directly connected, Tunnel1.0, 0:08:48
B 172.31.0.0/16 [20/100] via 169.254.128.173, Tunnel0.0, 0:08:36
C 192.168.1.0/24 [0/1] is directly connected, GigaEthernet1.0, 1:29:34
NEC IXからAWSへprefixをadvertiseしている事を確認します。
nec-ix01(config)# show ip bgp neighbors 169.254.128.173 advertised-routes
BGP table version is 3, local router ID is 192.168.1.1
Local AS number 65000
Status codes: s - suppressed, * - valid, h - history
> - best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Path
*> 0.0.0.0/0 169.254.128.174 0 i
*> 192.168.1.0/24 169.254.128.174 1 i
Total number of prefixes 2
疎通確認
疎通確認のため、AWS側にEC2インスタンスを起動させます。

EC2インスタンスへのpingとtracerouteが可能である事を確認します。
[root@entrance010 ~]# ifconfig ens192
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::1254:6fcf:19ab:dee5 prefixlen 64 scopeid 0x20<link>
ether 00:50:56:b7:9e:43 txqueuelen 1000 (Ethernet)
RX packets 412 bytes 38160 (37.2 KiB)
RX errors 0 dropped 16 overruns 0 frame 0
TX packets 262 bytes 38616 (37.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@entrance010 ~]# ping 172.31.20.154 -c 3
PING 172.31.20.154 (172.31.20.154) 56(84) bytes of data.
64 bytes from 172.31.20.154: icmp_seq=2 ttl=253 time=50.1 ms
64 bytes from 172.31.20.154: icmp_seq=3 ttl=253 time=238 ms
--- 172.31.20.154 ping statistics ---
3 packets transmitted, 2 received, 33% packet loss, time 2000ms
rtt min/avg/max/mdev = 50.165/144.380/238.595/94.215 ms
[root@entrance010 ~]# traceroute 172.31.20.154
traceroute to 172.31.20.154 (172.31.20.154), 30 hops max, 60 byte packets
1 gateway (192.168.1.1) 0.581 ms 0.544 ms 0.500 ms
2 * * *
3 172.31.20.154 (172.31.20.154) 44.957 ms 44.829 ms *
[root@entrance010 ~]#
