Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to configure my wireless network to use gateway when accessing IP addresses that start with 10.0.0.

I followed a few explanations on how to do it with the interfaces file but without success.

This is the content of my initial /etc/network/interfaces file:

auto lo
iface lo inet loopback

After several hours searching and reading I made it look like this:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth1

iface eth1 inet static

# static route
up route add -net gw dev eth1

Mentioned configuration works after I restart networking and until I restart Ubuntu. After I restart Ubuntu, I lose network manager and cannot connect to Internet or intended addresses 10.0.0.x.

What am I doing wrong, or is there a simpler way of setting a permanent route in newer versions of Ubuntu?

Just to mention I'm configuring wireless connection, because I do not use wired one.

UPDATE 1: (~$ ifconfig)

eth0      Link encap:Ethernet  HWaddr 00:24:81:64:9a:5c  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

eth1      Link encap:Ethernet  HWaddr 00:21:00:d8:25:45  
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::221:ff:fed8:2545/64 Scope:Link
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:  Mask:
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:284 errors:0 dropped:0 overruns:0 frame:0
          TX packets:284 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:21280 (21.2 KB)  TX bytes:21280 (21.2 KB)

UPDATE 2: (~$ route -n)

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   UG    0      0        0 eth1   U     0      0        0 eth1     U     1000   0        0 eth1         UG    100    0        0 eth1

UPDATE 3: I realised that there is a problem with this code:

iface eth1 inet static

If I comment it out I get network manager and Internet access, but not my desired route.

share|improve this question
What you put in /etc/network/interfaces looks right to me. What do the commands ifconfig and route -n show when the network isn't working? – Gilles Nov 9 '10 at 21:30
In /var/log/daemon.log, do any lines concerning NetworkManager appear on a boot that leaves you with a non-working network? – Gilles Nov 9 '10 at 21:39
I don't see anything suspicious in daemon.log :( – Milan Nov 10 '10 at 11:21
ifconfig output is added in main post – Milan Nov 10 '10 at 11:24
When you comment out the stanza about eth1 in /etc/network/interfaces, NetworkManager takes over the interface. What could help is in fact the output from ifconfig and route -n when you boot with the /etc/network/interfaces in your original question and do not get any internet connection. Note that Network Manager and ifupdown (invoked when you “restart networking”) are two different components; ifupdown is the one that executes the instructions in /etc/network/interfaces, while Network Manager only reads it to prevent itself from taking over if you've set things up for ifupdown. – Gilles Nov 10 '10 at 18:23
up vote 3 down vote accepted

If you've configured the network through ifupdown (i.e. in /etc/network/interfaces), and it works when you start networking manually but not after a fresh boot, one possibility is that your setup is bringing up the network correctly, and then some other system component reconfigures the network. The obvious suspect is Network Manager. Make sure that in /etc/NetworkManager/nm-system-settings.conf, under [ifupdown], you have managed=false. (It's the default, at least under Ubuntu 10.04, but maybe that changed in 10.10 or you changed it in previous experiments with Network Manager.)

If you want to stick with Network Manager, you can tell it to add the extra route. As of Ubuntu 10.04 (other distributions might not set up Network Manager in the same way), Network Manager executes the ifupdown scripts in /etc/network/if-*.d/. The role of these scripts is similar to the up, down, pre-up and post-down directives in /etc/network/interfaces (which Network Manager does not execute). Comment out all mentions of eth1 from/etc/network/interfaces` so that Network Manager will manage this interface.

The scripts are documented in the interfaces(5) man page. They are executed in an environment containing information about the connection being started or stopped, in particular $IFACE is the interface name. So put the following script in /etc/network/if-up.d/zzzz-milan-wireless-route:

if [ "$IFACE" = "eth1" ]; then
  route add -net gw dev eth1

Make it executable: chmod 755 /etc/network/if-up.d/zzzz-milan-wireless-route. The next time Network Manager brings up the network, you should have your default route.

share|improve this answer
In conf file I have: [main] plugins=ifupdown,keyfile [ifupdown] managed=false – Milan Nov 10 '10 at 10:27
I didn't have to stick with network manager, but if I modify interfaces file I loose and NM and Internet access. Anyway your updated answer finally solved my problem. Thanks a lot. – Milan Nov 12 '10 at 9:25
In my case, I had to remove the IF selection to make it work. But thanks anyway, you save me hours. – Aryo Jul 25 '13 at 13:57

I usually put static route commands in /etc/rc.local:

ip route add via dev eth1

I use iproute2 package btw

share|improve this answer
How then my rc.local should look like? Now it looks like this: #!/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. exit 0 – Milan Nov 9 '10 at 11:16
@Milan just add before the exit 0 all the commands you need to execute. So you can add the ip route [...] or route add [...] command just before exit 0 – Mr Shunz Nov 9 '10 at 11:26
I did it and it does not work. If I type "sudo ip route add via dev eth1" in terminal it works, but is lost on every restart. – Milan Nov 9 '10 at 11:38
@Milan You should add sudo in rc.local, too. But you must configure it not to ask for a password (try man sudoers) – Mr Shunz Nov 9 '10 at 11:48
Why is this so complicated. In windows it was piece of cake. I did add "sudo ip route add via dev eth1" in rc.local. It does not ask for password, but it still does not work. – Milan Nov 9 '10 at 12:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.