MTCRE Lab 1.2: Route Selection & Longest-Prefix Match

MTCRE Lab 1.2: Route Selection & Longest-Prefix Match

Objective

Understand how MikroTik RouterOS selects routes using the longest-prefix match rule and observe how it chooses between overlapping routes.

You will:

  • Configure multiple static routes for the same destination with different prefix lengths.
  • Analyze how RouterOS selects the most specific route.
  • Verify path selection using ping and traceroute.

We are going to use the lab 1.1 file that we created earlier as the base for this lab. If you have not gone through lab 1.1 we suggest doing so, or you can download the file below and import it into your EVE-NG instance.

  • The longest-prefix match rule means RouterOS always picks the route with the most specific subnet mask (the smallest network).
  • Example: /26 is preferred over /25, which is preferred over /24.
  • This rule applies to both static and dynamic routes.

Step-by-Step Lab Procedure

Step 1 – Clear Old Routes
On R1, remove existing static routes to 192.168.3.0/24:

/ip route remove [find dst-address=192.168.3.0/24]

Step 2 – Add Multiple Routes to the Same Destination
We’ll create overlapping routes that differ only by prefix length.

/ip route add dst-address=192.168.3.0/24 gateway=10.1.12.2 comment="General route"
/ip route add dst-address=192.168.3.0/25 gateway=10.1.12.2 comment="More specific route"
/ip route add dst-address=192.168.3.0/26 gateway=10.1.12.2 comment="Most specific route"

Step 3 – View Routing Table
Display all routes to confirm how MikroTik handles overlapping destinations:

/ip route print detail where dst-address~"192.168.3"

Expected Result:
The route with /26 will be active and used for any destination that falls within 192.168.3.0–63.

Step 4 – Test Longest-Prefix Behavior

  1. From PC1, ping a few targets in PC2’s LAN:
ping 192.168.3.10
  1. On R1 use,
/tool traceroute 192.168.3.10

Disable the /26 route and re-run traceroute:

/ip route disable [find dst-address=192.168.3.0/26]
/tool traceroute 192.168.3.10

Expected Result:
You’ll now see the router automatically use the /25 route.
Disable the /25 next → RouterOS falls back to /24.


Step 5 – Verify Route Priority
Inspect active routes again:

/ip route print detail where dst-address~"192.168.3"

Expected Result:
Only one route (the most specific) will be marked A (active) at any time.

Step 6: Verification Tasks

Test Command Expected Result
Show all routes /ip route print Three routes listed, only one active
Ping PC2 from PC1 ping 192.168.3.10 Success via most specific route
Traceroute to PC2 /tool traceroute 192.168.3.10 Uses /26, then /25 when /26 disabled
Disable most specific route /ip route disable [find dst-address=192.168.3.0/26] Router falls back to next prefix


Summary

In this lab, you verified that MikroTik RouterOS selects the most specific route when multiple matches exist.
By disabling higher-priority routes, you observed the router’s fallback mechanism.

Understanding longest-prefix match is critical for designing stable and predictable routing policies — especially before adding ECMP, recursive routes, and PBR in later lessons.

Review Questions

1. What is the longest-prefix rule and why does RouterOS use it?
The longest-prefix rule means that when multiple routes match a destination IP, RouterOS chooses the route with the most specific (longest) subnet mask.
For example, /26 (255.255.255.192) is more specific than /25 or /24.

Why RouterOS uses it:
Because it ensures packets take the most precise, efficient path to their destination.
This rule aligns with standard IP routing behavior defined in RFC 1812 — it avoids ambiguity and directs traffic to the closest match in the routing table.


2. If you have /24, /25, and /26 routes, which is chosen first?
RouterOS will choose the /26 route first, because it has the longest prefix length and therefore the most specific match.

Priority order:
/26/25/24

If the /26 route covers the destination IP, it will always be selected before broader prefixes.


3. What happens when the most specific route becomes inactive?
If the most specific route (for example, /26) becomes inactive or unreachable, RouterOS automatically falls back to the next available, less-specific route (such as /25 or /24).
This ensures continuous connectivity using a broader path when the preferred one fails.


4. How can you verify which route is active in MikroTik?

You can view active and inactive routes using:

/ip route print detail