Difference between revisions of "How to configure static routes"

From Alpine Linux
Jump to: navigation, search
(delete Category:HOWTO)
Line 1: Line 1:
This document describes how to configure persistent static routes in Alpine Linux so that the route definitions survive server reboots.  
+
This document describes how to configure persistent static routes in Alpine Linux so the route definitions survive server reboots.  
  
 
This process was tested with release 2.1.4, dated 2011-01-07.
 
This process was tested with release 2.1.4, dated 2011-01-07.
Line 15: Line 15:
 
  staticroute="net 10.200.200.0 netmask 255.255.255.0 gw 192.168.202.12"
 
  staticroute="net 10.200.200.0 netmask 255.255.255.0 gw 192.168.202.12"
  
If you need to add multiple static routes, just add additional routes to the end of the text between the quotes, with each route separated by a semicolon or a line break (press ENTER).
+
If you need to add multiple static routes, just add additional routes to the end of the text between the quotes with each route separated by a semicolon or a line break (press ENTER).
  
 
==Option 2: Create /etc/route.conf==
 
==Option 2: Create /etc/route.conf==
  
Use nano, vi, or your favourite installed editor to create the file /etc/route.conf and add each static route on a separate line - for example:
+
Use nano, vi, or your favourite installed editor to create the file /etc/route.conf  
 +
Add each static route on a separate line - for example:
  
 
  net 10.200.200.0 netmask 255.255.255.0 gw 192.168.200.12
 
  net 10.200.200.0 netmask 255.255.255.0 gw 192.168.200.12
 
  net 10.200.201.0 netmask 255.255.255.0 gw 192.168.200.13
 
  net 10.200.201.0 netmask 255.255.255.0 gw 192.168.200.13
  
==Option 3: Setup routes in /etc/network/interfaces==
+
==Option 3: Set up routes in /etc/network/interfaces==
  
If you have static network configuration in /etc/network/interfaces, you can add a static route that gets activated when an interface gets brought up:
+
If you have static network configuration in /etc/network/interfaces, you can add a static route that gets activated when an interface is brought up:
  
 
  auto eth0
 
  auto eth0

Revision as of 07:05, 23 July 2021

This document describes how to configure persistent static routes in Alpine Linux so the route definitions survive server reboots.

This process was tested with release 2.1.4, dated 2011-01-07.

First, set the staticroute service to start automatically on boot by entering the following command:

rc-update add staticroute

You can now define your static routes in one of three ways:

Option 1: Edit /etc/conf.d/staticroute

Routes are added as a parameter value - the staticroute file has header information that explains the syntax - for example:

staticroute="net 10.200.200.0 netmask 255.255.255.0 gw 192.168.202.12"

If you need to add multiple static routes, just add additional routes to the end of the text between the quotes with each route separated by a semicolon or a line break (press ENTER).

Option 2: Create /etc/route.conf

Use nano, vi, or your favourite installed editor to create the file /etc/route.conf Add each static route on a separate line - for example:

net 10.200.200.0 netmask 255.255.255.0 gw 192.168.200.12
net 10.200.201.0 netmask 255.255.255.0 gw 192.168.200.13

Option 3: Set up routes in /etc/network/interfaces

If you have static network configuration in /etc/network/interfaces, you can add a static route that gets activated when an interface is brought up:

auto eth0
iface eth0 inet static
       address 192.168.0.1
       netmask 255.255.255.0
       up ip route add 10.14.0.0/16 via 192.168.0.2
       up ip route add 192.168.100.0/23 via 192.168.0.3

Once editing is complete, remember to save your changes if you are running the OS in RAM (eg: booting from a USB stick) - if you are not sure how to do this, see this article: How to Boot Alpine Linux and Save Settings on a USB Stick or Alpine_local_backup

You can verify your settings by restarting the server, or by issuing the following commands:

To add your defined static routes manually (for testing):

/etc/init.d/staticroute start

To remove your defined static routes:

/etc/init.d/staticroute stop

There is a 'restart' option to do an automatic stop/start, but it seems less reliable than using the two above.