Creating static routes

    Note

    The default static route (0.0.0.0/0) is used for VMs with public IPs. If you need to create a NAT instance, create it in a separate subnet.

    To create a route table and add static routes:

    1. Open the Virtual Private Cloud section in the folder where you want to create a static route.

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

    3. Click imageCreate route table.

    4. Enter a name for the route table.

      The name must be unique within the folder. The name may contain lowercase Latin letters, numbers, and hyphens. The first character must be a letter. The last character can't be a hyphen. The maximum length of the name is 63 characters.

    5. Click Add route.

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

    7. Specify the next hop, which is an IP address from the allowed ranges.

    8. Click Add.

    9. Click Create route table.

    To use static routes, link the route table to a subnet:

    1. In the line with the desired subnet, click image.
    2. In the menu that opens, select Link route table.
    3. In the window that opens, select the created table from the list.
    4. Click Add.

    To create a route table and add static routes:

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

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

      $ yc vpc network list
      +----------------------+-----------------+
      |          ID          |      NAME       |
      +----------------------+-----------------+
      | enp34hbpj8dqebn3621l | yc-auto-subnet  |
      | enp846vf5fus0nt3lu83 | routes-test     |
      +----------------------+-----------------+
      
    3. Create a routing table in one of the networks. Use the following flags:

      • name — The name of the route table.
      • network-id — The ID of the network where the tables will be created.
      • route — The route settings with two parameters:
        • destination — The destination subnet prefix in CIDR notation.
        • next-hop — The internal IP address of the VM from the allowed ranges that traffic is sent through.
      $ yc vpc route-table create --name=test-route-table --network-id=enp846vf5fus0nt3lu83 --route destination=0.0.0.0/0,next-hop=192.168.1.5
      ...done
      id: enpsi6b08q2vfdmppsnb
      folder_id: b1gqs1teo2q2a4vnmi2t
      created_at: "2019-06-24T09:57:54Z"
      name: test-route-table
      network_id: enp846vf5fus0nt3lu83
      static_routes:
      - destination_prefix: 0.0.0.0/0
        next_hop_address: 192.168.1.5
      

    To use static routes, link the route table to a subnet:

    1. Get a list of subnets in your cloud:

      $ yc vpc subnet list
      +----------------------+------------------+----------------------+----------------+---------------+------------------+
      |          ID          |       NAME       |      NETWORK ID      | ROUTE TABLE ID |     ZONE      |      RANGE       |
      +----------------------+------------------+----------------------+----------------+---------------+------------------+
      | b0cf2b0u7nhl75gp1c9t | subnet-1         | enp846vf5fus0nt3lu83 |                | ru-central1-c | [192.168.0.0/24] |
      | e2llnffvbakqu18hr170 | subnet-2         | enp846vf5fus0nt3lu83 |                | ru-central1-b | [192.168.1.0/24] |
      +----------------------+------------------+----------------------+----------------+---------------+------------------+
      
    2. Link the routing table to one of the subnets:

      $ yc vpc subnet update b0cf2b0u7nhl75gp1c9t --route-table-id enp1sdveovdpdhaao5dq
      ..done
      id: b0cf2b0u7nhl75gp1c9t
      folder_id: b1gqs1teo2q2a4vnmi2t
      created_at: "2019-03-12T13:27:22Z"
      name: subnet-1
      network_id: enp846vf5fus0nt3lu83
      zone_id: ru-central1-c
      v4_cidr_blocks:
      - 192.168.0.0/24
      route_table_id: enp1sdveovdpdhaao5dq