2 WAN, in-interface=??

Hello everyone,
I want to load balancing 2 WAN but it’s very hard because a lot of tutorials found googling were old and they didn’t work. Now with this code I don’t know what do I have to put in prerouting “in-interface=” (see below). At the moment in ethef2-3-4 there aren’t PC attached, I want that wlan clients use the “2 WAN in load balancing” but also laptops connected in 2-3-4. How can I do? This is my situation:

ether1 (WAN1) → 192.168.1.100
ether2 → Nothing
ether3 → Nothing
ether4 → Nothing
ether5 (WAN2) → 192.168.0.100

/ip firewall mangle
add chain=input in-interface=ether1 action=mark-connection new-connection-mark=WAN1_conn
add chain=input in-interface=ether5 action=mark-connection new-connection-mark=WAN2_conn

add chain=output connection-mark=WAN1_conn action=mark-routing new-routing-mark=to_WAN1
add chain=output connection-mark=WAN2_conn action=mark-routing new-routing-mark=to_WAN2

add chain=prerouting dst-address=192.168.1.0/24 action=accept in-interface=bridge
add chain=prerouting dst-address=192.168.0.0/24 action=accept in-interface=bridge

add chain=prerouting dst-address-type=!local in-interface=bridge per-connection-classifier=both-addresses-and-ports:2/0 action=mark-connection new-connection-mark=WAN1_conn passthrough=yes
add chain=prerouting dst-address-type=!local in-interface=bridge per-connection-classifier=both-addresses-and-ports:2/1 action=mark-connection new-connection-mark=WAN2_conn passthrough=yes

add chain=prerouting connection-mark=WAN1_conn in-interface=bridge action=mark-routing new-routing-mark=to_WAN1
add chain=prerouting connection-mark=WAN2_conn in-interface=bridge action=mark-routing new-routing-mark=to_WAN2


/ip route
add dst-address=0.0.0.0/0 gateway=192.168.1.100 routing-mark=to_WAN1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.0.100 routing-mark=to_WAN2 check-gateway=ping

add dst-address=0.0.0.0/0 gateway=192.168.1.100 distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.0.100 distance=2 check-gateway=ping


/ip firewall nat
add chain=srcnat out-interface=ether1 action=masquerade
add chain=srcnat out-interface=ether5 action=masquerade

If you have your LAN interfaces bridged, then in-interface=bridge in your prerouting rules is ok. The only thing that does not look right is ether5 (WAN2) being slave to something (either bridge, of switch master port), it should be independent interface.

Thank you! Everything seems to work well :smiley: Great! There is just one line blue in route list.. What does it means?

Inactive route. The one with lower distance is better, so it wins. But when you mark routing for all outgoing connections, they use routes from given routing tables to_WANx. These two in main routing table will be used only by router itself.

Ok.. From my PC seems to work.. Unfortunately from my iphone/ipad they used just WAN1, do you know what can I try to change?

Is there anything different between how PC and iphone/ipad are connected? From what I’ve seen so far, it look like you have only one LAN with all interfaces bridged together, so no matter if you connect device to wired LAN or to wireless, it should work the same.

Thank you for your help.. Unfortunately not… They are connected to the same wifi… I don’t know..

I put “per-connection-classifier=both-addresses-and-ports” but I read googling that could be problems with banks or something like that.. What do you think? It is better to use “per-connection-classifier=both-addresses”?

You need to understand what those options do. In both cases, they take connections based on given criteria and split them in different groups (in your case two). And it’s predictable, same input means same result.

“both-addresses” only works with addresses, so connection from client A to server X will always use same WAN.

“both-addresses-and-ports” also includes port, which means that results will look random, because even though client A still has same address, so does server X and target port does not change either, source port does change for each connection. So it might as well happen that each connection to target server will use different WAN, which means completely different source address and some servers might not like it.

But it does not explain what happens with your iphone/ipad. If you had “both-addresses”, it could just mean that you did not test with enough remote servers. Because while it should be close to 50/50 split for many connections, with just few ones it could happen that all will fall to only one WAN. But the same is very unlikely with “both-addresses-and-ports”.

I retested now from my iphone 2-3 times and now it works.. I don’t know why, I just disabled/enabled the two interface.
I’ll remove “-ports” as you explained, servers might not like it.

Thank you Sob! Your help is much appreciated, I didn’t find the button to give you reputation :slight_smile:

Now seems to not work on all devices… Very streange.. At the moment my gateway’s name are ether1 and ether5 as you can see from my screenshot.. Maybe do I must rename my interface according to firewall mangle (WAN1 and WAN2)? or it doesn’t matter? “new-connection-mark=WAN1_conn”

No, that’s two completely different things. You first mark connections, then based on that mark routing and it causes router to use routes with same routing mark.