本稿の目的
Classic Infrastructure/VPCの両方に同じIPアドレス(今回の例では10.212.64.135)が存在した場合に、外部環境はTransit Gateway経由でどちらに接続するか?という問題を本稿で扱う。
結論から言うと・・・
- Classic Infrastructureはsubnet単位で経路広告が行われるのに対し、VPCではaddress prefix単位で経路広告される。
- 経路が重複した場合は、ネットワーク長のLongest Matchingに従って優先度が決定された(挙動は期待どおり)。
- Transit Gatewayにはprefix filteringがあり、ここにも書いてある通り、Transit Gateway に入ってくる経路広告についてはフィルタリングが可能だが、Transit Gateway から各リソースへ出ていく経路広告をフィルタリングすることはできない。このprefix filteringを活用することで、より明確な通信制御が可能となる。
- VPCの Ingress Custom Route には、特定のネットワークを VPC 外部へ経路広告する機能がある。一般的には「10.xx.xx.xx/24 宛の通信を 10.212.64.135 に転送する」といった形で設定することが想定されるが、必ずしもその方法に限らない。例えば、「10.212.64.135/32 宛のネットワークを 10.212.64.135 に転送する」という、一見すると意味がないように見える設定であっても、外部には/32で経路広告されるため Longest Matchingによる最優先経路となり、結果として意図した経路制御を行うことが可能である。
1. 初期構成: Classic Infrastructureしか接続していない場合
- 当然Classic Infrastructureと通信する。
- 構成図
- Transit Gatewayで確認したroute table。Classic Infrastructureから経路広告される10.212.64.128/26のみを認識
Classic Infrastructureのtcpdump
[root@classic-syasuda ~]# tcpdump -i any icmp -nn
tcpdump: data link type LINUX_SLL2
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
09:31:34.371974 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 13036, seq 0, length 64
09:31:34.372003 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 13036, seq 0, length 64
09:31:35.375095 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 13036, seq 1, length 64
09:31:35.375124 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 13036, seq 1, length 64
09:31:36.377139 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 13036, seq 2, length 64
09:31:36.377175 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 13036, seq 2, length 64
09:31:37.382724 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 13036, seq 3, length 64
09:31:37.382759 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 13036, seq 3, length 64
09:31:38.385279 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 13036, seq 4, length 64
09:31:38.385301 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 13036, seq 4, length 64
2. Classic Infrastructureのsubnet長よりVPCのaddress prefix長の方が長い場合
- Longest Matchingに従って、VPCと通信する。
- 構成図
- Transit Gatewayで確認したroute table。Classic Infrastructure/VPCの双方から経路広告されOverlapが発生しているが、Longest MatchingによりVPCへの経路が優先される。
Classic Infrastructureのtcpdump
[root@classic-syasuda ~]# tcpdump -i any icmp -nn
tcpdump: data link type LINUX_SLL2
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
(出力なし)
VPCのtcpdump
[root@syasuda-vpc ~]# tcpdump -i any icmp -nn
tcpdump: data link type LINUX_SLL2
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
00:46:15.718571 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 21246, seq 3, length 64
00:46:15.718589 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 21246, seq 3, length 64
00:46:16.723306 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 21246, seq 4, length 64
00:46:16.723321 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 21246, seq 4, length 64
00:46:17.731592 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 21246, seq 5, length 64
00:46:17.731612 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 21246, seq 5, length 64
00:46:18.733927 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 21246, seq 6, length 64
00:46:18.733950 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 21246, seq 6, length 64
00:46:19.736980 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 21246, seq 7, length 64
00:46:19.737024 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 21246, seq 7, length 64
3. VPCのaddress prefix長の方が長い場合 + VPCへの接続にprefix filteringを実施
- prefix filteringの結果、Classic Infrastructureと通信する。
- 構成図
- prefix filteringの設定
- Transit Gatewayで確認したroute table。VPCからの経路広告はフィルタリングされたため、Classic Infrastructureへの経路のみが残っている。
prefix filteringがされているのにVPC側と通信できてしまっていて悩んでいたのですが、実はVPC間で別のTransit Gatewayでも繋がっていました・・・
prefix filter設定から経路が切り替わるまでに30秒ぐらいかかりました。
Classic Infrastructureのtcpdump
[root@classic-syasuda ~]# tcpdump -i any icmp -nn
tcpdump: data link type LINUX_SLL2
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
15:58:56.926548 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 9182, seq 4, length 64
15:58:56.926569 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 9182, seq 4, length 64
15:58:57.925738 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 9182, seq 5, length 64
15:58:57.925770 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 9182, seq 5, length 64
15:58:58.929919 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 9182, seq 6, length 64
15:58:58.929937 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 9182, seq 6, length 64
15:58:59.935151 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 9182, seq 7, length 64
15:58:59.935184 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 9182, seq 7, length 64
15:59:00.941334 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 9182, seq 8, length 64
15:59:00.941374 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 9182, seq 8, length 64
VPCのtcpdump
[root@syasuda-vpc ~]# tcpdump -i any icmp -nn
tcpdump: data link type LINUX_SLL2
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
(出力なし)
4. VPCのaddress prefix長の方が長い場合 + VPCへの接続にprefix filteringを実施+VPCでingress routeのadvertiseを設定
- "10.212.64.128/32"が経路広告されたため、Longest Matchingに従って、VPCと通信する。
- 構成図
- prefix filteringの設定
- Ingress routeの設定。10.212.64.135宛の経路を10.212.64.135/32でより明示的に経路広告することでLongest MatchingでVPC側に接続するように構成している。
- Transit Gatewayで確認したroute table。10.212.64.135/32は先述のprefix filtering設定のDeny対象にはならない。
Ingress routeのadvertise設定から実際に経路が切り替わるまでは数秒であり非常に高速でした。
Classic Infrastructureのtcpdump
[root@classic-syasuda ~]# tcpdump -i any icmp -nn
tcpdump: data link type LINUX_SLL2
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
(出力なし)
VPCのtcpdump
[root@syasuda-vpc ~]# tcpdump -i any icmp -nn
tcpdump: data link type LINUX_SLL2
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
07:12:39.742840 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 486, length 64
07:12:39.742857 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 486, length 64
07:12:40.745826 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 487, length 64
07:12:40.745840 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 487, length 64
07:12:41.747323 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 488, length 64
07:12:41.747370 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 488, length 64
07:12:42.748281 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 489, length 64
07:12:42.748306 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 489, length 64
07:12:43.754086 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 490, length 64
07:12:43.754134 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 490, length 64
5. Classic InfrastructureのsubnetよりVPCのaddress prefix長の方が短い場合
- Longest Matchingに従って、Classic Infrastructureと通信する。
- 構成図
- Transit Gatewayで確認したroute table。Classic Infrastructure/VPCの双方から経路広告されOverlapが発生しているが、Longest MatchingによりClassic Infrastructureへの経路が優先される
Classic Infrastructureのtcpdump
[root@classic-syasuda ~]# tcpdump -i any icmp -nn
tcpdump: data link type LINUX_SLL2
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
16:24:55.408621 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 1224, length 64
16:24:55.408641 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 1224, length 64
16:24:56.411883 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 1225, length 64
16:24:56.411902 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 1225, length 64
16:24:57.416339 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 1226, length 64
16:24:57.416371 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 1226, length 64
16:24:58.423747 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 1227, length 64
16:24:58.423796 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 1227, length 64
16:24:59.420800 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 1228, length 64
16:24:59.420827 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 1228, length 64
VPCのtcpdump
[root@server-vpc ~]# tcpdump -i any icmp -nn
tcpdump: data link type LINUX_SLL2
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
(出力なし)
6. VPCのaddress prefix長の方が短い場合 + Classic Infrastructureへの接続にprefix filteringを実施
- Classic Infrastructureへの経路がフィルタリングされたため、VPCと通信する。
- 構成図
- prefix filtering
- Transit Gatewayで確認したroute table。Classic Infrastructureからの経路広告はフィルタリングされたため、VPCへの経路のみが残っている。
prefix filter設定から経路が切り替わるまでに30秒ぐらいかかりました。
Classicのtcpdump
[root@classic-syasuda ~]# tcpdump -i any icmp -nn
tcpdump: data link type LINUX_SLL2
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
(出力なし)
VPCのtcpdump
[root@server-vpc ~]# tcpdump -i any icmp -nn
tcpdump: data link type LINUX_SLL2
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
07:30:38.341516 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 1561, length 64
07:30:38.341533 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 1561, length 64
07:30:39.347155 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 1562, length 64
07:30:39.347171 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 1562, length 64
07:30:40.352019 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 1563, length 64
07:30:40.352066 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 1563, length 64
07:30:41.357163 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 1564, length 64
07:30:41.357209 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 1564, length 64
07:30:42.361513 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 1565, length 64
07:30:42.361562 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 1565, length 64
7. VPCのaddress prefix長の方が短い場合 + VPCでingress routeのadvertiseを設定
- "10.212.64.128/32"がVPCから経路広告されたため、Longest Matchingに従って、VPCと通信する。
- 構成図
- Ingress routeの設定。10.212.64.135宛の経路は本来は10.212.64.128/25に含まれているが、10.212.64.135/32でより明示的に経路広告することでLongest MatchingでVPC側に接続するように構成している
- Transit Gatewayで確認したroute table。Classic Infrastructure/VPCの双方から経路広告されOverlapが発生しているが、Longest Matchingにより10.212.64.135/32を経路広告しているVPCへの経路が優先される。
Ingress routeのadvertise設定から実際に経路が切り替わるまでは数秒であり非常に高速でした。
Classic Infrastructureのtcpdump
[root@classic-syasuda ~]# tcpdump -i any icmp -nn
tcpdump: data link type LINUX_SLL2
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
(出力なし)
VPCのtcpdump
[root@server-vpc ~]# tcpdump -i any icmp -nn
tcpdump: data link type LINUX_SLL2
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
07:41:05.381999 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 2186, length 64
07:41:05.382019 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 2186, length 64
07:41:06.384547 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 2187, length 64
07:41:06.384563 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 2187, length 64
07:41:07.390487 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 2188, length 64
07:41:07.390533 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 2188, length 64
07:41:08.398602 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 2189, length 64
07:41:08.398647 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 2189, length 64
07:41:09.398249 eth0 In IP 192.168.100.4 > 10.212.64.135: ICMP echo request, id 55013, seq 2190, length 64
07:41:09.398292 eth0 Out IP 10.212.64.135 > 192.168.100.4: ICMP echo reply, id 55013, seq 2190, length 64