DED9

Load Balancing Technique Training In Mikrotik

Load Balancing Is A Technique Used To Send Network Traffic Through Multiple Gateways. If You Have Multiple ISP Connections On Your Network, You Can Send Your Network Traffic Through Those ISP Connections, And You Can Create A Load Balancing Network.

You may be wondering why we would use multiple ISP connections. What are the benefits of using various ISP connections on a network? This article will thoroughly review the concept of Load balancing in Mikrotik.

Suppose you have recently purchased a Mikrotik server and intend to establish a smooth and uninterrupted connection. In that case, we suggest you stay with us until the end of this article.

Reasons why it is essential to have multiple ISP connections on your network:

  1. No ISP can guarantee 100% that their connection will always remain intact. Therefore, using more than one ISP connection in your network is better to increase the probability of your internet access.
  2. You have an ISP connection that is not so good, but you cannot disconnect it because you are using other services (like Mail, IPPBX, etc.) of this ISP. In this case, you can use another ISP that offers you better services.
  3. You have a better ISP connection but a high-paid bandwidth. In that case, you can buy bandwidth from another cheap ISP with a good relationship.

Now that you’re convinced to use multiple ISP connections on your network, let’s look at how load balancing works. You can load balance your network and create link redundancy if you have multiple ISP connections. You can make load balancing and link redundancy using a Mikrotik router. I will show you how to create a load-balancing network using only Policy Based Routing (PBR) on a MikroTik router.

Policy Routing Based on Client IP Address (PBR)

Policy-based routing (PBR) is a technique used to make routing decisions based on policies set by each network administrator. Therefore, in the following, we will show you an approach to the Mikrotik router by which you can create a load-balancing system in your network.

If you have several hosts and multiple ISP connections, you can group your hosts by IP addresses and send traffic through different ISP connections depending on the source IP address. For example, consider a simple office network diagram like the one below, where two ISP connections are used as gateways to a MikroTik router.

Network Load Balancing across multiple gateways at Mikrotik

In this network diagram, two ISP connections are used as WAN connections of a MikroTik router. Also, several hosts are connected to this Mikrotik router through a distribution switch. Since dual WAN connections are available for this MikroTik router, we will create a PBR routing so that half of our total LAN users will access the Internet through the ISP WAN1 connection, and the rest of the LAN users will access the Internet through the ISP’s WAN2 connection. They will have internet access.

Five steps to creating PBR routing on MikroTik router

Now I will show you how to create a routing policy on your MikroTik router so that half of your LAN users get Internet through a WAN1 connection and the other half of your LAN users get Internet through WAN2 links.

-Like the simple office network diagram above, you must have two WAN connections in your Mikrotik router for load balancing. Also, several hosts are connected to this Mikrotik router to access the Internet. This means that you can create a load-balancing network on these two gateways.

The entire configuration for applying policy-based routing to create a load-balancing network with a Mikrotik router can be divided into five steps.

We will explain all the above steps in the rest of this article to configure a load-balancing network on multiple gateways.

Step 1. Assign WAN and LAN IP addresses

To configure a complete load-balancing network with policy-based routing, you must first assign WAN and LAN IP addresses on your MikroTik router. Since you have two ISP connections, you must have two WAN IP addresses and two gateway addresses. For the configuration of this article, we will use two WAN IP addresses and two gateway addresses for different ISP connections.

I will configure this article with these WAN IP addresses and Gateway addresses. Still, in practice, your WAN IP addresses and Gateway addresses should differ, and your ISP company will provide these.

However, you also have a LAN with many hosts. For the configuration of this article, I assume the LAN IP block and Gateway address are as below.

We have our WAN IP addresses and our LAN IP block. Now I will show you how to assign these WAN IP addresses and LAN gateway addresses in your MikroTik router. Follow the steps below to set your MikroTik router’s WAN and LAN IP addresses.

  1. Log into your MikroTik router with Winbox software. If you are new to this article and the MikroTik router, follow the Connecting to MikroTik Server article.
  2. Go to the IP > Addresses option from the inbox menu bar. The address list window appears.
  3. Now click on Add button. A new address window will appear. Enter your WAN1 IP address (in this article: 172.22.15.221/24) in the address input box and select the WAN1 interface (in this article: ether1) from the Interface drop-down menu, and then click the Apply and Confirm button.
  4. Likewise, click the Add button again, put your WAN2 IP address (in this article: 192.168.168.210/24) in the address input field, and select the WAN2 interface (in this article: ether2) from the Interface drop-down menu. Select and then click the OK button.
  5. Click the Add button again, put your LAN gateway IP (in this article: 192.168.10.254/24) in the Address input field, select your LAN interface (in this article: ether10) from the Interface drop-down menu, and then click Click Apply and press the OK button.

The assignment of WAN and LAN IP addresses is completed. Now, in the next step, we will configure the DNS server.

