Creating persistent static routes in Ubuntu Server 8.10

Published on Tuesday, 31 March 2009.

Create a file in /etc/network/if-up.d called static-routes. Add the following lines:

#!/bin/sh
/sbin/route add -net 172.16.0.0 gw X.X.X.X netmask 255.240.0.0 dev eth0

Of course, you would have to change the X.X.X.X to your gateway address as well as change the network (in my case 172.16.0.0) and subnet mask (in my case 255.240.0.0) for your respective environment. Now, make the file executable like so:

sudo chmod 755 /etc/network/if-up.d/static-routes

Now, restart networking:

/etc/init.d/networking restart

Good to go!