I ran across two entries in a linux routing table that both have the same destination, but have different gateways. How would this traffic be routed? I've been searching around online for additional information, as it seems like this type of setup would be common, although I am having a difficult time tracking down any information on this (might be wording it incorrectly). I am assuming that the route with a gateway of would automatically be used, or would traffic be load balanced over the two routes instead?   UG        0 0          0 eth1   U         0 0          0 eth1

Thank you

  • 1
    linux uses "longest prefix match", which means the most specific route is chosen. In your case the GW is more specific than the default GW (, so it would always be used. See additional info here on discussion of if you applied priority/metrics to the gateways: serverfault.com/questions/648276/… – jlehtinen Mar 18 '15 at 14:52
  • @jlehtinen sounds good, thanks. With the longest prefix, wouldn't that just applying to the destination? (since the listed mask is for that) – lacrosse1991 Mar 18 '15 at 15:04
  • In your example, traffic for would be routed through Other traffic would be routed according to whatever other routes are defined. – jlehtinen Mar 18 '15 at 15:13

To find out how it works try:

ip route get ADDRESS [ from ADDRESS iif STRING ]
                     [ oif STRING ] [ tos TOS ]
                     [ mark NUMBER ]

it will tell you where/how packet with such parameters gets routed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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