Community discussions

MikroTik App
 
hasan020
just joined
Topic Author
Posts: 9
Joined: Fri Jan 17, 2025 8:00 pm

Merging 2 lines with PCC loadbalancing fails to pick the right gateway

Fri Jan 17, 2025 8:29 pm

Hello dear all.. the Mikrtotik lovers :-D

I've been using Mikrotik and RouterOS for quite some years now.
I've always load-balanced 2 lines (ISPs) up to 5 lines together using almost same configurations, same script, both in RouterOS v6 and v7.

Recently, I did setup a router with 2 (PPPoE), but the traffic keeps going to one line, ignoring the route-mark.
Here is basic configurations export:
/interface ethernet
set [ find default-name=ether1 ] name=out1
set [ find default-name=ether2 ] name=out2
set [ find default-name=ether5 ] name=wan1
set [ find default-name=ether6 ] name=wan2

/interface list
add name=LAN

/interface list member
add interface=out1 list=LAN
add interface=out2 list=LAN


/ip pool
add name=dhcp_pool0 ranges=172.16.0.2-172.16.0.254
/ip dhcp-server
add address-pool=dhcp_pool0 interface=out2 name=dhcp1

/routing table
add fib name=to-wan1
add fib name=to-wan2

/ip address
add address=172.16.0.1/24 interface=out2 network=172.16.0.0

/ip dhcp-server network
add address=172.16.0.0/24 dns-server=192.168.8.1 gateway=172.16.0.1

/ip dns
set cache-size=20480KiB max-concurrent-queries=200 \
    max-concurrent-tcp-sessions=50

/ip firewall address-list
add address=192.168.0.0/16 list=LOCAL-IP
add address=172.16.0.0/12 list=LOCAL-IP
add address=10.0.0.0/8 list=LOCAL-IP

/ip firewall mangle
add action=mark-connection chain=input in-interface=wan1 new-connection-mark=\
    cm-wan1 passthrough=yes
add action=mark-connection chain=input in-interface=wan2 new-connection-mark=\
    cm-wan2 passthrough=yes

add action=mark-connection chain=prerouting dst-address-type=!local \
    in-interface-list=LAN new-connection-mark=cm-wan1 passthrough=yes \
    per-connection-classifier=both-addresses-and-ports:2/0
add action=mark-connection chain=prerouting dst-address-type=!local \
    in-interface-list=LAN new-connection-mark=cm-wan2 passthrough=yes \
    per-connection-classifier=both-addresses-and-ports:2/1

add action=mark-routing chain=prerouting connection-mark=cm-wan1 \
    in-interface-list=LAN new-routing-mark=to-wan1 packet-mark="" \
    passthrough=yes
add action=mark-routing chain=prerouting connection-mark=cm-wan2 \
    in-interface-list=LAN new-routing-mark=to-wan2 passthrough=yes

add action=mark-routing chain=output connection-mark=cm-wan1 \
    new-routing-mark=to-wan1 passthrough=yes
add action=mark-routing chain=output connection-mark=cm-wan2 \
    new-routing-mark=to-wan2 passthrough=yes

/ip firewall nat
add action=masquerade chain=srcnat out-interface=pppoe-out1
add action=masquerade chain=srcnat out-interface=pppoe-out2

/ip route
add check-gateway=ping distance=1 gateway=pppoe-out1 routing-table=to-wan1
add check-gateway=ping distance=1 gateway=pppoe-out2 routing-table=to-wan2

Help is more than appreciated..!!
Last edited by hasan020 on Sat Jan 18, 2025 1:56 am, edited 1 time in total.
 
User avatar
sindy
Forum Guru
Forum Guru
Posts: 11490
Joined: Mon Dec 04, 2017 9:19 pm

Re: Merging 2 lines with PCC loadbalancing fails to pick the right gateway  [SOLVED]

Fri Jan 17, 2025 10:09 pm

You have only posted the part of the configuration you assume to be related. However, in most cases, the issue you cannot find is typically caused by some part of the configuration you don't expect to be related but it actually is.

But even in this restricted configuration, I can see two mistakes:
  • on the two /ip route rows you did post, the gateway set to interface name (which is perfectly OK since the interfaces are L3 ones) and check-gateway is set to ping, which would be allright too if the gateway was set to an IP address but it is wrong in this case where the gateway is an interface. Since RouterOS developers did not anticipate such a misconfiguration, the check-gateway result is "fail" and the routes are not eligible. As a consequence, the traffic falls back to routing table main, in which one of the routes probably has a higher priority (lower value of distance) so it gets all the traffic.
  • you assign the connection-mark valuses based on in-interface, but from the point of view of the firewall, the WAN interfaces are pppoe-out1 and pppoe-out2, not the Ethernet ports they are attached to.
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 23358
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Merging 2 lines with PCC loadbalancing fails to pick the right gateway

