[GCP] Cisco ルータを使った VPC との Cloud VPN 接続を試してみた

GCPのネットワークの勉強を兼ねて、VPCへのVPN接続をやってみました。
2020.06.24

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは、菊池です。

GCP上のVPNを使って、VPN接続(Cloud VPN)を試してみました。

前提条件

構成イメージは以下の通りです。VPN接続するルータ(ピアVPNゲートウェイ)はルータの内側にあり、直接パブリックIPを持たない構成となります。そのため、NATトラバーサルが必要です。インターネット接続ルータでは、IPSecVPN(+NATトラバーサル)に必要なポート(ESP:50、UDP:500、UDP:4500)はピアVPNゲートウェイにフォワードするように予め設定済みです。

また、VPNルータ(ピアVPNゲートウェイ)にはおなじみ(?)のCisco C841Mを使用しています。

  • オンプレミス側
    • オンプレミスCIDR:10.10.10.0/24
    • VPNゲートウェイのインターフェースIP:192.168.1.253
    • インターネット接続IP:222.xxx.xxx.xxx
    • ASN:65000
    • トンネル0ピアIP:169.254.0.2/30
    • トンネル1ピアIP:169.254.0.6/30
  • VPC側
    • VPC CIDR:172.16.0.0/16
    • ASN:65100
    • トンネル0ピアIP:169.254.0.1/30
    • トンネル1ピアIP:169.254.0.5/30

Cloud VPNの接続

VPCの作成

まずはGCP側にVPCを作成します。[VPCネットワークを作成] に進みます。

VPCの名前を入力し、サブネットを作成します。今回は[カスタム]として、asia-east1に172.16.0.0/16のサブネットを作成します。

その他はデフォルトのまま作成しました。

新しくVPCが作成できました。

VPNの作成

続いて、VPNの作成です。[ハイブリッド接続] から [VPN] を選択します。

[VPN接続を作成] に進みましょう。

冗長化に対応した HA VPNを選択します。HA VPNでは動的ルーティング(BGP)のみ対応します。

まずはVPNゲートウェイの作成です。名前を入力し、先ほど作成したVPCとリージョンを選択します。

続けて、VPN接続先となるピアVPNゲートウェイを設定します。[オンプレミスまたは非Google Cloud] を選択し、[新しいピアVPNゲートウェイを作成する] を選びましょう。

オンプレ側のVPN接続先の情報を入力します。名前は任意です。オンプレ側は1回線なので、[1つのインターフェース]を選び、パブリックIPを入力します。

ピアVPNゲートウェイの情報が設定できたので、VPNトンネルの設定を行います。[VPNトンネルを1つ作成する] が選択されていますので、そのままクラウドルータの設定を選択します。

クラウドルータから[新しいルーターを作成] を選択します。

オンプレ側と経路交換を行うためのBGPルータの設定になります。名前とASNを入力します。任意のプライベートASNが指定できますので、65100としました。

VPN接続の情報を入力し、[IKEバージョン]にIKEv2(デフォルト)を選び、[IKE事前共有キー]を生成してキーの文字列を控えておきます。

次にBGPセッションの情報です。以下の[構成] を選択します。

BGPセッションに使用する情報を設定します。[ピアASN]にオンプレ側のASNし、トンネル間のIPアドレスを入力します。ここで入力するアドレスは、リンクローカルアドレス(169.254.0.0/16)から/30の範囲で指定が必要です。MEDはオプションなので空欄でも問題ありません。

設定したら、先に進みます。

設定された内容を確認しましょう。

これで、VPNゲートウェイと1つ目のトンネルが作成できました。

2つ目のトンネルの追加

ここまでで、VPNトンネルが1つ作成されています。HA VPN構成ではトンネルを冗長化したいので、[VPNトンネルを作成]から追加のトンネルを作成していきましょう。

先ほどと同じようにトンネルを設定していきます。異なるのは、Cloud VPNゲートウェイのインターフェースに、先ほどと異なるIPを指定する点です。以下のように[1: xxx.xxx.xxx.104] の方のIPをもつインターフェースを選択しました。

同様に、IKEv2を指定し、IKE事前共有キーを生成して控えておきます。

同じように、BGPセッションも設定します。

ピアASNは同様に65000を指定します。IPアドレスは先ほどと重複しない、/30のリンクローカルアドレスから割り当てます。

保存して、次へ。

作成できましたので、確認しましょう。

これで2つのトンネルが作成できました。

ピアVPNゲートウェイ(オンプレ側VPNルータ)の設定

