Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Virtual Private Cloud
  • Getting started
    • All guides
      • Creating a static route
      • Creating and setting up a NAT gateway
      • Getting information about a NAT gateway
      • Moving a route table between folders
      • Getting information about a route table
      • Moving a NAT gateway between folders
      • Deleting a route table
      • Deleting a NAT gateway
    • Enabling a software-accelerated network
    • Chart of network connections
    • Viewing operations with resources
  • DDoS Protection
  • Access management
  • Terraform reference
  • Audit Trails events
  • Release notes
  • FAQ
  1. Step-by-step guides
  2. Static routing
  3. Creating a static route

Creating a static route

Written by
Yandex Cloud
Improved by
Danila N.
Updated at May 5, 2025

Note

VMs with public IP addresses use the default static route (0.0.0.0/0). If you need to create a NAT instance, create it in a separate subnet.

Management console
CLI
Terraform
API

To create a route table and add static routes to it:

  1. In the management console, go to the folder where you need to create a static route.

  2. In the list of services, select Virtual Private Cloud.

  3. In the left-hand panel, select Routing tables.

  4. Click Create.

  5. Enter a name for the route table. The naming requirements are as follows:

    • It must be from 2 to 63 characters long.
    • It may contain lowercase Latin letters, numbers, and hyphens.
    • It must start with a letter and cannot end with a hyphen.
  6. (Optional) Add a description of a route table.

  7. Select the network to create the route table in.

  8. Click Add.

  9. In the window that opens, enter the destination subnet prefix in CIDR notation.

  10. Specify the Next hop, which is an IP address from the allowed ranges.

  11. Click Add.

  12. Click Create routing table.

To use static routes, associate the route table with a subnet:

  1. In the left-hand panel, select Subnets.
  2. In the row of the subnet you need, click .
  3. In the menu that opens, select Link routing table.
  4. In the window that opens, select the created table from the list.
  5. Click Link.

To create a route table and add static routes to it:

  1. View the description of the CLI command for creating route tables:

    yc vpc route-table create --help
    
  2. Get the IDs of cloud networks in your cloud:

    yc vpc network list
    

    Result:

    +----------------------+-----------------+
    |          ID          |      NAME       |
    +----------------------+-----------------+
    | enp34hbpj8dq******** | yc-auto-subnet  |
    | enp846vf5fus******** | routes-test     |
    +----------------------+-----------------+
    
  3. Create a route table in one of the networks:

    yc vpc route-table create \
      --name=<table_name> \
      --network-id=<network_ID> \
      --route destination=<destination_prefix>,next-hop=<internal_IP_address>
    

    Where:

    • --name: Name of the route table.

    • --network-id: ID of the network where the table will be created.

    • --route: Route settings, which include these two parameters:

      • destination: Destination subnet prefix in CIDR notation, e.g., 0.0.0.0/0.
      • next-hop: Internal IP address of the VM from the allowed ranges the traffic will be sent through, e.g., 192.168.1.5.

    Result:

    ...done
    id: enpsi6b08q2v********
    folder_id: b1gqs1teo2q2********
    created_at: "2019-06-24T09:57:54Z"
    name: test-route-table
    network_id: enp846vf5fus********
    static_routes:
    - destination_prefix: 0.0.0.0/0
      next_hop_address: 192.168.1.5
    

To use static routes, associate the route table with a subnet:

  1. Get a list of subnets in your cloud:

    yc vpc subnet list
    

    Result:

    +----------------------+------------------+----------------------+----------------+---------------+------------------+
    |          ID          |       NAME       |      NETWORK ID      | ROUTE TABLE ID |     ZONE      |      RANGE       |
    +----------------------+------------------+----------------------+----------------+---------------+------------------+
    | b0cf2b0u7nhl******** | subnet-1         | enp846vf5fus******** |                | ru-central1-a | [192.168.0.0/24] |
    +----------------------+------------------+----------------------+----------------+---------------+------------------+
    
  2. Associate the route table with one of the subnets:

    yc vpc subnet update <subnet_ID> \
      --route-table-id <route_table_ID>
    

    Result:

    ..done
    id: b0cf2b0u7nhl********
    folder_id: b1gqs1teo2q2********
    created_at: "2019-03-12T13:27:22Z"
    name: subnet-1
    network_id: enp846vf5fus********
    zone_id: ru-central1-a
    v4_cidr_blocks:
    - 192.168.0.0/24
    route_table_id: enp1sdveovdp********
    

With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.

Terraform is distributed under the Business Source License. The Yandex Cloud provider for Terraform is distributed under the MPL-2.0 license.

For more information about the provider resources, see the documentation on the Terraform website or mirror website.

If you do not have Terraform yet, install it and configure its Yandex Cloud provider.

