Question:
Here is an AWS typical VPC, which is composed of the following components
- two subnets
- Internet Gateway
- Route table
- Instances
Imagine a scenario
step1, instance (private IP 172.31.0.5) in subnet1 send a packet to IP 172.31.16.5 (in subnet2).
step2, the packet reaches the route table, the route table redirect the packet to the target local
.
step3, Some magic happens. 🤔
step4, instance(172.31.16.5) receives the packet.
The following questions are about the magic in step3.
- What does local mean in this place? the VPC network?
- what’s the topology of vpc and subnets?
- How does route table know which subnet should be the right subnet to receive this packet?
- How does route table know which instance should be the right instance to receive this packet?
- How does route table redirect the packet to the instance(172.31.16.5)?
- If I would like to better understand it, which kind of background knowledge should I learn first?
Answer:
It might become easier to understand if you replace “route table” with “router” in the steps. The Router in your diagram is the one actually routing the traffic. The route table is only part of the configuration of the Router. The Router also knows about all the subnet CIDR ranges. They are subsets of the VPC CIDR range.
In a route table, the local
entry is usually configured with the CIDR range of the entire VPC. So in step 2, the Router looks up the route table, and sees that the destination is “local”, i.e. another host in the same VPC. In step 3, it would then look through the subnet CIDR ranges, sees that 172.31.16.5
is in subnet2’s range, and so routes the packets there.