Networking
D1 · Secure
D2 · Resilient
~1 phút đọc

VPC routing — edge cases hay bị bẫy

Longest prefix match, route ưu tiên giữa local/IGW/VGW/TGW, blackhole, transit gateway route table, asymmetric routing trong ELB.

vpc
routing
tgw
longest-prefix

Sơ đồ tổng quan

Đang tải sơ đồ…

Quy tắc cơ bản

  • Mỗi subnet gắn đúng 1 route table.
  • Local route (VPC CIDR) luôn có mặt, không xóa được.
  • Longest prefix match: route cụ thể hơn thắng. `10.0.0.0/24` thắng `10.0.0.0/16`.
  • Khi 2 route cùng prefix: static thắng propagated; trong propagated thì DX thắng VPN.

Các target có thể gán

  • `igw-...` Internet Gateway (public subnet).
  • `nat-...` NAT Gateway (egress private → internet).
  • `vgw-...` Virtual Private Gateway (VPN/DX site-to-site).
  • `tgw-...` Transit Gateway (hub).
  • `pcx-...` VPC Peering.
  • `vpce-...` VPC Endpoint (interface qua ENI; gateway endpoint cho S3/DDB).
  • `eni-...` Elastic Network Interface (NAT instance, appliance).
  • `blackhole` — route tồn tại nhưng target down → packet drop.

Transit Gateway routing

  • TGW có Route Table riêng (không phải VPC route table).
  • Association: VPC/VPN attachment → route table nào sẽ ra quyết định.
  • Propagation: attachment nào advertise route vào table này.
  • Tách association & propagation để isolate traffic (vd Prod ≠ Dev, Shared Services reachable từ cả 2).

Asymmetric routing trap

Khi packet đi qua stateful appliance (firewall, NAT instance), request & response phải cùng đường. ALB/NLB trong multi-AZ, subnet-level route khác nhau có thể gây asymmetric → firewall reject vì không có state entry. Fix: dùng GWLB (symmetric hashing) hoặc đảm bảo route table cả 2 chiều identical.

Lưu ý
Câu hỏi kinh điển: 'sao traffic từ on-prem sang EC2 vào được, EC2 reply không về?' → thiếu route ngược ở VPC route table / on-prem / BGP.