Community discussions

MikroTik App
 
podwodnaja
just joined
Topic Author
Posts: 1
Joined: Wed Apr 30, 2014 10:38 am

Load balancing and failover

Thu May 01, 2014 12:07 pm

Hi everyone.

I have a question and hope you people can help me out. Through the next youtube movie I have setup 2 connections on my Mikrotik.

https://www.youtube.com/watch?v=ECqntLlhaz8

Failover works great, only the load balancing (like in the video) doesn't work.

I have used this set of terminal rules with different values of my connection and LAN port of course:

Link(1) - 192.168.3.1 = WAN1

Link(2) - 192.168.4.1= WAN2

WAN-OUT = However u wanna export traffic

/ip firewall mangle
add chain=input in-interface=WAN1 action=mark-connection new-connection-mark=WAN1_conn
add chain=input in-interface=WAN2 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.3.0/24 action=accept in-interface=WAN-OUT
add chain=prerouting dst-address=192.168.4.0/24 action=accept in-interface=WAN-OUT

add chain=prerouting dst-address-type=!local in-interface=WAN-OUT 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=WAN-OUT 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=WAN-OUT action=mark-routing new-routing-mark=to_WAN1
add chain=prerouting connection-mark=WAN2_conn in-interface=WAN-OUT action=mark-routing new-routing-mark=to_WAN2

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

add dst-address=0.0.0.0/0 gateway=192.168.3.1 distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.4.1 distance=2 check-gateway=ping

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

Now here is mine (I have changed the values of my WAN connections for privacy):

/ip firewall mangle

add chain=input in-interface=ether1-GW-Zantel action=mark-connection new-connection-mark=WAN1_conn
add chain=input in-interface=ether2-GW2-Maishal action=mark-connection new-connection-mark=WAN2_conn

add chain=output connection-mark=WAN1_conn action=mark-routing new-routing-mark=to_ether1-GW-Zantel
add chain=output connection-mark=WAN2_conn action=mark-routing new-routing-mark=to_ether2-GW2-Maishal

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

add chain=prerouting dst-address-type=!local in-interface=ether3-LAN 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=ether3-LAN 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=ether3-LAN action=mark-routing new-routing-mark=to_ether1-GW-Zantel
add chain=prerouting connection-mark=WAN2_conn in-interface=ether3-LAN action=mark-routing new-routing-mark=to_ether2-GW2-Maishal

/ip route
add dst-address=0.0.0.0/0 gateway=192.168.1.1 routing-mark=to_ether1-GW-Zantel check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.2.1 routing-mark=to_ether2-GW2-Maishal check-gateway=ping

add dst-address=0.0.0.0/0 gateway=192.168.1.1 distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.2.1 distance=2 check-gateway=ping

/ip firewall nat
add chain=srcnat out-interface=ether1-GW-Zantel action=masquerade
add chain=srcnat out-interface=ether2-GW2-Maishal action=masquerade

I hope you can help out.
 
nemswisp
just joined
Posts: 6
Joined: Sat Oct 26, 2013 12:20 am

Re: Load balancing and failover

Fri May 16, 2014 5:48 am

I think what you want is to have your traffic to combine both of your internet connections at least that is what I wanted and needed. I have to connections to the internet both 30M download and 3M upload and I wanted to run a speed test that showed a 60M download and 6M upload but what I got was 30M download and 3M upload with PCC as it is in the manual.

I've been working on this for some time now. I had it working once before. Thought I had it backed up but then couldn't find back up and the router I was using it on crashed of course! Lesson learned. Like you I looked for youtube video to see how I might do this. The video I seen used PCC just like was in the Mikrotik Manual. Only thing is PCC doesn't work that way.

PCC that is in the manual only does per connection load balancing which means when a client first opens a connect on ether port 1 or ether port 2 that is the only port it will use from that point on until and new connection is made. What I think you may want is a per-packet load balancing which can be done using PCC but it has to modified for it to work that way.

I combined PCC with nth to do load balancing.
First here is the PCC script as it is in the manual.
I should note that I am using a RB1100AHx2 v.5.26 I had it on a 750GL as well. That's the one I lost. lol

PCC Load Balancing
(As it is written in Manual)

/ ip address
add address=192.168.0.1/24 network=192.168.0.0 broadcast=192.168.0.255 interface=LAN
add address=10.111.0.2/24 network=10.111.0.0 broadcast=10.111.0.255 interface=ISP1
add address=10.112.0.2/24 network=10.112.0.0 broadcast=10.112.0.255 interface=ISP2

