Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a Ubuntu box that has two networking interfaces (eth0 and wlan0). They are both configured for DHCP in /etc/network/interfaces, but they both assign a default gateway:

/etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto wlan0
iface wlan0 inet dhcp
wireless-essid test

Result of route -n

Kernel IP routing table
Destination Gateway      Genmask       Flags  Metric Ref Use  Iface
0.0.0.0     172.16.1.1   0.0.0.0        UG    100    0   0    wlan0
0.0.0.0     10.0.0.1     0.0.0.0        UG    100    0   0    eth0
10.0.0.0    0.0.0.0      255.255.255.0   U     0     0   0    eth0
172.16.1.0  0.0.0.0      255.255.255.0   U     0     0   0    wlan0

How can I set up /etc/network/interfaces to have only one default gateway, on the interface I want?

Worst case scenario, how can I at least control which one gets on top on the route -n command, each boot?

Note:

  • This box will travel a lot, and will be connected to different networks, so I don´t know in advance the IP addresses/ranges it will have.

  • Sometimes the default gw interface will be eth0. Sometimes it will be wlan0 ... So, this needs to be kind of automatic ...

share|improve this question
    
Welcome to Super User! Check our formatting tools – you can indent code by 4 spaces so you don't need to add <br> all over the place :) –  slhck Jun 16 '12 at 20:52

1 Answer 1

up vote 0 down vote accepted

Usually network related stuff is manged by "network-manager" and it comes with a fairly good glass bulb that knows how to do the right thing(TM).

If you insist on using /etc/network/interfaces and have a computer that travels a lot you should put an executable script into /etc/network/if-up.d. All scripts in this directory are executed everytime an interface goes up. In your new script you may implement logic that modifies your routing table as you want it.

I suggest you start reading the "IFACE OPTIONS" section in the interfaces man-page. Notice however, there is no such thing as "the way" of determining "the correct" settings for your routing table.

You can change the ordering of your default routes by assigning different metrics. The metric is a simple number and the kernel will prefer the default route with the lowest (I think) metric. So you should come up with some test that your script runs and based on the outcomes of that test your script assigns metric to default routes.

share|improve this answer
    
I want that way after not finding any other info about this issue ... Thanks :) –  user140600 Jun 17 '12 at 21:54

Your Answer

 
discard

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.