How to configure static routes: Difference between revisions

From Alpine Linux
m (Marked a dead link.)
Line 36: Line 36:
         up ip route add 192.168.100.0/23 via 192.168.0.3
         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: [http://5718wiki.gatorfone.com/wikka.php?wakka=KennyAralAlpine How to Boot Alpine Linux and Save Settings on a USB Stick] or [[Alpine_local_backup]]
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: [http://5718wiki.gatorfone.com/wikka.php?wakka=KennyAralAlpine 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:
You can verify your settings by restarting the server, or by issuing the following commands:

Revision as of 02:10, 20 December 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 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[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):

/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.