Creating a Route

You can create a route in a route table to specify how traffic is routed for virtual machines (VMs) in its associated Subnets.

You can create routes using the following targets:

  • An Internet gateway, to enable VMs with an associated public IP to directly connect to the Internet

  • A virtual gateway, to route traffic to a DirectLink or a VPN connection

  • A NAT service, to enable VMs to indirectly connect to the Internet

  • A VM

  • A network interface of a VM

  • A Net peering, to enable VMs to forward traffic to a peered Net

When you create a Net access point, the appropriate route is automatically created and added to the route tables you specify. For more information, see About Route Tables and About Net Access Points.

Creating a Route Using Cockpit v2

Before you begin: Create a route table. For more information, see Creating a Route Table.

  1. In the Route Tables dashboard, click the ID of the route table in which you want to create a route.
    The route table details panel appears.

  2. Click IconAddFull Create Route.
    The CREATE ROUTE dialog box appears.

  3. In the Target list, select the ID of the resource to use as target.
    For more information, see About Route Tables > Routes and Routing Options.

  4. In the Destination field, type the destination range of IPs, in CIDR notation.

    To specify the 0.0.0.0/0 CIDR, click All IPs.

  5. Click Create.
    The route is created.

Creating a Route Using OSC CLI

Before you begin: Create a route table. For more information, see Creating a Route Table.

The CreateRoute command creates a route in a specified route table within a specified Net.
You must specify one of the following elements as the target:

  • Net peering

  • NAT VM

  • Internet service

  • Virtual gateway

  • NAT service

  • Network interface card (NIC)

The routing algorithm is based on the most specific match.

For more information, see About Route Tables.

Request sample: Creating a route to an Internet service
$ osc-cli api CreateRoute --profile "default" \
    --RouteTableId "rtb-12345678" \
    --DestinationIpRange "0.0.0.0/0" \
    --GatewayId "igw-12345678"

This command contains the following attributes that you need to specify:

  • DestinationIpRange: The IP range used for the destination match, in CIDR notation (for example, 10.0.0.0/24).

  • DryRun: (optional) If true, checks whether you have the required permissions to perform the action.

  • GatewayId: (optional) The ID of an Internet service or virtual gateway attached to your Net.

  • NatServiceId: (optional) The ID of a NAT service.

  • NetPeeringId: (optional) The ID of a Net peering.

  • NicId: (optional) The ID of a NIC.

  • RouteTableId: The ID of the route table for which you want to create a route.

  • VmId: (optional) The ID of a NAT VM in your Net (attached to exactly one NIC).

The CreateRoute command returns the following elements:

  • ResponseContext: Information about the context of the response.

  • RouteTable: Information about the route table.

Result sample: Creating a route to an Internet service
{
  "RouteTable": {
    "Routes": [
      {
        "DestinationIpRange": "10.0.0.0/16",
        "CreationMethod": "CreateRouteTable",
        "State": "active"
      },
      {
        "GatewayId": "igw-12345678",
        "DestinationIpRange": "0.0.0.0/0",
        "CreationMethod": "CreateRoute",
        "State": "active"
      }
    ],
    "LinkRouteTables": [],
    "NetId": "vpc-12345678",
    "Tags": [],
    "RoutePropagatingVirtualGateways": [],
    "RouteTableId": "rtb-12345678"
  },
  "ResponseContext": {
    "RequestId": "0475ca1e-d0c5-441d-712a-da55a4175157"
  }
}

Creating a Route Using AWS CLI

Before you begin: Create a route table. For more information, see Creating a Route Table.

To create a route in a route table, use the create-route command following this syntax:

Request sample
$ aws ec2 create-route \
    --profile YOUR_PROFILE \
    --route-table-id rtb-87654321 \
    --destination-cidr-block 0.0.0.0/0 \
    --gateway-id igw-1234abcd \
    [--instance-id NOT_SPECIFIED] \
    [--network-interface-id NOT_SPECIFIED] \
    [--vpc-peering-connection-id NOT_SPECIFIED] \
    [--nat-gateway-id NOT_SPECIFIED] \
    --endpoint https://fcu.eu-west-2.outscale.com

This command contains the following attributes that you need to specify:

  • (optional) profile: The named profile you want to use, created when configuring AWS CLI. For more information, see Installing and Configuring AWS CLI.

  • route-table-id: The ID of the route table in which you want to create a route.

  • destination-cidr-block: The destination range of IPs, in CIDR notation.

  • (optional) gateway-id: The ID of the Internet gateway or virtual private gateway attached to the VPC to use as the route target.

  • (optional) instance-id: The ID of an instance in the VPC to use as the route target.

    The instance must only have one network interface attached (the primary one, and no flexible network interfaces). If the instance has several network interfaces attached, use the network-interface-id attribute to specify the one you want to use as the route target.

  • (optional) network-interface-id: The ID of a network interface to use as the route target (the primary network interface or a flexible network interface).

  • (optional) vpc-peering-connection-id: The ID of a VPC peering connection to use as the route target.

  • (optional) nat-gateway-id: The ID of a NAT gateway to use as the route target.

  • endpoint: The endpoint corresponding to the Region you want to send the request to.

The create-route command returns true if the request succeeded and the route is created. Otherwise, it returns an error.

Related Pages

Corresponding API Methods

AWS™ and Amazon Web Services™ are trademarks of Amazon Technologies, Inc or its affiliates in the United States and/or other countries.