I want to add a route permanently.

I've tried route add -net @ip netmask mask gw "gw" but every time when I shut down, I have to re-enter the command.

How can I make this route permanently?


2 Answers 2


You set static routes in /etc/network/interfaces An example entry would be

auto eth0
allow-hotplug eth0
iface eth0 inet static
        ### Ubuntu Linux add persistent route command ###
        post-up route add -net netmask gw

This sets a static address and mask and finally adds a static route.

  • @CharlesGreen Edited answer...
    – Jan
    Nov 13, 2014 at 7:38

Just add that command to /etc/rc.local.

It's pretty simple, just run this command: sudo echo "route add -net @ip netmask mask gw \"gw\"" >> /etc/rc.local.

Any commands in /etc/rc.local are automatically run towards the end of the boot process, though when you install a fresh, Ubuntu-proper installation it shouldn't have anything in it.

  • 1
    This does not work for Ubuntu 14.04 first of all because on the default rc.local file the last line is exit 0 - appending to it does nothing. This is already a sign that this is more a general and not ubuntu specific answer that has been checked in practice. Next to that problem, adding the route into that file even if executed did not work for me. The route was not added on boot. The file is executable.
    – hakre
    Jun 13, 2016 at 8:43

Not the answer you're looking for? Browse other questions tagged .