Adding a route after switching on the interface - Post-Up

Quite often one or more explicit routes are needed on a network interface. Here are the quick instructions to put this in the /etc/network/interfaces file.

Here is shown how a route can be added after a network interface has been successfully initialized. However, it is just as important to set the same command to remove the route when shutting down the interface.

Post-up means in this context that the command is only issued when the interface is marked as UP.

You could also set this command with just UP instead of POST-UP.

In this example, a route is set to the destination network 192.168.20.0/24, which is reachable via the gateway 192.168.10.250.

## Edit the file
nano /etc/network/interfaces

## Change the network config to your choise network configuration

auto eth0
allow-hotplug eth0
iface eth0 inet static
     address 192.168.10.10
     netmask 255.255.255.0
     gateway 192.168.10.1
     POST-UP ip route add 192.168.20.0/24 via 192.168.10.250
     POST-DOWN ip route del 192.168.20.0/24 via 192.168.10.250