I have a pretty simple standard routing table on my linux box:

default via dev eth0  proto static dev eth0  proto kernel  scope link  src  metric 1

Now I need to route a specific subnet to another gateway. No problem yet, just add via dev eth0

However, there's a subset of that which should NOT go there. This works: via dev eth0

But I'd rather not have to repeat the default gateway in there; I'd like to be able to just say, "for, do what you'd do if there was no route defined"

Any way of doing this? (Other than replacing the with a bunch of more specific routes to carefully avoid the 10.0.2/24 one)

  • and what is default gw on the host? – ALex_hha Jul 24 '13 at 7:40
  • As you can see in the first line of the routing table, – Jochen Jul 24 '13 at 17:59

Routing is matched as a most specific wins.

This: via dev eth0

Is more specific than this: via dev eth0

/24 vs /8

So just add both routes, the traffic for will match that route, anything else will match the less-specific /8 route.

Remember that your default route is which is the least-specific CIDR that exists, which is why all other routes match before your default route. ( is part of remember)

| improve this answer | |
  • I know that adding both works, but it means I must repeat the default gateway in the /24 route; I'd looking for a way to avoid that duplication. – Jochen Jul 24 '13 at 17:59
  • Oh I understand now; sorry, I don't know a way around that. You could do multiple routing tables and something with the 'throw' route but that's making it wayyyy more complex than just adding the same gateway twice. – fukawi2 Jul 25 '13 at 23:33

Why not add the route to on That way new hosts on your network don't need to know about that static route and you can leave as the default route and have it responsible for finding one-off networks like and more generally

| improve this answer | |
  • Nice idea. Unfortunately that won't work in this case since doesn't know how to route to the alternate (I oversimplified the example; the 10/8 actually goes to a different network, not just a different host on 192.168.1/24. And it would still mean having to specify the default gatway twice on the machine you put those routes on – Jochen Jul 24 '13 at 18:07

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.