Multi Routes and Winbox

Hello All
I have 4 WANs and using NTH method

WAN1 IP: 41.39.x.x
WAN2 IP: 197.51.x.x
WAN3 IP: 197.51.x.x
WAN4 IP: 41.39.x.x

The problem is I cant connect to rouberbourd via winbox from WAN2 & WAN3 & WAN4
Only WAN1 works
If I disable WAN1 Route, I can connect to WAN2
And if I disable WAN1 & WAN2 Route, I can connect to WAN3
and if disable WAN1 & WAN2 & WAN3 Route, I cant connect to WAN4
I need to able to connect to any WAN IP via winbox not must disable Routes to another work.

/ip address
add address=192.168.1.2/24 interface=WAN1 network=192.168.1.0
add address=192.168.2.2/24 interface=WAN2 network=192.168.2.0
add address=192.168.3.2/24 interface=WAN3 network=192.168.3.0
add address=192.168.4.2/24 interface=WAN4 network=192.168.4.0
add address=10.0.0.1/16 interface=LAN network=10.0.0.0

/ip firewall mangle
add action=mark-connection chain=prerouting connection-state=new \
new-connection-mark=line1 nth=4,1 passthrough=yes src-address=10.0.0.0/16
add action=mark-connection chain=prerouting connection-state=new \
new-connection-mark=line2 nth=4,2 passthrough=yes src-address=10.0.0.0/16
add action=mark-connection chain=prerouting connection-state=new \
new-connection-mark=line3 nth=4,3 passthrough=yes src-address=10.0.0.0/16
add action=mark-connection chain=prerouting connection-state=new \
new-connection-mark=line4 nth=4,4 passthrough=yes src-address=10.0.0.0/16
add action=mark-routing chain=prerouting connection-mark=line1 \
new-routing-mark=line1 passthrough=yes src-address=10.0.0.0/16
add action=mark-routing chain=prerouting connection-mark=line2 \
new-routing-mark=line2 passthrough=yes src-address=10.0.0.0/16
add action=mark-routing chain=prerouting connection-mark=line3 \
new-routing-mark=line3 passthrough=yes src-address=10.0.0.0/16
add action=mark-routing chain=prerouting connection-mark=line4 \
new-routing-mark=line4 passthrough=yes src-address=10.0.0.0/16

/ip firewall nat
add action=masquerade chain=srcnat out-interface=WAN1
add action=masquerade chain=srcnat out-interface=WAN2
add action=masquerade chain=srcnat out-interface=WAN3
add action=masquerade chain=srcnat out-interface=WAN4

/ip route
add check-gateway=ping distance=1 gateway=192.168.1.1 routing-mark=line1
add check-gateway=ping distance=1 gateway=192.168.2.1 routing-mark=line2
add check-gateway=ping distance=1 gateway=192.168.3.1 routing-mark=line3
add check-gateway=ping distance=1 gateway=192.168.4.1 routing-mark=line4
add check-gateway=ping distance=1 gateway=192.168.1.1
add check-gateway=ping distance=2 gateway=192.168.2.1
add check-gateway=ping distance=3 gateway=192.168.3.1
add check-gateway=ping distance=4 gateway=192.168.4.1

The key is that the response from the server to the client must come from the same IP address to which the client has sent the request.

So in addition to connection-marking the initial packets of outgoing connections using the ****

nth

classifier, you must also connection-mark the initial packets of incoming connections based on

in-interface

.

Hello sindy,
I didn’t understand you…
The ADSL routers has Real/Static IPs That I connect to.
and I connect to them via the internet

That doesn’t prevent the Mikrotik from choosing the route for the response packets among all the default routes up to their

distance

parameter if none of the interfaces is down. And by

distance

, WAN1 always wins.

So as I’ve said, you have to

  • connection-mark, in ****
chain=prerouting

of

/ip firewall mangle

, the incoming connections via each interface with a

new-connection-mark

value corresponding to that interface,

  • translate these connection marks to routing marks in ****