Step 2. DNS server configuration

DNS is not a mandatory configuration in the MikroTik router, but it is necessary for a complete MikroTik router configuration. Optionally, you can turn your MikroTik router into a DNS server, which will be helpful for your network. So, if you want to set DNS IP on your MikroTik router and also want to turn your MikroTik into a DNS server, follow the simple steps below.

  1. Go to IP > DNS menu option. The DNS settings window appears. Enter your DNS server IP provided by your ISP, or you can use Google’s public DNS server IP 8.8.8.8 in the servers entry.
  2. You can click the Allow Remote Requests checkbox to turn your MikroTik router into a DNS server. But you must block DNS requests from outside your local network. Otherwise, your MikroTik will be used as a DNS server if public users know your MikroTik’s public IP.
  3. Now click on Apply and OK button.

The DNS configuration on the MikroTik router is complete. Now we create a NAT masquerade rule so that our LAN user can access the Internet through our MikroTik router.

Step 3. Configure NAT

Now we create a NAT masquerade rule so that our LAN IP is NATed by the Mikrotik router. If we do not make this rule, our LAN users will not be able to access the Internet through our Mikrotik router, and the Load balancing technique will not be performed in our network. So, follow the below steps to create a NAT rule on the MikroTik router.

  1. Go to the IP section of the firewall section, and the firewall window will appear. Click on the NAT tab and the Add New button in this window. A new NAT Rule window will appear.
  2. In the General tab, select scant from the Chain drop-down menu and put the IP block address of your LAN (in this article: 192.168.10.0/24) in the address input field. Now click on the Action tab, select the masquerade option from the Action drop-down menu, and then click on the Apply button and OK.

The configuration of the NAT rule on the MikroTik router is complete. Now we create Mangle rules in our MikroTik router to divide our LAN users into two groups.

Step 4. Create Mangle rule

As we want to send our LAN users across two ISP connections for load balancing, we need to create Mangle rules that divide our LAN users into two groups and mark them for proper routing. I will use a class C IP block, 192.168.10.0/2,4, in this article for our LAN users. This IP block can be divided into two groups by subnetting as below.

Now I will show you two rules of Mangle. This subnetting allows all our users to be divided into two groups. Users using IP addresses between 192.168.10.1 and 192.168.10.126 will be in group A, and those using IP addresses between 192.168.10.129 and 192.168.10.253 will be in group B. On the MikroTik router, they correctly group and mark our LAN IPs.

Follow the steps below to create these Mangle rules.

  1. Go to the IP > Firewall menu, click the Mangle tab in the Firewall window, and then click the Add New button. Now the new Mangle Rule window will appear.
  2. Select the prerouting option from the Chain drop-down menu and put the IP block of group A (in this article: 192.168.10.0/25) in the address input field. Click the Action tab, select mark routing from the Action drop-down menu, put the group’s name (here, GroupA) in the New Routing Mark input box, uncheck the Passthrough option, and then click the Apply and OK buttons.
  3. Likewise, click the Add New button again, select the prerouting option from the Chain drop-down menu, and put the IP group B block (here, 192.168.10.128/25) in the address input field. Now click on the Action tab, select the mark routing option from the Action drop-down menu, put the group’s name (here, GroupB) in the New Routing Mark input field, uncheck the Passthrough option and then click the Apply button and OK.

We have successfully created Mangle rules to group our LAN users. Now we will configure the routes on the MikroTik router so that different groups can access the Internet through other ISP connections.

Step 5. Route configuration

After creating Mangle rules, for Load balancing, you now need to configure Mikrotik routing so that your different user groups can use the other WAN connections to access the Internet. So, follow the steps below to configure your MikroTik router properly.

  1. Go to IP > Routes menu option. Now the Route List window will appear. From this window, click on the Add New button. The new path window will appear.
  2. Enter the gateway address of ISP1 (here, 172.22.15.1) in the Gateway input field and select your routing mark (here, GroupA) for this GatewGateway the Routing Mark drop-down menu, and then click the Apply and Confirm button.
  3. Likewise, click the Add New (+) button and enter the gateway address of ISP2 (here, 192.168.168.254) in the Gateway input field and your routing mark (here, GroupB) for this gatewGateway the Routing Mark drop-down menu. Select and then click Apply and OK button.
  4. Click the Add New (+) button again and enter any ISP gateway (here, 172.22.15.1) and the Apply and OK buttons. If you do not apply this path, your MikroTik will not be able to access the Internet.

After this configuration, your GroupA users will access the Internet through the ISP1 gatewGateway GroupB users will access the Internet through the ISP2 gatewGateway with this Mikrotik configuration, you will have a complete Load balancing network. 

Now a question may arise in your mind. What happens if ISP disconnects? Yes, half of your users will be disconnected from the Internet. As I said earlier, this configuration is only for load balancing but not redundancy.

Exit mobile version