Fri Jan 17, 2025 11:12 pm

I wondered how its been used for many years with such a misconfiguration............
Which leads one to conclude we dont have a complete picture as well.

/export file=anynameyouwish ( minus router serial number, any public WANIP information, keys etc. )
 
hasan020
just joined
Topic Author
Posts: 9
Joined: Fri Jan 17, 2025 8:00 pm

Re: Merging 2 lines with PCC loadbalancing fails to pick the right gateway

Sat Jan 18, 2025 1:48 am

You have only posted the part of the configuration you assume to be related. However, in most cases, the issue you cannot find is typically caused by some part of the configuration you don't expect to be related but it actually is.

Well, indeed.. that was all about it. I removed very other basic stuff like, router identity... etc!

But even in this restricted configuration, I can see two mistakes:
  • on the two /ip route rows you did post, the gateway set to interface name (which is perfectly OK since the interfaces are L3 ones) and check-gateway is set to ping, which would be allright too if the gateway was set to an IP address but it is wrong in this case where the gateway is an interface. Since RouterOS developers did not anticipate such a misconfiguration, the check-gateway result is "fail" and the routes are not eligible. As a consequence, the traffic falls back to routing table main, in which one of the routes probably has a higher priority (lower value of distance) so it gets all the traffic.
  • you assign the connection-mark valuses based on in-interface, but from the point of view of the firewall, the WAN interfaces are pppoe-out1 and pppoe-out2, not the Ethernet ports they are attached to.


Thanks a ton! really thank you!
Point one, that was really the mistake.. I little-bit altered the configuration from balancing 2 lines coming from regular IP routers, to PPPoE lines.
Hence this piece of glitch was not dropped. Well, mistakes happen :-D
Once I removed the check part, all went as expected.
By the way.. what's the right way to check in case of PPPoE or Interface gateway?!

Regarding the other point, it was a typo I made during post touch-up for easier readability.. but it was set right in the router.

I repeat my gratitude.. :-)
Last edited by hasan020 on Sat Jan 18, 2025 1:57 am, edited 1 time in total.
 
hasan020
just joined
Topic Author
Posts: 9
Joined: Fri Jan 17, 2025 8:00 pm

Re: Merging 2 lines with PCC loadbalancing fails to pick the right gateway

Sat Jan 18, 2025 1:51 am

I wondered how its been used for many years with such a misconfiguration............
Which leads one to conclude we dont have a complete picture as well.

/export file=anynameyouwish ( minus router serial number, any public WANIP information, keys etc. )


Yes, it's the complete picture, sindy figured it out for me.
Thanks for wondering any way :-D
 
User avatar
sindy
Forum Guru
Forum Guru
Posts: 11490
Joined: Mon Dec 04, 2017 9:19 pm

Re: Merging 2 lines with PCC loadbalancing fails to pick the right gateway

Sat Jan 18, 2025 11:20 am

what's the right way to check in case of PPPoE or Interface gateway?!
It depends on the particular situation.

Like all the other PPP-based tunneling protocols, PPPoE is a stateful tunnel that uses keepalive messages to verify availability of the remote endpoint if no payload traffic is present, so if the connection to your ISP fails for whatever reason (disconnected Ethernet cable at your end, DSL/optical line broken due to ground works in the street, power outage at the ISP, ...), the pppoe-client interface becomes inactive so any routes that use it become ineligible too. So if all your uplink connections are provided by the same RAS at the same ISP, there is no point in checking anything else, because the path from your router to the RAS is monitored by PPPoE itself and the path from that RAS to internet is common for both your uplinks.

If your uplinks are provided by different ISPs operating their own hardware (in many countries, ISPs that are competitors on sales level actually share the infrastructure), or if you've got e.g. an LTE or satellite backup connection for critical traffic, it makes sense to verify the transparency of the path from the ISP to the internet, where "internet" is represented by some addresses that are known to be highly available, often called "canary" addresses (canaries are very sensitive to carbon monoxide so miners used them as biologic gas detectors before electronic ones got invented). You can use netwatch and scripts or the "recursive next hop search" approach to monitor those canary addresses and disable the default routes via affected uplinks. There are tons of topics about both these approaches here on the forum.
 
hasan020
just joined
Topic Author
Posts: 9
Joined: Fri Jan 17, 2025 8:00 pm

Re: Merging 2 lines with PCC loadbalancing fails to pick the right gateway

Sat Jan 18, 2025 2:00 pm

what's the right way to check in case of PPPoE or Interface gateway?!
canaries are very sensitive to carbon monoxide so miners used them as biologic gas detectors before electronic ones got invented
Lovely one.. about the canaries.. :-D

Thanks a lot sandy, precious information..