1

Is it valid to have multiple default gateways associated with the same interface. I thought that didn't make sense, but I'm seeing this on my laptop

$ route
Kernel IP routing table                                                                                                              
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.1.0.0        *               255.255.248.0   U     1      0        0 eth0
default         10.1.1.1        0.0.0.0         UG    0      0        0 eth0
default         10.1.1.1        0.0.0.0         UG    202    0        0 eth0

The reason I ask is that in an embedded system we're developing for, we need to get the default gateway associated with a particular interface. Is this just a display issue where it's showing the same default gateway twice? Or does having multiple default gateways on 1 interface mean something that I should have to take into account.

2
  • Can you tell us more about why you think you need multiple default gateways?
    – Zoredache
    Commented Oct 18, 2010 at 19:39
  • 1
    I don't think I do. I'm wondering if it's valid because I need to RETURN the default gateway. And I need to know what I should be returning.
    – Falmarri
    Commented Oct 18, 2010 at 19:42

4 Answers 4

4

It's not really valid to have multiple default gateways on the same machine let alone on a single interface. Sure there's some tiny edge cases where it might help but I've never come across any that jump to mind. You generally have a default then statics to anything outside that.

3
  • Then what does it mean to have more than 1, ie from the grab from my laptop
    – Falmarri
    Commented Oct 18, 2010 at 19:34
  • @Falmarri, If you have a second default gateway, it means you have route that was added that is not doing anything useful. This occasionally happens with multiple interfaces set to automatically configure themselves, or perhaps you configured something weird. In any case the default gateway with the lowest metric will be used, the other will be ignored.
    – Zoredache
    Commented Oct 18, 2010 at 19:46
  • @Falmarri, it means something's screwed up.
    – Chris S
    Commented Oct 18, 2010 at 20:16
1

When you look carefully, you see different values in the "metric" column. Everything else is equal so I suspect some mis(-auto-)configuration.

With a "real" routing protocol you can have different routes with the same destination (although one wouldn't speak of multiple "default" gateways) which would be selected according their routing "cost" e.g. the higher the "metric" on the route, the lower the chance of the route actually being used. When there's network contention, the metrics will be dynamically adapted to reflect this, so that in this case it would be possible that another route to the same destination could be selected.

0

The default route, even as shown above in 2 lines, is still the same node. (10.1.1.1) The only difference between the two is the Metric column. This is typically counted in hops. Has anything changed in your network topology that would impact this field? It's likely only displaying twice because of this. Reboot or restart the network services and this should clear.

What distribution are you using? In Red Hat, you can check the default gateway in /etc/sysconfig/network. By using the route command you will be subject to any unexepected output like you see here. Stick to getting the default route from the OS documented configuration, not another binary.

4
  • It's arch, but I'm not having problems or anything. All I'm trying to figure out is how to return the default gateway to the user. And if it's POSSIBLE to have more than 1 in the route table, regardless if it's erroneous or not, I need to know what to return to the user.
    – Falmarri
    Commented Oct 18, 2010 at 19:54
  • You replied as I was editing and adding my second paragraph. Look into extracting the gateway from configuration instead of relying on the output of route. You should get more consistent results this way. Good luck! Commented Oct 18, 2010 at 19:56
  • I don't really agree with you here. While getting the actual configured value is useful, getting the route table that is actually being used is also important. It is possible that down the road some user will do something non-standard and manually configure a route in a script or something somewhere. A good interface should be able to tell you both how the route table should look, and the current state of the route table.
    – Zoredache
    Commented Oct 18, 2010 at 20:05
  • True enough, the value from the file will be the start up value -- not necessarily the configured value. However, if a change is made and it isn't written to file, it is non-persistent and thus is questionable, IMO. I guess then that the more appropriate source would depend on the intended use of the application. Commented Oct 18, 2010 at 20:08
0

It really doesn't make sense to have more then one default gateway in a single route table. Usually on Linux only the destination address of the packet is used to select which route will be used. Routes will be check from the most specific to the least specific to determine if that route applies to the destination. If no specific route is found the default route with the lowest metric will be used.

If you want or need to select the route based on other criteria like the source address you will need to use the advanced routing features. This will mean creating multiple route tables and using ip rule to select the proper table based on whatever criteria you like.


It sounds like you are trying to get the route to display in some kind of GUI you are developing? Hopeful in your embedded setup you don't have a situation where multiple default gateways get set. In any case you probably should not be managing the default gateway per-interface. The default and most routes should be managed separately from the IP configuration for a specific interface. Routes really are system wide, not per-interface.

1
  • Yeah there SHOULD never be more than 1 default gateway. But I just grabbed my laptop to see what it displayed and got worried.
    – Falmarri
    Commented Oct 18, 2010 at 20:35

You must log in to answer this question.

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