Add static route
Occasionally, a static route will be required to access certain IP ranges on the network.
Temporary
In order to test the details of the route, it is easiest to manually add entries to the routing table.
For example, let's say the IP of your machine is 192.168.1.10/24
and you want to route to the 10.1.1.0/24
network via the gateway 192.168.1.20
. Keep in mind that the gateway MUST be on the same subnet as your machine IP. To temporarily add the route, use the following command
To remove the route when you are finished testing, simply replace add
with del
Permanent
Once you are satisfied that the details of the route are correct, follow these steps to make the route a permanent fixure of the network interface.
Download a copy of the network configuration file. These are stored in
/etc/netctl
and are share the same name as the interface. If you are usingenp2s0
to access the gateway, then you'll need to download/etc/netctl/enp2s0
.Edit the file in a Unix compatible text editor. Most modern editors will work (Atom, VSCode, Sublime Notepad++), but avoid older programs like Notepad.
Add the following line to the end of the file, replacing the route with your required values. Essentially it is everything after the keyword
add
in the Temporary stage. If multiple routes are required, leave a single space between each entry, e.g.('net1 via gw' 'net2 via gw')
Save the changes and upload the file to the device, replacing the old configuration file
Restart the interface, e.g.
netctl restart enp2s0
Last updated