1.5 Administrator's Guide

  1. Home
  2. Docs
  3. 1.5 Administrator’s Guide
  4. Advanced Administration
  5. Adding static routes to the network

Adding static routes to the network

It may be desirable to add static routes for routing of specific subnets via specific
gateways or over specific interfaces.

Applying networking changes from the Com.X GUI over-writes the
/etc/network/interfaces file. Any changes made to this file may be lost
after an apply.

Rather, static routes should be placed in /etc/network/if-up.d/static-routes. This
script will be run when-ever an IP interface comes up. The
interface that triggered the script is available via the IFACE
environment variable.

For example:

#!/bin/bash

if [ “$IFACE” == “eth0” ]; then

sudo ip route add x.x.x.x via y.y.y.y

fi

if [ “$IFACE” == “eth1” ]; then

 sudo ip route add x.x.x.x/24 dev eth1

fi

Ensure the script is executable:

sudo chmod +x /etc/network/if­up.d/static­routes

Restart the interface or alternatively the Com.X:

sudo ifdown eth && sudo ifup eth

Note: It is not recommended to have more than one default route
in the Com.X routing table.