Load balancing same gateway

Hi everyone,

I have a router rg760igs, I’d like to setup load balancing with 2 WANs dhcp clients same gateway (192.168.1.1) and 1 WAN dhcp client (192.168.2.1). How can i config load balancing there 3 lines come in ether1,2,3. And LAN out ether4, 5

There is an example here _https://wiki.mikrotik.com/wiki/Manual:PCC_

This part is easy or complex depending on your requirements.

If you don’t want to check whether the WAN path is completely OK all the way through the ISP network to the internet, i.e. you are only interested in load distribution, not resilience in case of outage of one WAN path, you just specify the right interface for the two routes via the two “distinct” 192.168.1.1:

/ip route
add routing-mark=via-WAN1 gateway=192.168.1.1**%ether1**
add routing-mark=via-WAN2 gateway=192.168.1.1**%ether2**
add routing-mark=via-WAN3 gateway=192.168.2.1

If you want to use the scriptless failover using recursive routing, you cannot use anything but IP addresses as gateways. Hence you need a bit of advanced magic to overcome the same subnets on the two WANs, so only do that if you really cannot change either of the subnets the connected uplink equipment uses.

The trick is to set up an additional static IP configuration on the same interface (I use ether2 throughout the example), e. g. address=192.168.55.2/24, and set the lowest level recursive route for monitoring the “virtual gateway” address in the internet with gateway=192.168.55.1. When a gateway is used to send a paket to some other destination IP address, no IP packet is actually ever sent to the own address of the gateway. The address is only used to identify the interface from which to send the packet (because it is in the subnet attached to that interface) and to resolve the MAC address of the gateway by means of the ARP protocol. But as no host with IP address 192.168.55.1 is actually connected to the interface, the ARP would never get a response. So you have to create a static ARP record translating 192.168.55.1 to the MAC address of the connected router whose actual IP address is 192.168.1.1. As the MAC address may change when the ISP change their equipment, the best way to keep the static ARP record up to date is to use a script on the DHCP client:

:if ($bound=1) do={
  :ping arp=yes interface=ether2 $"gateway-address" count=1
  :local gwMAC [/ip arp get [find address=$"gateway-address"] mac-address]
  :local arpRecord [/ip arp find address=192.168.55.1]
  :if (!([/ip arp get $arpRecord mac-address] = $gwMAC)) do={
   /ip arp set $arpRecord mac-address=$gwMAC
  }
}

But this DHCP client script will only update the ARP record, not create it, so you have to create it manually first: /ip arp add interface=ether2 address=192.168.55.1 mac-address=0:0:0:0:0:0. Once you’ve created the record, do /ip dhcp-client release [find interface=ether2], so that the script would run and update the ARP record with the actual MAC address of the gateway.

An action=masquerade rule in /ip firewall nat is necessary to make sure that packets will be sent from ether2 with the IP address assigned by the DHCP server, not the manually assigned one, as their source address. Otherwise the response packets could not be delivered because the connected ISP device doesn’t know the manually assigned subnet, so it would send the packets for 192.168.55.2 via its own default route.

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

Having bare minimum knowledge I am finding it hard to understand the advantage of load balancing two IP addresses from teh same gateway. Assuming the same single cable, would it not be likely that the OP is not getting another MB or GB of throughput, but just another IP address?? Oops, now I reread and see three lines coming in… my bad.