Each time when I start my computer I type in the console

sudo route add -net xxx.xxx.xxx.xxx netmask gw xxx.xxx.xx.xxx

When computer is rebooted or switched Off/On I must re-enter this in the terminal.

Is there an option whit which I can add this route permanently? I'm using Ubuntu

2 Answers 2


Add the route entry to your /etc/rc.local file (before exit 0):

/sbin/route add -net xxx.xxx.xxx.xxx netmask gw xxx.xxx.xx.xxx

or add it to your crontab:

@reboot /sbin/route add -net xxx.xxx.xxx.xxx netmask gw xxx.xxx.xx.xxx

Use the absolute path to route executable, on my system /sbin/route, change if needed.

As a side note, start using the ip command (ip route ....) for these trivial tasks now as the utilities of net-tools package are deprecated now.

  • Thank's a lot. It's working perfectly. With IP how will look this? Just IP instead ot route... ?
    – S.I.
    Jun 29, 2016 at 4:42
  • ip is a new command (in /sbin usually) which has all of the previously separate ip related commands (e.g. route) as subcommands. So this would be "ip route ..." to replace the direct call to route. In practical terms, add three characters "ip<space>" after the second slash.
    – MAP
    Jun 29, 2016 at 5:08

To expand on heemayl's answer regarding the use of theip suite.

The correct command to put into /etc/rc.local is

/sbin/ip route add xxx.xxx.xxx.xxx/20 via yyy.yyy.yyy.yyy

where xxx.xxx.xxx.xxx/20 represents the network address and the netmask (24010=111100002), so 20 bit are set, that number is now called prefix, and yyy.yyy.yyy.yyy represents the gateway.

Your /etc/rc.local should look this way:

#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.

/sbin/ip route add xxx.xxx.xxx.xxx/20 via yyy.yyy.yyy.yyy
exit 0

It is important to leave exit 0 in place as the last line.

You must log in to answer this question.

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