Multiple default gateways on the same interface

10,540

Solution 1

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.

Solution 2

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.

Share:
10,540

Related videos on Youtube

Falmarri
Author by

Falmarri

Updated on September 17, 2022

Comments

  • Falmarri
    Falmarri over 1 year

    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.

    • Zoredache
      Zoredache over 13 years
      Can you tell us more about why you think you need multiple default gateways?
    • Falmarri
      Falmarri over 13 years
      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
    Falmarri over 13 years
    Then what does it mean to have more than 1, ie from the grab from my laptop
  • Zoredache
    Zoredache over 13 years
    @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.
  • Falmarri
    Falmarri over 13 years
    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.
  • Aaron Copley
    Aaron Copley over 13 years
    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!
  • Aaron Copley
    Aaron Copley over 13 years
    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.
  • Philip
    Philip over 13 years
    @Falmarri, it means something's screwed up.
  • Falmarri
    Falmarri over 13 years
    Yeah there SHOULD never be more than 1 default gateway. But I just grabbed my laptop to see what it displayed and got worried.