AWS VPC: How does route table redirect local traffic to the right subnet and instance?

4.6k views Asked by At

AWS VPC

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.

  1. What does local mean in this place? the VPC network?
  2. what's the topology of vpc and subnets?
  3. How does route table know which subnet should be the right subnet to receive this packet?
  4. How does route table know which instance should be the right instance to receive this packet?
  5. How does route table redirect the packet to the instance(172.31.16.5)?
  6. If I would like to better understand it, which kind of background knowledge should I learn first?
3

There are 3 answers

0
John Rotenstein On

Amazon VPC is a virtualized network, also known as a software-defined network.

Behind-the-scenes, VPC traffic is encapsulated and transferred across 'normal' network equipment, but the VPC defines a simplified set of rules that allow a network to be provisioned through clicks and API calls rather than connecting and configuring equipment.

The simple answer to your questions is... It doesn't matter.

As long as the network behaves correctly for how it has been configured, the implementation details are irrelevant.

If you are interested in learning how networks in general operate, then I would recommend learning about Ethernet, TCP/IP and network routers. A VPC is higher-layer implementation of these technologies.

To learn a little bit about how VPCs operate, I would recommend watching these YouTube videos:

1
jingx On

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.

0
cvetomirst On

Actually this works exactly like your network at home. Imagine your ISP is the equivalent of the aws internet gateway and your home router is the equivalent of the aws router. So when you configure your home router you are actually setting the routing table. Based on this config the router knows which packets are for your ISP and which are for the local network. Regarding the magic in step 3 - the router actually sees that you are trying to access another subnet based on the mask(in your case /16) and redirects the packages directly to your Availability Zone B EC2 instance