[AWS] VGW を別 VPC に付け替えしたときの VPN 接続の挙動をみてみた

VPN接続された状態のVGWを、VPCから切り離し他のVPCに付け替えることで、VPNやルーティング情報にどのような影響があるか検証しました。
2018.04.14

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

こんにちは、菊池です。

AWS上のプライベートネットワークであるVPCでは、VPN接続することで、オンプレミス環境とプライベートな接続が可能です。

このVPN接続、正確には、オンプレミスのルーターであるカスタマーゲートウェイ(CGW)と、AWSの仮想プライベートゲートウェイ(VGW)がIPSec VPNで接続し、そのVGWをVPCと紐付け(アタッチ)することで実現されます。

CGW ---(VPN)--- VGW --- VPC

であれば、VPN接続された状態のVGWを、VPCから切り離し、他のVPCに付け替えることも可能ではないかと思い、検証してみました。

やってみた

前提条件

  • VPC1(VGW移行元)CIDR:172.16.0.0/24
  • VPC2(VGW移行先)CIDR:172.16.0.0/24
  • オンプレ側CIDR:10.10.10.0/24
  • VPNルーティング設定:Dynamic(BGP)
  • カスタマーゲートウェイ(CGW)ルータ:Cisco ISR

初期状態(VPC1にアタッチ)

まずは最初の状態です。VPC1にVGWがアタッチされ、VPNが接続されています。

VPC1のルートテーブルで、オンプレ側ネットワーク10.10.10.0/24へのルートを受信しています。

カスタマーゲートウェイルーター側の状態です。VPNセッションがアップしています。

#show ip bgp summary
BGP router identifier 192.168.1.253, local AS number 65000
BGP table version is 5, main routing table version 5
2 network entries using 288 bytes of memory
3 path entries using 240 bytes of memory
3/2 BGP path/bestpath attribute entries using 480 bytes of memory
1 BGP AS-PATH entries using 24 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 1032 total bytes of memory
BGP activity 2/0 prefixes, 3/0 paths, scan interval 60 secs

Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
169.254.24.77   4        10124      30      31        5    0    0 00:04:11        1
169.254.27.117  4        10124      32      33        5    0    0 00:04:24        1

AWS側のルート情報、172.16.0.0/24を受信しています。

#show ip bgp
BGP table version is 5, 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/24    169.254.24.77          100             0 10124 i
 *                    169.254.27.117         200             0 10124 i

VGWをデタッチ

それでは、VPC1から、VGWをデタッチしてみます。

デタッチしました。

カスタマーゲートウェイルーターで、BGPセッションの状態をみてみます。

#show ip bgp summary
BGP router identifier 192.168.1.253, local AS number 65000
BGP table version is 5, main routing table version 5
2 network entries using 288 bytes of memory
3 path entries using 240 bytes of memory
3/2 BGP path/bestpath attribute entries using 480 bytes of memory
1 BGP AS-PATH entries using 24 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 1032 total bytes of memory
BGP activity 2/0 prefixes, 3/0 paths, scan interval 60 secs

Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
169.254.24.77   4        10124      48      50        5    0    0 00:07:17        1
169.254.27.117  4        10124      51      52        5    0    0 00:07:31        1

セッションは2つともアップされたままで維持されています。しばらくすると、以下のメッセージがログに出力されました。

#debug ip bgp updates
BGP updates debugging is on for address family: IPv4 Unicast
*Apr 14 05:26:38.685: BGP(0): 169.254.24.77 rcv UPDATE about 172.16.0.0/24 -- withdrawn
*Apr 14 05:26:38.685: BGP(0): Revise route installing 1 of 1 routes for 172.16.0.0/24 -> 169.254.27.117(global) to main IP table
*Apr 14 05:26:38.685: BGP(0): (base) 169.254.24.77 send UPDATE (format) 172.16.0.0/24, next 169.254.24.78, metric 200, path 10124
*Apr 14 05:26:38.733: BGP(0): 169.254.27.117 rcv UPDATE about 172.16.0.0/24 -- withdrawn
*Apr 14 05:26:38.733: BGP(0): no valid path for 172.16.0.0/24
*Apr 14 05:26:38.733: BGP: topo global:IPv4 Unicast:base Remove_fwdroute for 172.16.0.0/24
*Apr 14 05:27:08.569: BGP(0): (base) 169.254.24.77 send unreachable (format) 172.16.0.0/24

