This post is to help you set up a static persistent route or routes on your Debian and/or Ubuntu.
Servers are generally hooked up to multiple subnets and when need be, your destination is connected to a NIC that isn’t your default gateway. You can only have 1 default route. Having two will cause lots of weird problems.
Check your routes first. A simple “route” command will show you the routes. Some people like “netstat -r”.
Edit /etc/network/interfaces and make sure you only see “gateway” once. If you have two, leave it on the NIC that takes you out to the internet.
Here is the NIC config we need to set up the static routes for:
iface eth1 inet static
To make something route over that interface since it doesn’t have a gateway and isn’t in that subnet, we can add:
#Static routes for VPL
up route add -net 10.103.128.56/29 gw 10.103.128.57 dev eth1
up route add -net 10.101.128.120/29 gw 10.103.128.57 dev eth1
The first IPs are the networks you need to hit. The second IP after “gw” is the gateway for that network, that will route you to the other networks. eth1 is the interface for which you are going out, pretty self explanatory.
NOTE: If you only need to hit a single host route and not a network route, change the line to this:
up route add -host 10.101.128.120 gw 10.103.128.57 dev eth1
Now, restart Networking or just reboot. Then a quick “route” or “route -n” (to keep it from trying to do a reverse DNS lookups on the IPs) command will show you your new static routes.