それではオンプレ側のルータを設定していきます。AWSやAzureと違い、そのまま適用できるようなサンプルコンフィグは提供されていませんので、以下のページにある仕様を確認しながら設定していきます。

まずはVPNトンネルの設定です。

トンネル0設定

crypto ikev2 proposal test-vpn
 encryption aes-cbc-256 aes-cbc-192 aes-cbc-128
 integrity sha256
 group 16

crypto ikev2 policy test-vpn
 proposal test-vpn

crypto ikev2 keyring test-vpn
 peer xxx.xxx.xxx.201
  address xxx.xxx.xxx.201
  pre-shared-key xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

crypto ikev2 profile test-vpn
 match identity remote address xxx.xxx.xxx.201 255.255.255.255
 identity local address 222.xxx.xxx.xxx
 authentication local pre-share
 authentication remote pre-share
 keyring local test-vpn
 lifetime 36000
 dpd 60 5 periodic

crypto ipsec transform-set test-vpn esp-aes 256 esp-sha256-hmac
 mode tunnel

crypto ipsec profile ipsec-profile-test-vpn
 set security-association lifetime kilobytes 102400000
 set transform-set test-vpn
 set pfs group16
 set ikev2-profile test-vpn

interface Tunnel100
 ip address 169.254.0.2 255.255.255.252
 ip tcp adjust-mss 1350
 tunnel source 192.168.1.253
 tunnel mode ipsec ipv4
 tunnel destination xxx.xxx.xxx.201
 tunnel protection ipsec profile ipsec-profile-test-vpn

トンネル1設定

crypto ikev2 proposal test-vpn-2
 encryption aes-cbc-256 aes-cbc-192 aes-cbc-128
 integrity sha256
 group 16

crypto ikev2 policy test-vpn-2
 proposal test-vpn-2

crypto ikev2 keyring test-vpn-2
 peer xxx.xxx.xxx.104
  address xxx.xxx.xxx.104
  pre-shared-key xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

crypto ikev2 profile test-vpn-2
 match address local interface GigabitEthernet0/5
 match identity remote address xxx.xxx.xxx.104 255.255.255.255
 identity local address 222.xxx.xxx.xxx
 authentication local pre-share
 authentication remote pre-share
 keyring local test-vpn-2
 lifetime 36000
 dpd 60 5 on-demand

crypto ipsec transform-set test-vpn-2 esp-aes 256 esp-sha256-hmac
 mode tunnel

crypto ipsec profile ipsec-profile-test-vpn-2
 set security-association lifetime kilobytes 102400000
 set transform-set test-vpn-2
 set pfs group16
 set ikev2-profile test-vpn-2

interface Tunnel101
 ip address 169.254.0.6 255.255.255.252
 ip tcp adjust-mss 1350
 tunnel source 192.168.1.253
 tunnel mode ipsec ipv4
 tunnel destination xxx.xxx.xxx.104
 tunnel protection ipsec profile ipsec-profile-test-vpn-2

ハマったのは、crypto ikev2 profileの部分です。今回の構成では、VPNルータはインターネット接続用ルータの内側にあるためNATトラバーサルの構成となります。以下のトラブルシューティングにあるように、ピアVPNゲートウェイ(オンプレ側VPNルータ)で設定したパブリックIPを自身のIDに使用する必要があります。

そこで、 identity local addressには以下のようにプライベートアドレスではなく、パブリックIPを指定する必要がありました。

crypto ikev2 profile test-vpn
 match identity remote address xxx.xxx.xxx.201 255.255.255.255
 identity local address 222.xxx.xxx.xxx
 authentication local pre-share
 authentication remote pre-share
 keyring local test-vpn
 lifetime 36000
 dpd 60 5 periodic

BGP設定

router bgp 65000
 bgp log-neighbor-changes
 neighbor 169.254.0.1 remote-as 65100
 neighbor 169.254.0.1 timers 20 60 60
 neighbor 169.254.0.5 remote-as 65100
 neighbor 169.254.0.5 timers 20 60 60
 address-family ipv4
  network 10.10.10.0 mask 255.255.255.0
  neighbor 169.254.0.1 activate
  neighbor 169.254.0.5 activate
 exit-address-family

上記のように設定後、VPN、BGPともにアップしていることが確認できました。

VPNルータ側もアップが確認できます。

#show crypto session
Crypto session current status

Interface: Tunnel101
Profile: test-vpn-2
Session status: UP-ACTIVE
Peer: xxx.xxx.xxx port 4500
  Session ID: 19705
  IKEv2 SA: local 192.168.1.253/4500 remote xxx.xxx.xxx.104/4500 Active
  IPSEC FLOW: permit ip 0.0.0.0/0.0.0.0 0.0.0.0/0.0.0.0
        Active SAs: 2, origin: crypto map