chain=output

of

/ip firewall mangle

.

This way, each incoming connection will “remember” its interface by means of the connection mark, and choose the route via that interface for response packets up to the routing mark assigned based on the connection mark.

The connection-mark-to-routing-mark translation rules in ****

chain=prerouting

do not affect locally originated packets because locally originated packets do not pass that chain. This picture says it all.

Could you write the script of them for me please?

/ip firewall mangle
add action=mark-connection chain=prerouting connection-state=new new-connection-mark=line1 in-interface=WAN1 passthrough=no
add action=mark-connection chain=prerouting connection-state=new new-connection-mark=line2 in-interface=WAN2 passthrough=no
add action=mark-connection chain=prerouting connection-state=new new-connection-mark=line3 in-interface=WAN3 passthrough=no
add action=mark-connection chain=prerouting connection-state=new new-connection-mark=line4 in-interface=WAN4 passthrough=no
add action=mark-routing chain=output connection-mark=line1 new-routing-mark=line1 passthrough=no
add action=mark-routing chain=output connection-mark=line2 new-routing-mark=line2 passthrough=no
add action=mark-routing chain=output connection-mark=line3 new-routing-mark=line3 passthrough=no
add action=mark-routing chain=output connection-mark=line4 new-routing-mark=line4 passthrough=no

Hello sindy
i have change from NTH to PCC for some Internet issues
and added the code you have told me
but its not work please take alook for my config

/interface ethernet
set [ find default-name=ether10 ] name=LAN
set [ find default-name=ether1 ] name=WAN1
set [ find default-name=ether2 ] name=WAN2
set [ find default-name=ether3 ] name=WAN3
set [ find default-name=ether4 ] name=WAN4

/ip firewall mangle
add action=accept chain=prerouting dst-address=192.168.1.0/24 in-interface=\
    LAN
add action=accept chain=prerouting dst-address=192.168.2.0/24 in-interface=\
    LAN
add action=accept chain=prerouting dst-address=192.168.3.0/24 in-interface=\
    LAN
add action=accept chain=prerouting dst-address=192.168.4.0/24 in-interface=\
    LAN
add action=mark-connection chain=prerouting connection-mark=no-mark \
    dst-address-type=!local in-interface=LAN new-connection-mark=ISP1_conn \
    passthrough=yes per-connection-classifier=src-address:4/0
add action=mark-connection chain=prerouting connection-mark=no-mark \
    dst-address-type=!local in-interface=LAN new-connection-mark=ISP2_conn \
    passthrough=yes per-connection-classifier=src-address:4/1
add action=mark-connection chain=prerouting connection-mark=no-mark \
    dst-address-type=!local in-interface=LAN new-connection-mark=ISP3_conn \
    passthrough=yes per-connection-classifier=src-address:4/2
add action=mark-connection chain=prerouting connection-mark=no-mark \
    dst-address-type=!local in-interface=LAN new-connection-mark=ISP4_conn \
    passthrough=yes per-connection-classifier=src-address:4/3
add action=mark-routing chain=prerouting connection-mark=ISP1_conn \
    in-interface=LAN new-routing-mark=to_ISP1
add action=mark-routing chain=prerouting connection-mark=ISP2_conn \
    in-interface=LAN new-routing-mark=to_ISP2
add action=mark-routing chain=prerouting connection-mark=ISP3_conn \
    in-interface=LAN new-routing-mark=to_ISP3
add action=mark-routing chain=prerouting connection-mark=ISP4_conn \
    in-interface=LAN new-routing-mark=to_ISP4
add action=mark-connection chain=prerouting connection-state=new \
    in-interface=WAN1 new-connection-mark=line1 passthrough=no
add action=mark-connection chain=prerouting connection-state=new \
    in-interface=WAN2 new-connection-mark=line2 passthrough=no
add action=mark-connection chain=prerouting connection-state=new \
    in-interface=WAN3 new-connection-mark=line3 passthrough=no
