How to configure static routes

From Alpine Linux
This material is obsolete ...

These directions need to be updated for Alpine v3.10+ (Discuss)

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 netmask gw"

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 editor to create the file /etc/route.conf Add each static route on a separate line - for example:

net netmask gw
net netmask gw

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
       up ip route add via
       up ip route add via

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[Dead Link] 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):

rc-service staticroute start

To remove your defined static routes:

rc-service staticroute stop

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