Interface: Tunnel100
Profile: test-vpn
Session status: UP-ACTIVE
Peer: xxx.xxx.xxx.201 port 4500
  Session ID: 19709
  IKEv2 SA: local 192.168.1.253/4500 remote xxx.xxx.xxx.201/4500 Active
  IPSEC FLOW: permit ip 0.0.0.0/0.0.0.0 0.0.0.0/0.0.0.0
        Active SAs: 2, origin: crypto map

コンソールからトンネルを選択すると、詳細情報を確認できます。

詳細から、ログを[表示] を選択することで、VPNの詳細なログを確認可能です。ここで詳細が確認できるので、接続でハマった際もトラブルシュートが非常に捗りました。

BGPルートの確認

BGPもアップしましたので、経路情報が適切に交換できているか確認します。VPC側はコンソールから、以下のように10.10.10.0/24の経路を受け取っていることが確認できます。

オンプレ側も、VPCの経路情報として172.16.0.0/16を受け取っています。

#show ip bgp
BGP table version is 3, local router ID is 192.168.1.253
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
              x best-external, a additional-path, c RIB-compressed,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *>  10.10.10.0/24    0.0.0.0                  0         32768 i
 *   172.16.0.0       169.254.0.5            100             0 65100 ?
 *>                   169.254.0.1            100             0 65100 ?

ルートテーブルにも反映されています。

#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, 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
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR

Gateway of last resort is 192.168.1.1 to network 0.0.0.0

S*    0.0.0.0/0 [1/0] via 192.168.1.1
      10.0.0.0/8 is variably subnetted, 3 subnets, 2 masks
C        10.10.10.0/24 is directly connected, Vlan1
L        10.10.10.254/32 is directly connected, Vlan1
S        10.212.134.0/24 [1/0] via 10.10.10.253
      169.254.0.0/16 is variably subnetted, 4 subnets, 2 masks
C        169.254.0.0/30 is directly connected, Tunnel100
L        169.254.0.2/32 is directly connected, Tunnel100
C        169.254.0.4/30 is directly connected, Tunnel101
L        169.254.0.6/32 is directly connected, Tunnel101
B     172.16.0.0/16 [20/100] via 169.254.0.1, 00:01:14
      192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.1.0/24 is directly connected, GigabitEthernet0/5
L        192.168.1.253/32 is directly connected, GigabitEthernet0/5

この結果をみると、VPCから受け取るBGPの経路情報はデフォルトでMED100が設定されているようです。明示的に優先ルートを指定する場合には、[BGPセッションの編集] から、MEDの値を変更します。現在ベストパスに選択されているトンネルを、MED:200に設定して優先度を落としてみました。

すると、以下のようにピアVPNゲートウェイ側で採用するルートが切り替わることが確認できました。

#show ip bgp
BGP table version is 4, local router ID is 192.168.1.253
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
              x best-external, a additional-path, c RIB-compressed,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *>  10.10.10.0/24    0.0.0.0                  0         32768 i
 *   172.16.0.0       169.254.0.1            200             0 65100 ?
 *>                   169.254.0.5            100             0 65100 ?

メトリックの変更に伴い、ルートテーブルに使用する経路も切り替わります。

#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, 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
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR

Gateway of last resort is 192.168.1.1 to network 0.0.0.0

S*    0.0.0.0/0 [1/0] via 192.168.1.1
      10.0.0.0/8 is variably subnetted, 3 subnets, 2 masks
C        10.10.10.0/24 is directly connected, Vlan1
L        10.10.10.254/32 is directly connected, Vlan1
S        10.212.134.0/24 [1/0] via 10.10.10.253
      169.254.0.0/16 is variably subnetted, 4 subnets, 2 masks
C        169.254.0.0/30 is directly connected, Tunnel100
L        169.254.0.2/32 is directly connected, Tunnel100
C        169.254.0.4/30 is directly connected, Tunnel101
L        169.254.0.6/32 is directly connected, Tunnel101
B     172.16.0.0/16 [20/100] via 169.254.0.5, 00:02:04
      192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.1.0/24 is directly connected, GigabitEthernet0/5
L        192.168.1.253/32 is directly connected, GigabitEthernet0/5

まとめ

GCPのVPCへのVPN接続を試しました。GCPの場合、BGPのMEDが明示的に設定できることから、柔軟な経路選択が利用可能です。また、VPNのログがCloud Loggingから詳細が確認できるので、トラブルシュートも容易に可能なことがわかりました。