/ ip firewall mangle
add chain=prerouting dst-address=10.111.0.0/24 action=accept in-interface=LAN
add chain=prerouting dst-address=10.112.0.0/24 action=accept in-interface=LAN
add chain=prerouting in-interface=ISP1 connection-mark=no-mark action=mark-connection \
new-connection-mark=ISP1_conn
add chain=prerouting in-interface=ISP2 connection-mark=no-mark action=mark-connection \
new-connection-mark=ISP2_conn
add chain=prerouting in-interface=LAN connection-mark=no-mark dst-address-type=!local \
per-connection-classifier=both-addresses:2/0 action=mark-connection new-connection-

mark=ISP1_conn
add chain=prerouting in-interface=LAN connection-mark=no-mark dst-address-type=!local \
per-connection-classifier=both-addresses:2/1 action=mark-connection new-connection-

mark=ISP2_conn
add chain=prerouting connection-mark=ISP1_conn in-interface=LAN action=mark-routing \
new-routing-mark=to_ISP1
add chain=prerouting connection-mark=ISP2_conn in-interface=LAN action=mark-routing \
new-routing-mark=to_ISP2
add chain=output connection-mark=ISP1_conn action=mark-routing new-routing-mark=to_ISP1
add chain=output connection-mark=ISP2_conn action=mark-routing new-routing-mark=to_ISP2

/ ip route
add dst-address=0.0.0.0/0 gateway=10.111.0.1 routing-mark=to_ISP1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=10.112.0.1 routing-mark=to_ISP2 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=10.111.0.1 distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=10.112.0.1 distance=2 check-gateway=ping

/ ip firewall nat
add chain=srcnat out-interface=ISP1 action=masquerade
add chain=srcnat out-interface=ISP2 action=masquerade

Here it is with the modifications I had to make it work the way I needed. That was to take two 30M connection and make one 60M connection. (I may have made some formatting errors so you may have to correct for that)

Rewritten for per packet load balance

/ ip address
add address=192.168.0.1/24 network=192.168.0.0 broadcast=192.168.0.255 interface=LAN
add address=10.111.0.2/24 network=10.111.0.0 broadcast=10.111.0.255 interface=ISP1
add address=10.112.0.2/24 network=10.112.0.0 broadcast=10.112.0.255 interface=ISP2

/ ip firewall mangle
add chain=prerouting dst-address=10.111.0.0/24 action=accept in-interface=LAN
add chain=prerouting dst-address=10.112.0.0/24 action=accept in-interface=LAN
add chain=prerouting in-interface=ISP1 connection-mark=no-mark action=mark-connection nth=2,1 \
new-connection-mark=ISP1_conn
add chain=prerouting in-interface=ISP1 connection-mark=no-mark action=mark-connection nth=2,2 \
new-connection-mark=ISP2_conn
add chain=prerouting in-interface=ISP2 connection-mark=no-mark action=mark-connection nth=2,1 \
new-connection-mark=ISP1_conn
add chain=prerouting in-interface=ISP2 connection-mark=no-mark action=mark-connection nth=2,2 \
new-connection-mark=ISP2_conn
add chain=prerouting in-interface=LAN connection-mark=no-mark dst-address-type=!local \
per-connection-classifier=both-addresses-and-ports:2/0 action=mark-connection new-connection-

mark=ISP1_conn
add chain=prerouting in-interface=LAN connection-mark=no-mark dst-address-type=!local \
per-connection-classifier=both--addresses-and-ports:2/1 action=mark-connection new-

connection-mark=ISP2_conn
add chain=prerouting connection-mark=ISP1_conn in-interface=LAN action=mark-routing \
new-routing-mark=to_ISP1
add chain=prerouting connection-mark=ISP2_conn in-interface=LAN action=mark-routing \
new-routing-mark=to_ISP2
add chain=output connection-mark=ISP1_conn action=mark-routing new-routing-mark=to_ISP1
add chain=output connection-mark=ISP2_conn action=mark-routing new-routing-mark=to_ISP2

/ ip route
add dst-address=0.0.0.0/0 gateway=10.111.0.1 routing-mark=to_ISP1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=10.112.0.1 routing-mark=to_ISP2 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=10.111.0.1 distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=10.112.0.1 distance=2 check-gateway=ping

/ ip firewall nat
add chain=srcnat out-interface=ISP1 action=masquerade
add chain=srcnat out-interface=ISP2 action=masquerade

If this works for you let me know. Also you may need to add some other rules if you use a lot of secure servers connections from your network.