Modifying a Route

You can modify a route that you created in a route table by replacing it with another one. This action automatically modifies the way traffic is routed for the Subnets associated with this route table.

Updating a Route Using OSC CLI

The UpdateRoute command replaces an existing route within a route table in a Net.
You must specify one of the following elements as the target:

  • Net peering

  • NAT virtual machine (VM)

  • Internet service

  • Virtual gateway

  • NAT service

  • Network interface card (NIC)

The routing algorithm is based on the most specific match.

Request sample: Updating a route to a virtual gateway
$ osc-cli api UpdateRoute --profile "default" \
    --RouteTableId "rtb-12345678" \
    --DestinationIpRange "198.51.100.0/24" \
    --GatewayId "vgw-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 network interface card (NIC).

  • RouteTableId: The ID of the route table.

  • VmId: (optional) The ID of a NAT VM in your Net.

The UpdateRoute command returns the following elements:

  • ResponseContext: Information about the context of the response.

  • RouteTable: Information about the route table.

Result sample: Updating a route to a virtual gateway
{
  "RouteTable": {
    "Routes": [
      {
        "DestinationIpRange": "10.0.0.0/16",
        "CreationMethod": "CreateRouteTable",
        "State": "active"
      },
      {
        "GatewayId": "vgw-12345678",
        "DestinationIpRange": "198.51.100.0/24",
        "CreationMethod": "CreateRoute",
        "State": "active"
      }
    ],
    "LinkRouteTables": [
      {
        "RouteTableId": "rtb-12345678",
        "Main": false,
        "SubnetId": "subnet-12345678",
        "LinkRouteTableId": "rtbassoc-12345678"
      }
    ],
    "NetId": "vpc-12345678",
    "Tags": [],
    "RoutePropagatingVirtualGateways": [],
    "RouteTableId": "rtb-12345678"
  },
  "ResponseContext": {
    "RequestId": "0475ca1e-d0c5-441d-712a-da55a4175157"
  }
}

Modifying a Route Using AWS CLI

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

Request sample
$ aws ec2 replace-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 replace 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 to specify which 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 route is modified according to the specified destination and target.

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.