NEC IXとAWSの接続(プライベートIPアドレス編)

スポンサーリンク

NEC IX ルータを用いて、AWSとVPN接続をする方法を説明します。AWSはグローバルIPアドレスを持つ機器のサンプル設定を提供していますが、工夫すればプライベートIPアドレスを持つ機器とIPsecを確立する事もできます。

動作確認環境

以下の構成で動作確認を行います。AWS側のグローバルIPアドレスはsite-to-site VPN作成時にランダムに生成されます。

+------------------+   +------------------+
|        AWS       |   |        AWS       |
+---------+--------+   +---------+--------+
          | 34.217.232.61        | 54.69.109.228
          |                      |
          +----------+-----------+
                     | 
                     | 
                 (internet)
                     | 
                     | 203.165.211.85
           +---------+--------+ 
           |     NAT Router   | 
           +---------+--------+
                     | .1
                     |
                     | 192.168.1.0/24
                     |
                G0.0 | .10
           +---------+--------+ 
           |    NEC IX 2015   | 
           |        R10       | 
           +---------+--------+
                G1.0 | .1 
                     |
                     | 192.168.2.0/24
                     | 

最終的な設定の全文は以下の通りです

IX2215
[final]
! NEC Portable Internetwork Core Operating System Software
! IX Series IX2105 (magellan-sec) Software, Version 8.10.11, RELEASE SOFTWARE
! Compiled Aug 02-Fri-2013 13:57:45 JST #2
! Current time Nov 28-Sun-2021 11:49:16 JST
!
!
hostname R10
timezone +09 00
!
!
!
!
!
!
!
!
!
!
!
ip route default 192.168.1.1
ip access-list sec-list permit ip src any dest any
!
!
!
ike proposal ike-prop encryption aes hash sha group 1024-bit
!
ike policy ike-policy1 peer 34.217.232.61 key pq5RW0mMbSxz8k8.ZRY2T3C82D9GX8_z ike-prop
ike keepalive ike-policy1 10 10
!
ike policy ike-policy2 peer 54.69.109.228 key QAElJrXGVeBgHi.U292jVF3eLTATQXMQ ike-prop
ike keepalive ike-policy2 10 10
!
ipsec autokey-proposal ipsec-prop esp-aes esp-sha lifetime time 3600
!
ipsec autokey-map ipsec-map1 sec-list peer 34.217.232.61 ipsec-prop pfs 1024-bit
ipsec local-id ipsec-map1 192.168.2.0/24
ipsec remote-id ipsec-map1 172.31.0.0/16
!
ipsec autokey-map ipsec-map2 sec-list peer 54.69.109.228 ipsec-prop pfs 1024-bit
ipsec local-id ipsec-map2 192.168.2.0/24
ipsec remote-id ipsec-map2 172.31.0.0/16
!
!
!
!
!
!
!
!
telnet-server ip enable
!       
!
!
!
!
!
!
!
!
router bgp 65000
  neighbor 169.254.8.1 remote-as 64512
  neighbor 169.254.8.1 timers 10 30
  neighbor 169.254.123.133 remote-as 64512
  neighbor 169.254.123.133 timers 10 30
  neighbor 169.254.30.57 remote-as 64512
  neighbor 169.254.30.57 timers 10 30
  address-family ipv4 unicast
    network 192.168.2.0/24
!
ikev2 default-profile
!
device GigaEthernet0
!
device GigaEthernet1
!
interface GigaEthernet0.0
  ip address 192.168.1.10/24
  no shutdown
!
interface GigaEthernet1.0
  ip address 192.168.2.1/24
  no shutdown
!
interface Loopback0.0
  no ip address
!
interface Null0.0
  no ip address
!
interface Tunnel0.0
  tunnel mode ipsec
  ip address 169.254.123.134/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.30.58/30
  ip tcp adjust-mss auto
  ipsec policy tunnel ipsec-map2 df-bit ignore pre-fragment out
  no shutdown

AWS側の設定

事前準備:グローバルIPアドレスの確認

オンプレミス側のグローバルIPアドレスを確認します。もし、ルータがマネージドサービスでありグローバルIPアドレスを確認できない状況ならば、「確認くん」などのWebサイトを使用すると良いでしょう。

確認くん

カスタマーゲートウェイ

VPCの画面にて「カスタマーゲートウェイ」メニューを開きます。

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

NEC IX - AWS カスタマーゲートウェイの作成001

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

NEC IX - AWS カスタマーゲートウェイの作成002

仮想プライベートゲートウェイ

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

NEC IX - AWS 仮想プライベートゲートウェイの作成001

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

