Static Routing · Topic 1 of 4
More Specific Routes and ECMP
Learn how RouterOS picks the most specific route first, how distance breaks ties, and how ECMP shares traffic across several equal gateways.
- 4 min
- The longest matching prefix wins, regardless of distance.
- Distance only decides between routes with the same destination prefix.
- Static routes have distance 1, OSPF 110, RIP 120, eBGP 20 and iBGP 200.
What it is
Route selection decides which gateway a packet uses, and ECMP lets several gateways share the load.
A router compares each destination address against every active route. The route with the longest matching prefix wins. This is why a /24 route beats a /16 route, and a /16 route beats the default route.
ECMP stands for equal cost multi path. It lets one route point at more than one gateway, so traffic is spread over several links at once.
How it works
RouterOS first matches the prefix, then compares distance, and then applies ECMP if a route lists several gateways.
Longest prefix match
Every packet is checked against the destination of each active route. Among the routes that match, the one with the largest prefix length is chosen. Distance is not compared at this stage.
/ip route add dst-address=0.0.0.0/0 gateway=203.0.113.1
/ip route add dst-address=10.1.0.0/16 gateway=10.0.0.2
/ip route add dst-address=10.1.1.0/24 gateway=10.0.0.6
A packet for 10.1.1.5 uses the /24 route through 10.0.0.6. A packet for 10.1.2.5 uses the /16 route through 10.0.0.2. Everything else uses the default route.
The default route 0.0.0.0/0 is simply the least specific route possible. Connected routes are created automatically for each address on an interface, and they are usually the most specific match for local hosts.
Distance only breaks ties
Distance matters when two routes have the same destination prefix. The route with the lower distance is used, and the other waits as a backup.
| Route source | Default distance |
|---|---|
| Connected | 0 |
| Static | 1 |
| eBGP | 20 |
| OSPF | 110 |
| RIP | 120 |
| iBGP | 200 |
A route with a long prefix and a high distance still beats a route with a short prefix and a low distance. The prefix comparison always comes first.
ECMP
An ECMP route lists several gateways in one route entry, separated by commas.
/ip route add dst-address=0.0.0.0/0 gateway=203.0.113.1,198.51.100.1
Both gateways are used at the same time. Traffic is shared per connection, not per packet, so one single download still uses only one link. Many connections together fill both links.
If one gateway fails, traffic should move to the others. That only happens when the router can tell the gateway is down, which is the job of the gateway check covered in a later page.
Verifying
/ip route print
/ip route print detail where dst-address=0.0.0.0/0
The print shows the active flag A and the static flag S for each route. An ECMP route shows its gateways in a list, and the status of each one is shown in the detail view.
When two routes seem to compete, compare the prefix length first. Only equal prefixes are decided by distance.
What to remember for the exam
Six facts cover most questions on this topic.
- The longest matching prefix wins, regardless of distance.
- Distance only decides between routes with the same destination prefix.
- Static routes have distance 1, OSPF 110, RIP 120, eBGP 20 and iBGP 200.
- Connected routes have distance 0 and are made automatically from addresses.
- ECMP uses several gateways in one route, written as a comma separated list.
- ECMP shares traffic per connection, not per packet.
ECMP does not make one connection faster. A single connection stays on one link.
Common mistakes
These four errors appear often.
Expecting distance to beat prefix length. A static default route with distance 1 never wins against a more specific OSPF route with distance 110.
Expecting one transfer to use both links. ECMP balances connections. A single TCP stream still travels over one gateway.
Assuming ECMP detects dead links by itself. Without a gateway check, the router may keep sending connections to a gateway that no longer answers.
Forgetting that a longer prefix can pull traffic away. A more specific route from a dynamic protocol can take traffic that you expected to follow your default route, so check which routes are active.
Check yourself
Work through these three questions.
A router has a default route and a /16 route that both match a packet. Which one is used?
The /16 route is used because the longest matching prefix wins. Distance is not compared when the prefixes differ.
When does the distance value decide between two routes?
It decides only when both routes have the same destination prefix. The route with the lower distance is used.
How do you configure ECMP for a default route over two gateways, and how is the traffic shared?
List both gateways in one route, for example
gateway=203.0.113.1,198.51.100.1. Traffic is shared per connection, not per packet.
Topic 1 of 4 in Static Routing
Test yourself on Static Routing
The full MikroTik MTCRE question bank has 417 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by MikroTik. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.