To create a route table and add static routes to it:

  1. In the configuration file, define the parameters of the resources you want to create:

    • name: Name of the route table. The name format is as follows:

      • It must be from 2 to 63 characters long.
      • It may contain lowercase Latin letters, numbers, and hyphens.
      • It must start with a letter and cannot end with a hyphen.
    • network_id: ID of the network where the table will be created.

    • static_route: Static route description:

      • destination_prefix: Destination subnet prefix in CIDR notation.
      • next_hop_address: Internal IP address of the VM from the allowed ranges the traffic will be routed through.

    Here is an example of the configuration file structure:

    resource "yandex_vpc_route_table" "test-route-table" {
    name       = "<route_table_name>"
      network_id = "<network_ID>"
      static_route {
        destination_prefix = "<destination_prefix>"
        next_hop_address   = "<internal_IP_address>"
      }
    }
    

    To add, update, or delete a route table, use the yandex_vpc_route_table resource indicating the network in the network_id field, e.g., network_id = yandex_vpc_network.test_route_table.id.

    For more information about the yandex_vpc_route_table resource parameters in Terraform, see the relevant provider documentation.

  2. Make sure the configuration files are correct.

    1. In the command line, go to the directory where you created the configuration file.

    2. Run a check using this command:

      terraform plan
      

    If the configuration description is correct, the terminal will display a list of the resources being created and their parameters. If the configuration contains any errors, Terraform will point them out.

  3. Deploy the cloud resources.

    1. If the configuration does not contain any errors, run this command:

      terraform apply
      
    2. Confirm creating the resources: type yes in the terminal and press Enter.

      This will create all the resources you need in the specified folder. You can check the new resources and their settings using the management console or this CLI command:

      yc vpc route-table list
      

      Result:

      +----------------------+-----------------------+-------------+----------------------+
      |          ID          |         NAME          | DESCRIPTION |      NETWORK-ID      |
      +----------------------+-----------------------+-------------+----------------------+
      | enpahlhr1vnl******** | terraform-route-table |             | enp0asmd9pr9******** |
      +----------------------+-----------------------+-------------+----------------------+
      

To create a route table and add static routes to it, use the create REST API method for the RouteTable resource or the RouteTableService/Create gRPC API call, and provide the following in the request:

  • ID of the folder the route table will reside in, in the folderId parameter.

  • Route table name in the name parameter. The name format is as follows:

    • It must be from 2 to 63 characters long.
    • It may contain lowercase Latin letters, numbers, and hyphens.
    • It must start with a letter and cannot end with a hyphen.
  • ID of the network the route table will reside in, in the networkId parameter.

  • Destination subnet prefix in CIDR notation in the staticRoutes[].destinationPrefix parameter.

  • Internal IP address of the VM the traffic will be routed through in the staticRoutes[].nextHopAddress parameter. The IP address must be within the allowed range.

To use static routes, associate the route table with a subnet. Use the update REST API method for the Subnet resource or the SubnetService/Update gRPC API call and provide the following in the request:

  • Subnet ID in the subnetId parameter.

    To get the subnet ID, use the list REST API method for the Subnet resource or the SubnetService/List gRPC API call and provide the folder ID in the folderId request parameter.

    To learn how to find out the folder ID, see Getting the folder ID.

  • Route table ID in the routeTableId parameter.

  • Name of the routeTableId parameter in the updateMask parameter.

Warning

The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the updateMask parameter as a single comma-separated string.

ExampleExample

Create a route table and associate it with your subnet. The example uses the following properties:

  • Folder ID: b1g681qpemb4********
  • Network ID: enp846vf5fus********
  • Subnet ID: b0cf2b0u7nhl********
  • Route table name: test-route-table
  • Destination subnet prefix: 0.0.0.0/0
  • Internal IP address: 192.168.1.5
CLI
Terraform
API
  1. Create a route table:

    yc vpc route-table create \
      --name=test-route-table \
      --network-id=enp846vf5fus******** \
      --route destination=0.0.0.0/0,next-hop=192.168.1.5
    
  2. Associate the route table with your subnet:

    yc vpc subnet update b0cf2b0u7nhl******** \
      --route-table-id enp1sdveovdp********
    
  1. In the configuration file, list the route table properties and specify route_table_id for your subnet:

    resource "yandex_vpc_route_table" "test_route_table" {
      name       = "test-route-table"
      network_id = "enp846vf5fus********"
      static_route {
        destination_prefix = "0.0.0.0/0"
        next_hop_address   = "192.168.1.5"
      }
    }
    
    resource "yandex_vpc_subnet" "example_subnet" {
      name           = "example-subnet"
      network_id     = "enp846vf5fus********"
      zone           = ru-central1-a
      v4_cidr_blocks = ["10.2.0.0/16"]
      # Associating the route table with the subnet
      route_table_id = yandex_vpc_route_table.test_route_table.id
    }
    

    For more information about the resources you can create with Terraform, see the provider documentation.

  2. Make sure the settings are correct.

    1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.

    2. Run this command:

      terraform validate
      

      Terraform will show any errors found in your configuration files.

  3. Apply the changes.

    1. Run this command to view the planned changes:

      terraform plan
      

      If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.

    2. If everything looks correct, apply the changes:

      1. Run this command:

        terraform apply
        
      2. Confirm updating the resources.

      3. Wait for the operation to complete.

  1. To create a route table, use the create REST API method for the RouteTable resource or the RouteTableService/Create gRPC API call, and provide the following in the request body:

    {
      "folderId": "b1g681qpemb4********",
      "name": "test-route-table",
      "networkId": "enp846vf5fus********",
      "staticRoutes": [
        {
          "destinationPrefix": "0.0.0.0/0",
          "nextHopAddress": "192.168.1.5"
        }
      ]
    }
    
  2. To associate a route table with a subnet, use the update REST API method for the Subnet resource or the SubnetService/Update gRPC API call, and provide the following in the request body:

    {
      "updateMask": "routeTableId",
      "subnet": {
        "routeTableId": "enpfs106jh40********"
      }
    }
    

Was the article helpful?

Previous
Deleting a static public IP address
Next
Creating and setting up a NAT gateway
Yandex project
© 2025 Yandex.Cloud LLC