add action=mark-connection chain=prerouting connection-state=new \
    in-interface=WAN4 new-connection-mark=line4 passthrough=no
add action=mark-routing chain=output connection-mark=line1 new-routing-mark=\
    line1 passthrough=no
add action=mark-routing chain=output connection-mark=line2 new-routing-mark=\
    line2 passthrough=no
add action=mark-routing chain=output connection-mark=line3 new-routing-mark=\
    line3 passthrough=no
add action=mark-routing chain=output connection-mark=line4 new-routing-mark=\
    line4 passthrough=no
    
    /ip firewall nat
add action=masquerade chain=srcnat out-interface=WAN1
add action=masquerade chain=srcnat out-interface=WAN2
add action=masquerade chain=srcnat out-interface=WAN3
add action=masquerade chain=srcnat out-interface=WAN4

/ip route
add check-gateway=ping distance=1 gateway=192.168.2.1 routing-mark=to_ISP2
add check-gateway=ping distance=1 gateway=192.168.3.1 routing-mark=to_ISP3
add check-gateway=ping distance=1 gateway=192.168.4.1 routing-mark=to_ISP4
add check-gateway=ping distance=1 gateway=192.168.1.1 routing-mark=to_ISP1
add check-gateway=ping distance=1 gateway=192.168.1.1
add check-gateway=ping distance=2 gateway=192.168.2.1
add check-gateway=ping distance=3 gateway=192.168.3.1
add check-gateway=ping distance=4 gateway=192.168.4.1

If I may, I am not sure if the passthrough on connection marking was intentionally set to no or if it was a copy / paste error, will wait for @sindy’s response to that, but to me it does not make sense as it will then never mark the routing, so below my suggestion to try:

Try this and let us know?

/ip firewall mangle
add action=mark-connection chain=prerouting connection-state=new new-connection-mark=line1 in-interface=WAN1 passthrough=yes
add action=mark-routing chain=output connection-mark=line1 new-routing-mark=line1 passthrough=no
add action=mark-connection chain=prerouting connection-state=new new-connection-mark=line2 in-interface=WAN2 passthrough=yes
add action=mark-routing chain=output connection-mark=line2 new-routing-mark=line2 passthrough=no
add action=mark-connection chain=prerouting connection-state=new new-connection-mark=line3 in-interface=WAN3 passthrough=yes
add action=mark-routing chain=output connection-mark=line3 new-routing-mark=line3 passthrough=no
add action=mark-connection chain=prerouting connection-state=new new-connection-mark=line4 in-interface=WAN4 passthrough=yes
add action=mark-routing chain=output connection-mark=line4 new-routing-mark=line4 passthrough=no

@CZFan, what I’ve posted was an add-on to existing rules, serving two separate purposes:

  • the first four rules are there to ensure that connections initiated by packets coming from outside, via one of the WAN interfaces, will be marked to use that WAN interface. Therefore, passthrough=yes is not necessary, because packets coming in via WAN typically do not need to be routing-marked, so we may stop mangling packets received from WAN immediately after connection-marking them. And the passthrough value is only relevant if the rule matches - if it doesn’t, the next rule is always processed.
  • the second four rules are there to assign a routing mark (based on connection mark) to packets sent by Mikrotik itself. Also here passthrough=no is fine, because once you assign one routing mark, there is no point in scanning further rules - unless something got wrong, none of them will match anyway.

But if there are some other things to do in the mangle table (like packet marking for QoS), of course you have to adjust the approach accordingly. However, if that was the case, I’d probably organize the distinct tasks into dedicated chains, so the first rule in chain=prerouting would call a “connection&routing marking” chain, and when processing of that chain would finish, the processing in chain=prerouting would continue (by assigning the packet marks for QoS). The passthrough=no in a rule in a called chain means that if the rule matches, only the rest of that called chain is skipped, and processing continues by the next rule in the calling chain.

Now let me have a look what is wrong with the complete configuration.

Hello CZFan
Same issue i cant conncet to winbox only from WAN1 works…

