4

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?

0

2 Answers 2

8

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

auto eth0
allow-hotplug eth0
iface eth0 inet static
        address 10.70.201.5
        netmask 255.255.255.192
        ### Ubuntu Linux add persistent route command ###
        post-up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.70.201.6

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

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

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
  • 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 or ask your own question.