Header Ads

How to Setup Load Balancing On Mikrotik Router Using The PCC Features.


Load balancing is the ability to balance traffic across two or more WAN links by using basic routing. When connections are initiated for session like Web, email, video streaming etc, the traffic is distributed over all WAN links.

 For example, if you have internet service from two ISPs 10Mbps and 5Mbps respectively, you will now have a total bandwidth of 15Mbps. When browsing the internet your browser will open multiple connections to the website, each connection will download a different part of the page, some for images and others for text which makes websites load faster.

Also, network load balancing is mostly used to provide network redundancy so that in the event of an outage on one of the WAN link, access to network resources is still available via the secondary link(s). Link redundancy is a key requirement for business continuity plans and is largely used in combination with critical applications like VPNs and VoIP.


While dealing with load balancing, Mikrotik has benefits over other routers, because of its features. One of the features we will be looking at while configuring our load balancing is the Mikrotik PCC features.

PCC is a feature in Mikrotik routerOS that allows traffics to be divided into equal streams of packets, giving administrators the ability to identify and keep specific traffics restricted to a predefined connection. It can be used to accomplish load-balancing with the option of automatic fail-over in a dual ISP connection. In this post, I will share with us on how to configure load balancing on a Mikrotik router, using the Mikrotik PCC features.






We can then create a connections that will go out via ISP1 and come in via same and vise versa. The configuration below ensures it is achieved. First, address the interfaces.

Mikrotik basic configuration here. If your new  to mikrotik i advice you read my post on getting started with mikrotik router.

Next, we use policy routing to permit traffics from the LAN to WAN subnets.


/ ip firewall mangle


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


add chain=prerouting dst-address=192.168.2.0/30 action=accept in-interface=LAN


Next, we identify, mark and keep connections through both WAN links separate. This makes sure that requests that come in through a particular ISP connection, leave via same. See below.


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

Next, we must also identify and separate traffics originating from the LAN and going out through a particular ISP connection. This will ensure the return through same. See below:

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

Next, we have to create routes using the connection marks created above. The route marks are created for connections via the LAN and WAN interfaces. These routes will be used to create default routes to our ISPs. See below.

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

Now, we create default routes using the route marks.This makes sure that ISP1's connections remain on ISP1's link while those of ISP2, remain on ISP2's link. See below.

/ ip route


add dst-address=0.0.0.0/0 gateway=192.168.1.1 routing-mark=to_ISP1 check-gateway=ping


add dst-address=0.0.0.0/0 gateway=192.168.2.1 routing-mark=to_ISP2 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


Finally, the NAT rule making sure that private IPs are masqueraded to the public IPs on the WAN ports as they exit to the internet.

/ ip firewall nat


add chain=srcnat out-interface=ISP1 action=masquerade


add chain=srcnat out-interface=ISP2 action=masquerade

See complete complete configuration command below:

/ ip address


add address=172.16.10.1/24 network=172.16.10.0 broadcast=172.16.10.255 interface=LAN


add address=192.168.1.2/30 network=192.168.1.0 broadcast=192.168.1.3 interface=ISP1


add address=192.168.2.2/30 network=192.168.2.0 broadcast=192.168.2.3 interface=ISP2


/ ip firewall mangle

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

add chain=prerouting dst-address=192.168.2.0/30 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=192.168.1.1 routing-mark=to_ISP1 check-gateway=ping


add dst-address=0.0.0.0/0 gateway=192.168.2.1 routing-mark=to_ISP2 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=ISP1 action=masquerade

add chain=srcnat out-interface=ISP2 action=masquerade.





so this is all new to configure load Balancing On Mikrotik Router Using The PCC Features.
If you have any challenge doing the above configuration please leave us a message in the comment box below and we will get back to you as soon as possible. thanks for staying with us.

No comments:

Theme images by Jason Morrow. Powered by Blogger.