sindy
could you help me?

@ sindy, yes, I missed the “in-interface”, apologies and thx for the patience and explanation

@eslamxboss, in your original post you were using connection marks line1 to line4, so I’ve given you the additional rules in accord with that nameset.

However, in the last configuration export, you use connection marks ISP1_conn to ISP4_conn in the rules which assign them based on pcc and in the rules which translate them to routing marks, but you haven’t modified accordingly the rules you’ve got from me.

The trick is that the all connections which should use WAN1 must have the same connection mark (regardless whether ISP1_conn or line1, but the same one) regardless whether WAN1 was chosen for them by the pcc rule if the initial packet came from LAN or by the fact that the initial packet of the connection came in via WAN1 from outside.

Similarly, “my” rules in chain=output must assign the same routing marks up to the same connection marks as your rules in chain=prerouting. So replace lineX by ISPX_conn where they are used as conection marks, and replace lineX by to_ISPX where they are used as routing marks, and you’ll be good.

Connection marks, routing marks and packet marks use different namespaces, so a string used as a connection mark doesn’t interfere with the same string used as routing mark. You need the rules to translate the former into the latter.

Other than that, you use four rules differing only by dst-address=so.me.sub.net/24, but those subnets are adjacent to each other. You can merge that into a single rule with dst-address=192.168.1.0-192.168.4.255.

Could you edit the code please?

Copy-paste this to the terminal window, it will fix the configuration.

/ip firewall mangle
set [find action="mark-connection" chain="prerouting" connection-state="new" new-connection-mark="line1" in-interface="WAN1" passthrough="no"] new-connection-mark=ISP1_conn
set [find action="mark-connection" chain="prerouting" connection-state="new" new-connection-mark="line2" in-interface="WAN2" passthrough="no"] new-connection-mark=ISP2_conn
set [find action="mark-connection" chain="prerouting" connection-state="new" new-connection-mark="line3" in-interface="WAN3" passthrough="no"] new-connection-mark=ISP3_conn
set [find action="mark-connection" chain="prerouting" connection-state="new" new-connection-mark="line4" in-interface="WAN4" passthrough="no"] new-connection-mark=ISP4_conn
set [find action="mark-routing" chain="output" connection-mark="line1" new-routing-mark="line1" passthrough="no"] connection-mark=ISP1_conn new-routing-mark=to_ISP1
set [find action="mark-routing" chain="output" connection-mark="line2" new-routing-mark="line2" passthrough="no"] connection-mark=ISP2_conn new-routing-mark=to_ISP2
set [find action="mark-routing" chain="output" connection-mark="line3" new-routing-mark="line3" passthrough="no"] connection-mark=ISP3_conn new-routing-mark=to_ISP3
set [find action="mark-routing" chain="output" connection-mark="line4" new-routing-mark="line4" passthrough="no"] connection-mark=ISP4_conn new-routing-mark=to_ISP4

I want you thank you very much
Its working now!!!

Just to confirm, the OP was talking about accessing the routerboard from outside the router (ie on the internet) and not internal access. I thought the reverse and was wondering why are we monkeying with in-interface WAN rules. :slight_smile:

Would it be better or easier to simply use VPN to access the router and then use WINBOX (from the inside).
If so I guess the problem remains, of the ability to vpn in on any of the WANS??

Exactly. The transport connection of a VPN is a connection just like any other, so you need to make sure that it uses the WAN through which it was established for both directions.

sindy
Which four rules?



add action=accept chain=prerouting dst-address=192.168.1.0/24 in-interface=LAN
add action=accept chain=prerouting dst-address=192.168.2.0/24 in-interface=LAN
add action=accept chain=prerouting dst-address=192.168.3.0/24 in-interface=LAN
add action=accept chain=prerouting dst-address=192.168.4.0/24 in-interface=LAN

can be replaced by a single rule

add action=accept chain=prerouting dst-address=192.168.1.0-192.168.4.255 in-interface=LAN