AWS VPC Route Table

AWS VPC Route Table

What is a Route Table in AWS VPC?

A route table specifies how packets are forwarded between the subnets within your VPC, the internet, and your VPN connection

A route table in AWS VPC controls the routing of traffic in and out of the subnets associated with it.

We attach route tables at the subnet level in the VPC.

Why do we need a Route Table?

We need route tables in VPC to control the traffic flow and determine where network traffic from the subnet is directed.

Route tables allow us to route traffic between subnets of the same VPC, between subnets of different VPCs, and between VPC and internet or on-premises networks.

Functionality of Route Table

The main functions of a route table are

  1. It contains a set of rules called routes that are used to determine where network traffic from the subnet is directed.

  2. When an instance in the subnet sends a packet, the route table is consulted to see where to forward the packet.

  3. It can route traffic between subnets of the same VPC, between subnets of different VPCs, and between VPC and the internet using an internet gateway, VPC peering, or VPN connections.

What makes a subnet public or private?

A public subnet is a subnet that is associated with a route table that has a route to an Internet gateway. This connects the VPC to the Internet and other AWS services.

A private subnet is a subnet that is associated with a route table that doesn't have a route to an internet gateway.

Different types of route table targets

Here are the descriptions of some common types of route table targets in AWS VPC with descriptions:

  1. Internet Gateway - Allows routing of traffic to the internet from resources in the VPC. The internet gateway must be attached to the VPC for this target.

  2. NAT Gateway - Allows private subnets to connect to the internet or other AWS services but prevents the Internet from initiating connections with instances. A NAT gateway is horizontally scaled within an Availability Zone.

  3. Virtual Private Gateway - Provides a tunnel between an AWS VPC and an on-premises network. Traffic is routed through the virtual private gateway to the customer gateway on the VPN connection.

  4. Transit Gateway - Centrally manages connectivity between VPCs, on-premises networks, and other AWS services. Traffic is routed through the transit gateway.

  5. Egress Only Internet Gateway - Allows outbound internet access for instances in the VPC while preventing the instances from receiving inbound traffic initiated from the internet.

  6. Network Interface - Targets a specific network interface attachment on an instance in the VPC. Useful for routing traffic to a NAT instance.

    .

Types of Route Table?

  1. Main RT

  2. Custom RT

Main route table

The main route table is a route table that is automatically created when a VPC is created. When a subnet is created without associating an explicit route table, it is implicitly associated with the main route table by default.

The main route table has the following characteristics

  1. It contains a local route for traffic within the VPC by default.

  2. The main route table cannot be deleted but routes can be added, modified, or removed from it.

  3. A custom route table cannot be set as the main route table.

  4. The association of a subnet can be replaced by explicitly associating it with another custom route table.

  5. The main route table determines the default routing for any new subnets created without an explicit association.

Custom route table

A manually created route table in AWS VPC refers to a custom route table. When a VPC is created, a main route table is automatically generated but we can create additional custom route tables as per our network requirements. for example for a Private subnet.

Some key points about a custom route table

  1. It is created separately other than the default main route table.

  2. We can add routes to it as per our use case to control traffic flow between subnets and resources.

  3. A custom route table needs to be explicitly associated with one or more subnets. This associates the routes in the table to the subnet.

  4. It provides flexibility to define custom routing logic compared to the default routes in the main route table.

  5. Common use cases for custom tables include private subnet routing, NAT subnet routing, etc.

How to Create a custom Route table in AWS VPC?

Open console.aws.amazon.com/vpcconsole/ ,

When creating the Route table we need to define the select VPC

Some key points

  • Each subnet must be associated with at least one route table, which controls the routing for the subnet.

  • A subnet can be explicitly associated with a custom route table or implicitly associated with the main route table.

  • A subnet can only be associated with one route table at a time. However, the same route table can be associated with multiple subnets.

  • This allows flexibility in defining different routing rules for different subnets using custom route tables while keeping the default rules using the main route table.