NEC IX - AWS 仮想プライベートゲートウェイの作成002

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

NEC IX - AWS 仮想プライベートゲートウェイの作成003

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

NEC IX - AWS 仮想プライベートゲートウェイの作成004

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

NEC IX - AWS 仮想プライベートゲートウェイの作成005

サイト間のVPN接続

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

「VPNの作成」を押下します。

NEC IX - AWS サイト間VPN001

「名前タグ」「仮想プライベートゲートウェイ」「カスタマーゲートウェイ」を入力します。「仮想プライベートゲートウェイ」「カスタマーゲートウェイ」は前述の設定をプルダウンから選びます。

NEC IX - AWS サイト間VPN002

画面下へとスクロールし、「ローカルIPv4ネットワークCidr」「リモートIPv4ネットワークCidr」にオンプレミスとAWS側双方のプライベートIPアドレスのCIDRを入力します。

この値はNAT環境下では入力必須です。NAT変換前の機器を識別するための情報としてCIDRをID代わりに使用します。なお、IDはCIDRの他にipv4, fqdn, keyなどの指定方法がありますが、AWSではCIDRのみに対応しています。

NEC IX - AWS サイト間VPN003

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

何らかの機種のサンプル設定を見ながら、NEC IXの設定を作成します。NEC IXの設定は例示されていないので、最も多数派と思われるCisco IOSの設定例を参考にしつつ、NEC IXの設定を作成する方法を例示します。

「Cisco Systems, Inc.」「CSRv AMI」「IOS 12.4+」を選択し、「ダウンロード」を押下します。

NEC IX - AWS サイト間VPN004

NEC IXの設定

サンプル設定の読み取り

AWSのsite to site VPNは、以下スクリーンショットのようにほぼ全てのハッシュと暗号化アルゴリズムに対応しています。ですので、AWSが提示するサンプル設定に合わせなくてもルータ側のデフォルト設定で動いてしまいます。

AWSのデフォルト設定

したがって、AWSが提供するサンプル設定から「最低限」読み取らなければならないのは以下4点です。

  • 事前共有鍵
  • AWS側のグローバルIPアドレス
  • トンネルに付与するIPアドレス
  • AWS側のAS番号

以下、読み取るべきパラメタが書かれている部分をハイライトします。

! --------------------------------------------------------------------------------
! IPSec Tunnel #1
! --------------------------------------------------------------------------------

  <omitted>

crypto keyring keyring-vpn-09043457e07b5f5d5-0
  local-address 203.165.211.85
  pre-shared-key address 34.217.232.61 key pq5RW0mMbSxz8k8.ZRY2T3C82D9GX8_z
exit

  <omitted>

interface Tunnel1
  ip address 169.254.123.134 255.255.255.252
  ip virtual-reassembly

  <omitted>

router bgp 65000
  neighbor 169.254.123.133 remote-as 64512
  neighbor 169.254.123.133 activate
  neighbor 169.254.123.133 timers 10 30 30

  <omitted>

! --------------------------------------------------------------------------------
! IPSec Tunnel #2
! --------------------------------------------------------------------------------

  <omitted>

crypto keyring keyring-vpn-09043457e07b5f5d5-1
  local-address 203.165.211.85
  pre-shared-key address 54.69.109.228 key QAElJrXGVeBgHi.U292jVF3eLTATQXMQ
exit

  <omitted>

interface Tunnel2
  ip address 169.254.30.58 255.255.255.252
  ip virtual-reassembly

  <omitted>

router bgp 65000
  neighbor 169.254.30.57 remote-as 64512
  neighbor 169.254.30.57 activate
  neighbor 169.254.30.57 timers 10 30 30

  <omitted>

設定作成

  • 事前共有鍵
  • AWS側のグローバルIPアドレス
  • トンネルに付与するIPアドレス
  • AWS側のAS番号

NEC IXの設定を作成します。「事前共有鍵」「AWS側のグローバルIPアドレス」「トンネルに付与するIPアドレス」はランダムに生成されますので、以下をコピペせずに適宜変更してください。「AS番号」は固定のようにも見えますが、念の為、サンプル設定の値を確認した方が無難かと思います。

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アドレスは毎回ランダムに生成されますので、本記事をコピペしないよう注意ください。

