Static routes
Static routing is a type of routing in which routes are specified explicitly when configuring a network interface on a server or router.
To configure static routing, Write static routes on the server.
Examples of problems that can be solved using static routing:
Write static routes on the server
Ubuntu
Debian
CentOS
Windows
-
Open the network interfaces configuration file with the vi text editor:
vi /etc/netplan/01-netcfg.yaml
-
At the end of the parameter block for the desired network interface, add a route:
routes:
- to: <ip_address>/<mask>
via: <gateway>Specify:
<ip_address>
— subnet to which you want to route;<mask>
— subnet mask of the subnet to which you want to route;<gateway>
— The gateway for the subnet of the current server, such as the gateway that is listed on the global router. The gateway address must be on the same subnet as the server.
-
If you need to prescribe multiple routes, add them sequentially in the same block, for example:
routes:
- to: 192.168.0.0/28
via: 172.16.0.1
- to: 192.168.1.0/28
via: 172.16.0.1 -
Exit the vi text editor with your changes saved:
:wq
-
Check the routing configuration:
sudo netplan try
-
Apply the changes:
netplan apply
-
Open the network interfaces configuration file with the vi text editor:
vi /etc/network/interfaces
- Add the desired route at the end of the parameter block for the corresponding network interface:
up route add -net <ip_address> netmask <mask> gw <gateway>
down route del -net <ip_address> netmask <mask> gw <gateway>
Specify:
<ip_address>
— the subnet you want to route to, e.g.192.168.0.0
;<mask>
— the subnet mask to which you want to route, e.g.255.255.255.0
;<gateway>
— The gateway for the subnet of the current server, such as the gateway that is listed on the global router. The gateway address must be on the same subnet as the server
-
If you need to prescribe multiple routes, add them sequentially in the same block.
-
Exit the vi text editor with your changes saved:
:wq
- Restart the network:
sudo /etc/init.d/networking restart
-
Create and complete a file to configure static routes:
echo "<ip_address>/<mask> via <gateway>" >> /etc/sysconfig/network-scripts/route-<eth_name>
Specify:
<ip_address>
— subnet to which you want to route;<mask>
— subnet mask of the subnet to which you want to route;<gateway>
— The gateway for the subnet of the current server, such as the gateway that is listed on the global router. The gateway address must be on the same subnet as the server;<eth_name>
— the name of the corresponding LAN interface.
- If you need to add multiple routes, specify them in one command. Specify each route on a new line, for example:
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
- Restart the network:
systemctl restart network
-
Connect to the server via RDP or through KVM console.
-
Add the required routes one at a time:
route -p ADD <ip_address> MASK <mask> <gateway> METRIC <x>
Specify:
<ip_address>
— the subnet you want to route to, e.g.192.168.0.0
;<mask>
— the subnet mask to which you want to route, e.g.255.255.255.0
;<gateway>
— The gateway for the subnet of the current server, such as the gateway that is listed on the global router. The gateway address must be on the same subnet as the server;<x>
— parameter defining the priority of the specified gateway, 1 is the highest priority.
Example of organizing static routes to connect dedicated servers and a cloud server over a private network
Purpose of customization
Connect the two dedicated servers in the SPB-2 pool and the 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 see each other.
What you need to customize
In the example, we used two dedicated servers in the SPB-2 pool with access to the private network and a cloud server in the ru-2 pool for configuration.
Customization result
Private connectivity will be configured between the two dedicated servers in the SPB-2 pool and the cloud server in the ru-2 pool.
Customization steps
-
Connect private subnets to the global router:
192.168.0.0/28
to the VLAN that contains the dedicated servers in the SPB-2 pool;172.16.0.0/28
for the cloud platform project in the ru-2 pool.
-
Assign IP addresses from the private subnets that you have connected to the global router to the dedicated servers and cloud server. For more information, see the subsection Assign IP addresses to servers.
-
Spell out the routes:
- at each dedicated server in the SPB-2 pool to the subnet.
172.16.0.0/28
through the gateway192.168.0.1
; - on cloud server in the ru-2 pool to the subnet
192.168.0.0/28
through the gateway172.16.0.1
.
- at each dedicated server in the SPB-2 pool to the subnet.