Community discussions

MikroTik App
 
SwaggerRO
just joined
Topic Author
Posts: 19
Joined: Wed Jul 08, 2020 11:16 pm

MikroTik BGP ECMP Behavior and Preferential Routing  [SOLVED]

Sat Apr 26, 2025 12:02 am

I'm running a MikroTik router (CCR1009) on RouterOS 7.18.2 and I'm trying to achieve a clean and reliable dual-uplink BGP setup with two providers:

ISP1 (Primary)

ISP2 (Backup)

I am receiving full Internet routing tables from both ISPs, plus a default route (0.0.0.0/0) from each.
I have BGP filters that set bgp-local-pref=200 for ISP1 and bgp-local-pref=100 for ISP2, aiming for ISP1 to always be the primary path.

However, RouterOS installs multiple BGP routes (ECMP) into the routing table even when local preference is different.
As a result, both ISP1 and ISP2 routes for the same prefixes are installed in FIB as ECMP paths, and traffic is randomly load-balanced between the two.

What I want:

Use ISP1 as the primary uplink for all traffic.

Use ISP2 only as backup (if ISP1 fails).

Prevent ECMP between ISP1 and ISP2 for identical prefixes.

Accept the default route from ISP1 only.

Keep full routing information for diagnostics and optional exports (like BGP-tools), if needed.

What I tried:

Set bgp-local-pref=200 for ISP1, bgp-local-pref=100 for ISP2.

Attempted to change distance, but RouterOS doesn't allow per-route distance modification for BGP.

Tried setting bgp-med, but it is read-only on input.

Found that RouterOS 7 automatically installs multiple "best" paths when attributes match, resulting in ECMP.

Tried select-only=yes on BGP template, but this command is not available in RouterOS 7.18.2.

Config (sanitized):

bashCopyEdit/routing bgp template
set default as=myasn disabled=no output.network=bgp-networks routing-table=main
add as=myasn disabled=no name=custom-template

/routing bgp connection
add name=ISP1-BGP remote.address=XXX.XXX.XXX.1 .as=XXXXX local.address=XXX.XXX.XXX.2 \
.role=ebgp input.filter=ISP1-IN output.filter=EXPORT-BGP routing-table=main
add name=ISP2-BGP remote.address=YYY.YYY.YYY.1 .as=YYYYY local.address=YYY.YYY.YYY.2 \
.role=ebgp input.filter=ISP2-IN output.filter=EXPORT-BGP routing-table=main

/routing filter rule
add chain=ISP1-IN rule="set bgp-local-pref=200; accept"
add chain=ISP2-IN rule="set bgp-local-pref=100; accept"

/ip route print where dst-address=\"0.0.0.0/0\"
Problem:

Even though I have configured different local preferences, I still get ECMP for most prefixes received from both ISPs.
Traffic randomly uses ISP1 or ISP2, instead of always preferring ISP1 unless ISP1 fails.

I know RouterOS 7 doesn't support changing distance for BGP routes and select-only is not an option at this RouterOS version.

Currently, I don't find a clean way to disable ECMP without manually rejecting duplicate prefixes or very complex policy routing.

Question:

How can I reliably prioritize all outbound traffic over ISP1?

How can I ensure default route is accepted from ISP1 only?

How can I cleanly avoid ECMP when receiving identical prefixes from two BGP peers?

Any help, workaround or example from MikroTik admins or advanced users would be really appreciated.
 
markonen
newbie
Posts: 36
Joined: Tue Aug 11, 2020 4:28 pm

Re: MikroTik BGP ECMP Behavior and Preferential Routing

Sat Apr 26, 2025 4:34 pm

This sounds like your BGP sessions are on different BGP instances. That would make every path received the best path (in that instance), and thus installed in the routing table.

Your config snippet is too sanitized to show this, though. Do you have the same router id on both?
 
User avatar
chechito
Forum Guru
Forum Guru
Posts: 3294
Joined: Sun Aug 24, 2014 3:14 am
Location: Bogota Colombia
Contact:

Re: MikroTik BGP ECMP Behavior and Preferential Routing

Sat Apr 26, 2025 6:42 pm


Attempted to change distance, but RouterOS doesn't allow per-route distance modification for BGP.
try some filter like this
{ set distance 19; accept; }
 
SwaggerRO
just joined
Topic Author
Posts: 19
Joined: Wed Jul 08, 2020 11:16 pm

Re: MikroTik BGP ECMP Behavior and Preferential Routing

Sun Apr 27, 2025 12:13 pm

This sounds like your BGP sessions are on different BGP instances. That would make every path received the best path (in that instance), and thus installed in the routing table.

Your config snippet is too sanitized to show this, though. Do you have the same router id on both?
Hi,

Thank you so much for pointing that out!
Honestly, I hadn't even thought about the Router-ID and instance separation causing ECMP, but your explanation made complete sense.

I checked my setup and indeed, my BGP sessions were under different instances with different Router-IDs.
After I unified all BGP sessions under a single instance and made sure they all have the same Router-ID, everything started working exactly as expected.

Now, traffic properly prefers ISP1 (primary) and only falls back to ISP2 when needed, with no random load-balancing across both providers.

I really appreciate your help — you saved me a lot of headache!

Thanks again!
 
SwaggerRO
just joined
Topic Author
Posts: 19
Joined: Wed Jul 08, 2020 11:16 pm

Re: MikroTik BGP ECMP Behavior and Preferential Routing

Sun Apr 27, 2025 12:15 pm


Attempted to change distance, but RouterOS doesn't allow per-route distance modification for BGP.
try some filter like this
{ set distance 19; accept; }
Thanks a lot for your suggestion as well!
I didn't had to use this since after modifying the Router ID, re-establishing the BGP connections with all the peers, traffic started to go through ISP1 for almost 95% of the traffic, and only about ~5% of the traffic goes out through ISP2. This started to work as expected.

Appreciate all the hints received, and thank you again!