Add static route

Occasionally, a static route will be required to access certain IP ranges on the network.


In order to test the details of the route, it is easiest to manually add entries to the routing table.

ip r add $cidr_subnet via $gateway

For example, let's say the IP of your machine is and you want to route to the network via the gateway 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

ip r add via

To remove the route when you are finished testing, simply replace add with del

ip r del via


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.

  1. 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 using enp2s0 to access the gateway, then you'll need to download /etc/netctl/enp2s0.

  2. Edit the file in a Unix compatible text editor. Most modern editors will work (Atom, VSCode, Sublime Notepad++), but avoid older programs like Notepad.

  3. 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')

    Routes=(' via')
  4. Save the changes and upload the file to the device, replacing the old configuration file

  5. Restart the interface, e.g. netctl restart enp2s0

Last updated