---
title: "Configure static routes on dedicated servers"
sidebar_label: "Static routes"
sidebar_position: 10
description: "How to specify static routes on a server, examples of configuring connectivity between a dedicated server and a cloud server, routing internet traffic through a firewall, and connectivity with external infrastructure"
toc_max_heading_level: 2
---

import Formbricks from '@theme/MDXComponents/Formbricks'
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import {TabItemLabel} from '@selectel/docux/components'
import MoreVerticalIcon from '@selectel/docux/icons/more-vertical'
import {CustomTable} from '@selectel/docux/components'

# Configure static routes on dedicated servers

Static routing is a type of routing where routes are explicitly defined when configuring a network interface on a server or router.

To configure static routing, [add static routes on the server](#write-routes-on-server).

Examples of tasks that can be solved using static routing:

* [connect dedicated servers and a cloud server over a private network](#example-of-static-routes-to-connect-dedicated-and-cloud-servers) ; &#x20;
* [route internet traffic through a firewall](#example-of-static-routes-to-route-traffic-via-firewall);
* [configure connectivity with external infrastructure through a firewall](#example-of-static-routes-to-connect-to-external-infrastructure-via-firewall).

## Specify static routes on a server \{#write-routes-on-server}

<Tabs queryString="write-routes-on-server">
  <TabItem value="ubuntu" default>
    <TabItemLabel>
      Ubuntu
    </TabItemLabel>

    1. [Connect to the server](/dedicated/manage/connect-to-server.mdx).

    2. View the configuration file name of the `netplan` utility:

       ```bash
       ls /etc/netplan/
       ```

       The response will show the configuration file name. For example:

       ```bash
       01-netcfg.yaml
       ```

       Copy the configuration file name.

    3. Open the configuration file of the `netplan` utility with the text editor `vi`:

       ```bash
       vi /etc/netplan/<file_name>
       ```

       Specify `<file_name>` — the configuration file name that you copied in step 2.

    4. At the end of the block with parameters of the required network interface, add a route:

       ```bash
       routes:
       - to:  <ip_address>/<mask>
         via: <gateway>
       ```

       Specify:

       * `<ip_address>` — subnet to which the route is needed;
       * `<mask>` — subnet mask for the subnet to which the route is needed;
       * `<gateway>` — gateway for the current server subnet, for example, the gateway specified on the global router. The gateway address must be in the same subnet as the server.

    5. If you need to configure multiple routes, add them sequentially in the same block, for example:

       ```bash
       routes:
       - to:  192.168.0.0/28
         via: 192.168.0.1
       - to:  192.168.1.0/28
         via: 192.168.0.1
       ```

    6. Press **ESC**.

    7. Exit the text editor `vi` saving changes:

       ```bash
       :wq
       ```

    8. Check the route configuration:

       ```bash
       sudo netplan try
       ```

    9. Apply the changes:

       ```bash
       netplan apply
       ```
  </TabItem>

  <TabItem value="debian">
    <TabItemLabel>
      Debian
    </TabItemLabel>

    1. [Connect to the server](/dedicated/manage/connect-to-server.mdx).

    2. View the configuration file name of the `ifupdown` utility:

       ```bash
       ls /etc/network/interfaces.d/
       ```

       The response will show the configuration file name. For example:

       ```bash
       50-cloud-init
       ```

       Copy the configuration file name.

    3. Open the configuration file of the `ifupdown` utility with the text editor `vi`:

       ```bash
       vi /etc/network/interfaces.d/<file_name>
       ```

       Specify `<file_name>` — the configuration file name that you copied in step 2.

    4. At the end of the block with parameters of the corresponding network interface, add a route:

       ```bash
       up route add -net <ip_address> netmask <mask> gw <gateway>
       down route del -net <ip_address> netmask <mask> gw <gateway>
       ```

       Specify:

       * `<ip_address>` — subnet to which the route is needed, for example `192.168.0.0`;
       * `<mask>` — subnet mask for the subnet to which the route is needed, for example `255.255.255.0`;
       * `<gateway>` — gateway for the current server subnet, for example, the gateway specified on the global router. The gateway address must be in the same subnet as the server

    5. If you need to configure multiple routes, add them sequentially in the same block.

    6. Press **ESC**.

    7. Exit the text editor `vi` saving changes:

       ```bash
       :wq
       ```

    8. Restart the network:

       ```bash
       sudo /etc/init.d/networking restart
       ```
  </TabItem>

  <TabItem value="centos">
    <TabItemLabel>
      CentOS
    </TabItemLabel>

    1. [Connect to the server](/dedicated/manage/connect-to-server.mdx).

    2. Create and populate the static route configuration file:

       ```bash
       echo "<ip_address>/<mask> via <gateway>" >> /etc/sysconfig/network-scripts/route-<eth_name>
       ```

       Specify:

       * `<ip_address>` — subnet to which the route is needed;
       * `<mask>` — subnet mask for the subnet to which the route is needed;
       * `<gateway>` — gateway for the current server subnet, for example, the gateway specified on the global router. The gateway address must be in the same subnet as the server;
       * `<eth_name>` — name of the corresponding private network interface.

    3. If you need to add multiple routes, specify them in a single command. Specify each route on a new line, for example:

       ```bash
       echo "192.168.0.0/28 via 172.16.0.1
       192.168.1.0/28 via 172.16.0.1" >> /etc/sysconfig/network-scripts/route-eno2
       ```

    4. Restart the network:

       ```bash
       systemctl restart network
       ```
  </TabItem>

  <TabItem value="windows">
    <TabItemLabel>
      Windows
    </TabItemLabel>

    1. [Connect to the server via RDP](/dedicated/manage/connect-to-server.mdx#connect-via-rdp) or via the [KVM console](/dedicated/manage/connect-to-server.mdx#connect-via-kvm-console).

    2. Add the required routes one by one:

       ```bash
       route -p ADD <ip_address> MASK <mask> <gateway> METRIC <x>
       ```

       Specify:

       * `<ip_address>` — subnet to which the route is needed, for example `192.168.0.0`;
       * `<mask>` — subnet mask for the subnet to which the route is needed, for example `255.255.255.0`;
       * `<gateway>` — gateway for the current server subnet, for example, the gateway specified on the global router. The gateway address must be in the same subnet as the server;
       * `<x>` — parameter that determines the priority of the specified gateway, 1 being the highest priority.
  </TabItem>
</Tabs>

## Example of configuring static routes for connecting dedicated servers and a cloud server over a private network \{#example-of-static-routes-to-connect-dedicated-and-cloud-servers}

### Goal \{#configuration-purpose-dedicated-to-cloud}

Connect two dedicated servers in the SPB-2 pool and a cloud server in the ru-2 pool with a private network using a global router, and configure routing in the network so that the devices can communicate with each other.

### Prerequisites \{#what-is-required-dedicated-to-cloud}

In the configuration example, we used two dedicated servers in the SPB-2 pool with access to a private network and a cloud server in the ru-2 pool.

### Result \{#configuration-result-dedicated-to-cloud}

Private connectivity will be configured between two dedicated servers in the SPB-2 pool and a cloud server in the ru-2 pool.

![](https://423.selcdn.ru/kb/dedic-static-routes-example-connect-dedicated-and-cloud-servers-LANG-THEME.png)

### Configuration steps \{#configuration-steps-dedicated-to-cloud}

1. [Create a global router](/global-router/create-network/create-global-router-network.mdx#create-global-router).

2. [Connect private subnets to the global router](/global-router/create-network/create-global-router-network.mdx#connect-networks-and-subnets-to-global-router):

   * `192.168.0.0/28` to the VLAN where the dedicated servers in the SPB-2 pool are located;
   * `172.16.0.0/28` for the Cloud Platform project in the ru-2 pool.

3. Assign IP addresses from the private subnets you connected to the global router to the dedicated servers and cloud server. For more information, see the [Assign IP addresses to servers](/global-router/create-network/create-global-router-network.mdx#assign-ip-addresses-on-servers) section.

4. Configure routes:

   * on each [dedicated server](#write-routes-on-server) in the SPB-2 pool — to the subnet `172.16.0.0/28` via the gateway `192.168.0.1`;
   * on the [cloud server](/cloud-servers/cloud-networks/static-routes/) in the ru-2 pool — to the subnet `192.168.0.0/28` via the gateway `172.16.0.1`.

## Example of configuring static routes to direct Internet traffic through a firewall \{#example-of-static-routes-to-route-traffic-via-firewall}

### Goal \{#configuration-purpose-route-traffic-via-firewall}

Direct Internet traffic to a dedicated server through a firewall.

### Prerequisites \{#what-is-required-route-traffic-via-firewall}

In the configuration example, we used a dedicated server with access to a private network and a firewall.

### Result \{#configuration-result-route-traffic-via-firewall}

After configuring routed networks, Internet traffic to the dedicated server will pass through the [firewall](/firewalls/about/about-firewalls.mdx).

![](https://423.selcdn.ru/kb/dedic-static-routes-example-connectivity-via-firewall-LANG-THEME.png)

### Configuration steps \{#configuration-steps-route-traffic-via-firewall}

1. [Configure a static route on the dedicated server](#write-routes-on-server) to the subnet `0.0.0.0/0` via the gateway `198.51.100.1`.

2. Configure default gateway `203.0.113.2` on the firewall.

3. To provide internet access on the dedicated server behind the firewall, [create a ticket](https://my.selectel.ru/tickets/create/) requesting to add a static route to the Selectel router. In the ticket, specify:

   * private subnet of the dedicated server located behind the firewall, in the example — `198.51.100.0/28`;
   * public IP address of the firewall, in the example — `203.0.113.2`.

4. Wait for a response from Selectel confirming that the static route has been configured on the router.

## Example of configuring static routes for connecting to external infrastructure through a firewall \{#example-of-static-routes-to-connect-to-external-infrastructure-via-firewall}

### Goal \{#configuration-purpose-connect-to-external-infrastructure}

Connect two dedicated servers in the MSK-1 and SPB-2 pools to external infrastructure via a private network. Using a global router, configure routing in the network so that devices can communicate with each other, and direct routed network traffic through the firewall in the SPB-3 pool.

### Prerequisites \{#what-is-required-connect-to-external-infrastructure}

In the configuration example, we used two dedicated servers in the MSK-1 and SPB-2 pools with access to a private network, a firewall in the SPB-3 pool, and external infrastructure.

### Result \{#configuration-result-connect-to-external-infrastructure}

Private connectivity will be configured between external infrastructure and the servers in the MSK-1 and SPB-2 pools, and routed network traffic will pass through the firewall in the SPB-3 pool.

![](https://423.selcdn.ru/kb/dedic-static-routes-example-connectivity-to-external-infrastructure-LANG-THEME.png)

### Configuration steps \{#configuration-steps-route-connect-to-external-infrastructure}

1. [Create a global router](/global-router/create-network/create-global-router-network.mdx#create-global-router).

2. [Connect subnets to the global router](/global-router/create-network/create-global-router-network.mdx#connect-networks-and-subnets-to-global-router):

   * `192.168.11.0/24` to the VLAN where the dedicated server in the MSK-1 pool is located;
   * `192.168.22.0/24` to the VLAN where the dedicated server in the SPB-2 pool is located;
   * `192.168.33.0/24` to the VLAN where the firewall in the SPB-3 pool is located.

3. Assign IP addresses from the private subnets you connected to the global router to the dedicated servers. For more information, see the [Assign IP addresses to servers](/global-router/create-network/create-global-router-network.mdx#assign-ip-addresses-on-servers) section.

4. Assign an IP address from the private subnet you connected to the global router to the firewall.

5. [Configure routes on the servers](#write-routes-on-server):

   * in the MSK-1 pool — to the subnets `192.168.22.0/24` and `192.168.33.0/24` via the gateway `192.168.11.1`;
   * in the SPB-2 pool — to the subnets `192.168.11.0/24` and `192.168.33.0/24` via the gateway `192.168.22.1`;

6. Configure routes on the firewall — to the subnets `192.168.11.0/24` and `192.168.22.0/24` via the gateway `192.168.33.1`.

7. [Configure routing on the global router](/global-router/create-network/create-global-router-network.mdx#configure-routing-on-global-router) — specify a static route for outbound traffic to the Internet. Specify:

   * destination subnet — `0.0.0.0/0`;
   * Next hop — firewall IP address, in the example `192.168.33.2`.

<Formbricks />
