Trace a failed connection through AWS VPC route tables

Trace a failed connection through AWS VPC route tables

A private subnet can have a perfectly reasonable default route and still send one destination to the wrong next hop. Consider an application reaching 10.52.4.20. Its subnet route table contains 0.0.0.0/0 pointing to a NAT gateway and 10.52.0.0/16 pointing to a transit gateway. The service address follows the transit gateway route because /16 is more specific than /0.

Find the route table the subnet actually uses

Start with a single source subnet ID and destination IP. Look for an explicit association. If the command returns an empty list, use the VPC's main route table. It is easy to spend half an hour reading the right CIDR in a route table that a workload never uses.

aws ec2 describe-route-tables \
  --filters Name=association.subnet-id,Values="$SOURCE_SUBNET" \
  --query 'RouteTables[].{ID:RouteTableId,Routes:Routes}'
aws ec2 describe-route-tables \
  --filters Name=vpc-id,Values="$VPC_ID" Name=association.main,Values=true \
  --query 'RouteTables[].{ID:RouteTableId,Routes:Routes}'

Pick the winning route in each direction

Write down the destination, matched prefix, next hop, and route state. A route whose state is blackhole has no usable target. For a transit gateway, check the route table associated with the source attachment as a separate hop. At the destination, repeat the lookup using the application's source IP as the return destination. If an appliance performs address translation, use the translated address on the segments where it applies.

Verify one change at a time

Retry a known TCP request from the same source using the same port and destination. Record its timestamp and the source and destination addresses. An ACCEPT entry in VPC Flow Logs can help narrow the search at an interface, but it doesn't demonstrate that the complete round trip worked. Keep the route and security checks separate enough that one test can tell you which change mattered.

Related reading

Techmandra Avatar