ike proposal ike-prop encryption aes hash sha group 1024-bit
!
ike policy ike-policy1 peer 34.217.232.61 key pq5RW0mMbSxz8k8.ZRY2T3C82D9GX8_z ike-prop
ike policy ike-policy2 peer 54.69.109.228 key QAElJrXGVeBgHi.U292jVF3eLTATQXMQ ike-prop
!
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 34.217.232.61 ipsec-prop pfs 1024-bit
ipsec autokey-map ipsec-map2 sec-list peer 54.69.109.228 ipsec-prop pfs 1024-bit
!
no ipsec local-id ipsec-map1 192.168.2.0/24 
no ipsec remote-id ipsec-map1 172.31.0.0/16
no ipsec local-id ipsec-map2 192.168.2.0/24 
no ipsec remote-id ipsec-map2 172.31.0.0/16
!
interface Tunnel0.0
  tunnel mode ipsec
  ip address 169.254.123.134/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.30.58/30
  ip tcp adjust-mss auto
  ipsec policy tunnel ipsec-map2 df-bit ignore pre-fragment out
  no shutdown
!
router bgp 65000
  neighbor 169.254.123.133 remote-as 64512
  neighbor 169.254.123.133 timers 10 30
  neighbor 169.254.30.57 remote-as 64512
  neighbor 169.254.30.57 timers 10 30
  address-family ipv4 unicast
    network 192.168.2.0/24

設定投入後、IPsecが確立された事を確認します。

R10(config)# show ike sa 
ISAKMP SA - 2 configured, 2 created
Local address is 192.168.1.10, port is 500
Remote address is 34.217.232.61, port is 500
  IKE policy name is ike-policy1
  Direction is initiator
  Initiator's cookie is 0x6b8f5d5e57ba6061
  Responder's cookie is 0x9e93277dd7df582e
  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 28382 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 192.168.1.10, port is 500
Remote address is 54.69.109.228, port is 500
  IKE policy name is ike-policy2
  Direction is initiator
  Initiator's cookie is 0x893a43bdcc762508
  Responder's cookie is 0x7f6c9722e87d46cc
  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 28552 seconds
  #ph1 success: 1, #ph1 failure: 0
  #ph1 hash err: 0, #ph1 timeout: 0, #ph1 resend: 1
  #ph2 success: 1, #ph2 failure: 0
  #ph2 hash err: 0, #ph2 timeout: 0, #ph2 resend: 0
R10(config)# 
R10(config)# 
R10(config)# 
R10(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 192.168.1.10
    Remote address is 34.217.232.61
    Outgoing interface is GigaEthernet0.0
    Interface MTU is 1438, path MTU is 1500
    Inbound:
      ESP, SPI is 0xd9e8216f(3655868783)
        Transform is ESP-AES-128-HMAC-SHA-96
        Remaining lifetime is 3177 seconds
      Replay detection support is on
    Outbound:
      ESP, SPI is 0xc24886ee(3259533038)
        Transform is ESP-AES-128-HMAC-SHA-96
        Remaining lifetime is 3177 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 192.168.1.10
    Remote address is 54.69.109.228
    Outgoing interface is GigaEthernet0.0
    Interface MTU is 1438, path MTU is 1500
    Inbound:
      ESP, SPI is 0x3358a799(861448089)
        Transform is ESP-AES-128-HMAC-SHA-96
        Remaining lifetime is 3347 seconds
      Replay detection support is on
    Outbound:
      ESP, SPI is 0xce91830a(3465642762)
        Transform is ESP-AES-128-HMAC-SHA-96
        Remaining lifetime is 3347 seconds
      Replay detection support is on
    Perfect forward secrecy is 1024-bit
R10(config)# 

BGPによって経路を交換できる事を確認します。

R10(config)# show ip bgp 
BGP table version is 7, local router ID is 192.168.2.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
*> 172.31.0.0/16      169.254.123.133        100             64512 i
*> 192.168.2.0/24     0.0.0.0                  1             i

Total number of prefixes 2
R10(config)# 
R10(config)# 
R10(config)# 
R10(config)# sow ip route
% sow  -- Invalid command.
R10(config)# show ip route
IP Routing Table - 6 entries, 1 hidden, 2041 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 [1/1] via 192.168.1.1, GigaEthernet0.0, 0:22:57
     169.254.0.0/16 is subnetted, 2 subnets
C      169.254.30.56/30 [0/1] is directly connected, Tunnel1.0, 0:10:36
C      169.254.123.132/30 [0/1] is directly connected, Tunnel0.0, 0:10:39
B    172.31.0.0/16 [20/100] via 169.254.123.133, Tunnel0.0, 0:06:37
C    192.168.1.0/24 [0/1] is directly connected, GigaEthernet0.0, 0:22:57
C    192.168.2.0/24 [0/1] is directly connected, GigaEthernet1.0, 0:22:57
R10(config)# 
タイトルとURLをコピーしました