BGPの経路がアップデートされ、172.16.0.0/24がRemoveされています。VPC1を切り離したことによる経路の更新がされたようです。

BGPの経路情報を見ると、受信した経路は無しになっています。

#show ip bgp
BGP table version is 7, 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

VPC1側のルートテーブルを見ると、こちらもBGPで受信していたルートは削除されています。

VGWをVPC2にアタッチ

それでは、切り離したVGWを、VPC2にアタッチしてみます。

VPC2にアタッチしました。

BGPセッションには変化はなく、アップしたまま維持されています。

#show ip bgp summary
BGP router identifier 192.168.1.253, local AS number 65000
BGP table version is 7, main routing table version 7
1 network entries using 144 bytes of memory
1 path entries using 80 bytes of memory
1/1 BGP path/bestpath attribute entries using 160 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 384 total bytes of memory
BGP activity 2/1 prefixes, 3/2 paths, scan interval 60 secs

Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
169.254.24.77   4        10124      68      71        7    0    0 00:10:22        0
169.254.27.117  4        10124      70      73        7    0    0 00:10:35        0

しばらくすると、BGPルートのアップデートがログに表示されました。

*Apr 14 05:30:19.741: BGP(0): 169.254.24.77 rcvd UPDATE w/ attr: nexthop 169.254.24.77, origin i, metric 100, merged path 10124, AS_PATH
*Apr 14 05:30:19.741: BGP(0): 169.254.24.77 rcvd 172.16.0.0/24
*Apr 14 05:30:19.741: BGP(0): Revise route installing 1 of 1 routes for 172.16.0.0/24 -> 169.254.24.77(global) to main IP table
*Apr 14 05:30:19.741: BGP(0): 169.254.24.77 NEXT_HOP is on same subnet as the bgp peer and set to 169.254.24.77 for net 172.16.0.0/24, flags 200, sb: A9FE184C, mask: FFFFFFFC
*Apr 14 05:30:19.741: BGP(0): (base) 169.254.24.77 send UPDATE (format) 172.16.0.0/24, next 169.254.24.77, metric 100, path 10124
*Apr 14 05:30:36.165: BGP(0): 169.254.27.117 rcvd UPDATE w/ attr: nexthop 169.254.27.117, origin i, metric 200, merged path 10124, AS_PATH

VPC2に紐付けたことでルートが更新されたようです。BGPルートを見ると、172.16.0.0/24を受信しています。

#show ip bgp
BGP table version is 8, 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/24    169.254.27.117         200             0 10124 i
 *>                   169.254.24.77          100             0 10124 i

VPC2側のルートを確認します。まずは、ルートテーブルで、ルート伝播を有効化する必要があります。(VGWアタッチ前にはできません)

ルート伝播を有効にすると、すぐにオンプレ側の10.10.10.0/24が有効化されました。

まとめ

ということで、今回の検証でわかったことです。

  • VGWをVPCからデタッチ・他のVPCにアタッチをすると
    • VPNセッション/BGPセッションは維持される
    • VPCが切り離し、割り当てされることでBGPのルートは自動でアップデートされる

VPCの移行などで、オンプレ側ルータの設定を変えずにVPNを維持したい場合にはVGWの付け替えのみで、影響を最小限に移行することができそうです。

その気になれば、オンプレ側には全く意識させずに、別の環境へ移行するということもできます。高度に仮想化・ソフトウェア化されたAWSのネットワークだからこそできることではないでしょうか。