But is there a difference between a more specific dst-address and for example the default gateway?
What about dst-address 1.2.3.4/32 and 0.0.0.0/0
From article “If there is more than one candidate route with the same distance, selection of active route is arbitrary” - so I guess I need a lower distance for the 1.2.3.4 route, am I correct?
Routing (for any device that does routing) functions according to this priority:
Choose the most specific route
Choose the route with the lowest distance
Choose randomly among all equally valid routes
When you use routing marks in your route table, those routes will only be checked for packets that carry the same routing mark. If a packet is marked with “routing mark A” and there is no matching route in the routing table specific to “routing mark A”, the packet will fall back to the default routing table.
So, in your scenario, 1.2.3.4/32 will always be preferred over 0.0.0.0/0 because it is the most specific route (has the longest subnet mask).
If you’re trying to send traffic to 1.2.3.4 and have two routes for 1.2.3.0/24 – one with distance 1 and gateway 192.168.1.1, a second with distance 10 and gateway 10.1.1.1 – the traffic will match the route with the lowest distance (as both routes are equally specific) and travel via gateway 192.168.1.1.
If you’re sending traffic to 1.2.3.4 and have two routes for 1.2.3.0/24 both with distance 1, then traffic will “round robin” between the two gateways. With dynamic routing (OSPF), you’ll probably get close to a 50/50 traffic split, but it won’t be guaranteed to break down that way (hence, it will look somewhat arbitrary). I can’t speak with authority as to what happens in a static routing scenario that results in equal cost routes.
Thank you for information, did not find documentation that there is also a priority for the most specific rule. So I think this would be the sequence:
Select all applicable routes, from this:
choose routes with matching routing-mark (if existing), from this:
choose most specific routes, from this:
choose the one with lowest distance, if more than one:
arbitrary or round-robin behaviour (I want to prevent this behaviour)
I´m not sure about order of point 3&4.
Two routes:
a) 1.2.3.0/24 with distance 4
b) 1.2.0.0/16 with distance 2
Trying to reach 1.2.3.4
Will route (a) be selected because of the more specific route, so above order would be correct
or will route (b) selected because of the lower distance, so 3&4 must be swapped?