LAB 35 ‐ Custom RT - DevWithNehaCloud/Oracle-Cloud-Infrastructure-wiki GitHub Wiki
Route Table in OCI
A Route Table is a collection of Route Rules that tells OCI where network traffic should be sent when it leaves a subnet.
Example
If a private subnet needs internet access through a NAT Gateway, the subnet is associated with a Route Table that contains a route rule pointing to the NAT Gateway.
Route Rule in OCI
A Route Rule is an individual entry within a Route Table. It defines:
- Destination CIDR Block (where the traffic is going)
- Target (where the traffic should be forwarded)
Example
| Destination CIDR | Target |
|---|---|
0.0.0.0/0 |
Internet Gateway |
This route rule means that all traffic destined for the internet is sent to the Internet Gateway.
Quick Example
Suppose a public subnet contains a web server:
| Component | Value |
|---|---|
| Subnet | Public Subnet |
| Destination CIDR | 0.0.0.0/0 |
| Target | Internet Gateway |
Traffic Flow:
Instance → Route Table → Route Rule (0.0.0.0/0) → Internet Gateway → Internet
Key Difference
| Route Table | Route Rule |
|---|---|
| A collection of routing entries. | A single routing entry inside a Route Table. |
| Associated with a subnet. | Defines destination and target. |
| Can contain multiple route rules. | Represents one routing path. |
One-line summary: A Route Table is a container of routing instructions, while a Route Rule is a single instruction that tells OCI where to send specific network traffic.
Steps to create custom Route Table
- Navigate to Networking → Virtual Cloud Networks, select Hub_Network, click the Routing option, and then click Create Route Table.
- Enter a name for the route table, select the appropriate compartment, and then click Create.
Scroll down and also select tag and finally click on Create
- Navigate to the newly created route table, click Add Route Rules, and configure the route rule as required.
- Select the Target Type, enter the Destination CIDR Block, choose the appropriate Compartment, and select the target Internet Gateway. Then click Add Route Rules.
- The route rule has been successfully added to the custom route table, and the custom route table is now configured to route traffic according to the specified destination and target.
- Now, navigate to Subnets, select the Public Subnet, and click Edit. Associate the subnet with the newly created custom route table instead of default route table, and then save the changes.
- We can see that the Public Subnet is now associated with the custom route table that we have created instead of the default route table.
Explanation:-
When a subnet is created, it is typically associated with the VCN's default route table. By updating the subnet to use a custom route table, the subnet will follow the routing rules defined in the custom route table rather than the default one. This allows you to control how traffic is routed, such as directing internet-bound traffic through a specific Internet Gateway, NAT Gateway, or other network target.
Traffic Flow Before:
Public Subnet → Default Route Table → Route Rules in Default Route Table
Traffic Flow After:
Public Subnet → Custom Route Table → Route Rules in Custom Route Table
This ensures that the Public Subnet uses the routing configuration you explicitly defined in the custom route table.
Default Route Table vs Custom Route Table (OCI)
| Feature | Default Route Table | Custom Route Table |
|---|---|---|
| Creation | Automatically created with the VCN | Manually created by the administrator |
| Management | Managed as the default routing option | Fully customizable based on requirements |
| Association | Used by subnets unless another route table is assigned | Must be explicitly associated with a subnet |
| Flexibility | Limited to common routing needs | Supports different routing policies for different subnets |
| Use Case | Simple network environments | Complex or segmented network architectures |
Why Use a Custom Route Table if a Default Route Table Already Exists?
A custom route table allows different subnets to have different routing behaviors within the same VCN. This provides greater control, security, and network segmentation.
Example
- Public Subnet: Route traffic to an Internet Gateway for internet access.
- Private Subnet: Route traffic to a NAT Gateway without exposing resources directly to the internet.
- Hub-and-Spoke Network: Different subnets can route traffic through different gateways or DRGs based on business requirements.
Key Benefit
Custom route tables provide granular routing control, while the default route table is suitable only for basic routing requirements.