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 IconView details icon 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.

    • RequestId: The ID of the request.

  • RouteTable: Information about the route table.

    • LinkRouteTables: One or more associations between the route table and Subnets.

      • LinkRouteTableId: The ID of the association between the route table and the Net or Subnet.

      • Main: If true, the route table is the main one.

      • NetId: The ID of the Net, if the route table is not explicitly linked to a Subnet.

      • RouteTableId: The ID of the route table.

      • SubnetId: The ID of the Subnet, if the route table is explicitly linked to a Subnet.

    • NetId: The ID of the Net for the route table.

    • RoutePropagatingVirtualGateways: Information about virtual gateways propagating routes.

      • VirtualGatewayId: The ID of the virtual gateway.

    • RouteTableId: The ID of the route table.

    • Routes: One or more routes in the route table.

      • CreationMethod: The method used to create the route.

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

      • DestinationServiceId: The ID of the OUTSCALE service.

      • GatewayId: The ID of the internet service or virtual gateway attached to the Net.

      • NatServiceId: The ID of a NAT service attached to the Net.

      • NetAccessPointId: The ID of the Net access point.

      • NetPeeringId: The ID of the Net peering.

      • NicId: The ID of the NIC.

      • State: The state of a route in the route table (always active).

      • VmAccountId: The account ID of the owner of the VM.

      • VmId: The ID of a VM specified in a route in the table.

    • Tags: One or more tags associated with the route table.

      • Key: The key of the tag, with a minimum of 1 character.

      • Value: The value of the tag, between 0 and 255 characters.

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 oapi-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
$ oapi-cli --profile "default" CreateRoute \
    --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.

    • RequestId: The ID of the request.

  • RouteTable: Information about the route table.

    • LinkRouteTables: One or more associations between the route table and Subnets.

      • LinkRouteTableId: The ID of the association between the route table and the Net or Subnet.

      • Main: If true, the route table is the main one.

      • NetId: The ID of the Net, if the route table is not explicitly linked to a Subnet.

      • RouteTableId: The ID of the route table.

      • SubnetId: The ID of the Subnet, if the route table is explicitly linked to a Subnet.

    • NetId: The ID of the Net for the route table.

    • RoutePropagatingVirtualGateways: Information about virtual gateways propagating routes.

      • VirtualGatewayId: The ID of the virtual gateway.

    • RouteTableId: The ID of the route table.

    • Routes: One or more routes in the route table.

      • CreationMethod: The method used to create the route.

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

      • DestinationServiceId: The ID of the OUTSCALE service.

      • GatewayId: The ID of the internet service or virtual gateway attached to the Net.

      • NatServiceId: The ID of a NAT service attached to the Net.

      • NetAccessPointId: The ID of the Net access point.

      • NetPeeringId: The ID of the Net peering.

      • NicId: The ID of the NIC.

      • State: The state of a route in the route table (always active).

      • VmAccountId: The account ID of the owner of the VM.

      • VmId: The ID of a VM specified in a route in the table.

    • Tags: One or more tags associated with the route table.

      • Key: The key of the tag, with a minimum of 1 character.

      • Value: The value of the tag, between 0 and 255 characters.

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:

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. For more information, see Installing and Configuring AWS CLI.

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.