Managing static routes

You can also configure static routes of a router by manually adding entries into its routing table. This can be useful, for example, if you do not need a mutual connection between two virtual networks and want only one virtual network to be accessible from the other.

Consider the following example:

  • The virtual machine VM1 is connected to the virtual network private1 (192.168.128.0/24) via the network interface with IP address 192.168.128.10.
  • The virtual machine VM2 is connected to the virtual network private2 (192.168.30.0/24) via the network interface with IP address 192.168.30.10.
  • The router router1 connects the network private1 to the physical network via the external gateway with the IP address 10.94.129.73.
  • The router router2 connects the network private2 to the physical network via the external gateway with the IP address 10.94.129.74.

To be able to access VM2 from VM1, you need to add a static route for router1, specifying the CIDR of private2, that is 192.168.30.0/24, as the destination subnet and the external gateway IP address of router2, that is 10.94.129.74, as the next hop IP address. In this case, when an IP packet for 192.168.30.10 reaches router1, it will be forwarded to router2 and then to VM2.

Prerequisites

To create a static route for a router

Admin panel

  1. On the Routers screen, click the router name. Open the Static routes tab, and then click Add on the right pane. If there are no routes to show, click Add static route.
  2. In the Add static route window, specify the destination subnet range and mask in CIDR notation and the next hop’s IP address. The next hop’s IP address must belong to one of the networks that the router is connected to.

  3. Click Add.

Command-line interface

Use the following command:

vinfra service compute router set --route <destination=destination,
                                  nexthop=nexthop> <router>
--route <destination=destination,nexthop=nexthop>

A static route for the router. This option can be used multiple times.

  • destination: destination subnet range in CIDR notation.
  • nexthop: next hop IP address from one of the networks that the router is connected to.
<router>
Virtual router name or ID

For example, to create a static route for the virtual router myrouter with the destination subnet 192.128.30.0/24 and the next top IP address 10.94.129.74, run:

# vinfra service compute router set myrouter --route destination=192.128.30.0/24,nexthop=10.94.129.74
+-----------------------+--------------------------------------------------+
| Field                 | Value                                            |
+-----------------------+--------------------------------------------------+
| external_gateway_info | enable_snat: false                               |
|                       | ip_addresses:                                    |
|                       | - 10.94.129.76                                   |
|                       | network_id: 720e45bc-4225-49de-9346-26513d8d1262 |
| id                    | b9d8b000-5d06-4768-9f65-2715250cda53             |
| name                  | myrouter                                         |
| project_id            | 894696133031439f8aaa7e4868dcbd4d                 |
| routes                | - destination: 192.128.30.0/24                   |
|                       |   nexthop: 10.94.129.74                          |
| status                | ACTIVE                                           |
+-----------------------+--------------------------------------------------+

To edit a static route

Admin panel

  1. Click the ellipsis icon next to the required static route, and then click Edit.
  2. In the Edit static route window, change the desired parameters, and then click Save.

Command-line interface

Use the following command:

vinfra service compute router set --route <destination=destination,
                                  nexthop=nexthop> <router>
--route <destination=destination,nexthop=nexthop>

A static route for the router. This option can be used multiple times.

  • destination: destination subnet range in CIDR notation.
  • nexthop: next hop IP address from one of the networks that the router is connected to.
<router>
Virtual router name or ID

For example, to edit the destination subnet to 192.168.30.0/24 and the next top IP address 10.94.129.15 for the virtual router myrouter, run:

# vinfra service compute router set myrouter --route destination=192.168.30.0/24,nexthop=10.94.129.15
+-----------------------+--------------------------------------------------+
| Field                 | Value                                            |
+-----------------------+--------------------------------------------------+
| external_gateway_info | enable_snat: false                               |
|                       | ip_addresses:                                    |
|                       | - 10.94.129.76                                   |
|                       | network_id: 720e45bc-4225-49de-9346-26513d8d1262 |
| id                    | b9d8b000-5d06-4768-9f65-2715250cda53             |
| name                  | myrouter                                         |
| project_id            | 894696133031439f8aaa7e4868dcbd4d                 |
| routes                | - destination: 192.168.30.0/24                   |
|                       |   nexthop: 10.94.129.15                          |
| status                | ACTIVE                                           |
+-----------------------+--------------------------------------------------+

To remove a static route

Admin panel

Click the ellipsis icon next to the static route you want to remove, and then click Delete.

Command-line interface

Use the following command:

vinfra service compute router set --no-route <router>
--no-route
Clear routes associated with the router
<router>
Virtual router name or ID

For example, to delete all of the static routes for the virtual router myrouter, run:

# vinfra service compute router set myrouter --no-route
+-----------------------+--------------------------------------------------+
| Field                 | Value                                            |
+-----------------------+--------------------------------------------------+
| external_gateway_info | enable_snat: false                               |
|                       | ip_addresses:                                    |
|                       | - 10.94.129.76                                   |
|                       | network_id: 720e45bc-4225-49de-9346-26513d8d1262 |
| id                    | b9d8b000-5d06-4768-9f65-2715250cda53             |
| name                  | myrouter                                         |
| project_id            | 894696133031439f8aaa7e4868dcbd4d                 |
| routes                | []                                               |
| status                | ACTIVE                                           |
+-----------------------+--------------------------------------------------+