Diagram of a fibre line and a fixed LTE line connected to one MikroTik router, with the office network's load shared between them
Category: MikroTik

Internet outages are a recurring event for many companies: sometimes the telecom exchange, sometimes the provider, sometimes a power cut at the exchange. The result is always the same: IP phones drop, the accounting software cannot reach its cloud server, and staff sit idle.

The professional fix is to have two or more internet lines over different routes and a MikroTik router that both shares the load between them and, if one fails, sends everything over the line that still works. In this article we build both, step by step, with PCC on RouterOS 7.

Two internet lines, fibre and fixed LTE, connected to a MikroTik router that shares the office network's load between them
Two internet lines, fibre and fixed LTE, connected to a MikroTik router that shares the office network's load between them

Failover or load balancing?

MethodWhat it doesBest for
FailoverEveryone uses the main line; if it fails, the second line takes overWhen the second line is slow or metered (for example fixed LTE or 4G)
Load balancing (PCC)Connections are shared between the lines, so you use the capacity of bothWhen the two lines are roughly equal
Both togetherThe load is shared, and if one line fails everything moves to the otherMost companies; this is what we build here

If you only need simple failover, Routing in MikroTik: from a simple route to two internet lines is enough. Here we take the next step.

An important point: load balancing does not add up the speed of one download. With two 50 Mbps lines, a single file over a single connection still downloads at up to 50 Mbps; but when ten people work at the same time, the combined capacity of both lines is used.

Before configuring: choose the second line carefully

Most outages happen at the infrastructure level, not at the provider. If you buy two DSL lines from two different providers that both run through the same exchange and the same copper cable, they fail together when that exchange goes down. Better combinations:

  • Fibre (FTTH) + fixed LTE or fixed wireless
  • Fibre + a 4G/5G modem (for failover, with a data cap)
  • Two fibre lines over two routes from two different providers, if the building allows it
  • For sites with several buildings, a wireless or fibre link between buildings can bring another building's line in as a backup.

And do not forget: if the router and modems lose power, none of this works. Put the router and modems on a UPS; the details are in Server room UPS design and backup power.

The scenario in this guide

PartExample value
Line one (fibre)Port ether1, gateway 203.0.113.1
Line two (fixed LTE)Port ether2, gateway 198.51.100.1
Office networkA bridge called bridge, network 192.168.88.0/24
VersionRouterOS 7

These addresses are examples; use the real values of your own lines. If one line is PPPoE or L2TP, write that interface's name instead of ether. Always back up the router before any change.

PCC load balancing in four steps: connection mark with mangle, routing mark, routing table and NAT
PCC load balancing in four steps: connection mark with mangle, routing mark, routing table and NAT

Step 1: routing tables

In RouterOS 7 you create a separate routing table for each line:

/routing table
add name=to_ISP1 fib
add name=to_ISP2 fib

Step 2: marking connections with PCC

The PCC (Per Connection Classifier) rule hashes every new connection by its addresses and puts it in one of two groups. Each connection stays on the same line for its whole life.

/ip firewall mangle
add chain=prerouting in-interface=bridge dst-address=192.168.88.0/24 action=accept comment="LAN to LAN"
add chain=prerouting in-interface=ether1 connection-mark=no-mark action=mark-connection new-connection-mark=ISP1_conn
add chain=prerouting in-interface=ether2 connection-mark=no-mark action=mark-connection new-connection-mark=ISP2_conn
add chain=prerouting in-interface=bridge dst-address-type=!local connection-mark=no-mark per-connection-classifier=both-addresses:2/0 action=mark-connection new-connection-mark=ISP1_conn
add chain=prerouting in-interface=bridge dst-address-type=!local connection-mark=no-mark per-connection-classifier=both-addresses:2/1 action=mark-connection new-connection-mark=ISP2_conn
add chain=prerouting in-interface=bridge connection-mark=ISP1_conn action=mark-routing new-routing-mark=to_ISP1 passthrough=no
add chain=prerouting in-interface=bridge connection-mark=ISP2_conn action=mark-routing new-routing-mark=to_ISP2 passthrough=no
add chain=output connection-mark=ISP1_conn action=mark-routing new-routing-mark=to_ISP1 passthrough=no
add chain=output connection-mark=ISP2_conn action=mark-routing new-routing-mark=to_ISP2 passthrough=no

What the lines do:

  • The first line keeps traffic inside the office network out of load balancing.
  • The second and third lines mark connections that arrive from outside on each line, so their replies go back over the same line (essential for port forwarding and remote access).
  • The fourth and fifth lines spread users' connections across the two lines with PCC. 2/0 and 2/1 mean "split into two groups; this is group zero, that is group one".
  • The remaining lines send each marked connection to its own routing table.

Why both-addresses?

Some sites, especially bank payment gateways and government portals, end the session if your IP address changes mid-way. With both-addresses, all connections from one user to one destination use the same line, so this does not happen. both-addresses-and-ports spreads the load more evenly but causes exactly this problem.

Unequal lines

If line one is twice as fast as line two, make three groups instead of two and give two of them to line one: both-addresses:3/0 and 3/1 for ISP1, and 3/2 for ISP2.

Step 3: routes and failover

/ip route
add dst-address=0.0.0.0/0 gateway=203.0.113.1 routing-table=to_ISP1 distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=198.51.100.1 routing-table=to_ISP1 distance=2
add dst-address=0.0.0.0/0 gateway=198.51.100.1 routing-table=to_ISP2 distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=203.0.113.1 routing-table=to_ISP2 distance=2
add dst-address=0.0.0.0/0 gateway=203.0.113.1 distance=1 check-gateway=ping comment="main ISP1"
add dst-address=0.0.0.0/0 gateway=198.51.100.1 distance=2 check-gateway=ping comment="main ISP2"

Each table has two routes: the main one with distance=1 and the other line with distance=2 as a backup. When check-gateway=ping sees that a line's gateway is not answering, its route is disabled and that table's traffic goes over the other line. The last two lines are for the main table, used by the router's own traffic and anything unmarked.

The limit of check-gateway: it only pings the gateway. If the modem is on but its internet is down, the gateway still answers and failover does not happen. For that case use recursive routing, which checks the route through an outside address such as a public DNS server. A full example is in Routing in MikroTik.

Step 4: NAT for each line

/ip firewall nat
add chain=srcnat out-interface=ether1 action=masquerade comment="NAT ISP1"
add chain=srcnat out-interface=ether2 action=masquerade comment="NAT ISP2"

If you already have a general masquerade rule that uses out-interface-list=WAN and both ports are in the WAN list, that is enough.

Step 5: check FastTrack

MikroTik's default configuration has a FastTrack rule that, for speed, lets packets skip normal processing, including mangle. It conflicts with load balancing and sends traffic out of the wrong line. The simplest fix is to disable it:

/ip firewall filter print where action=fasttrack-connection
/ip firewall filter disable [find action=fasttrack-connection]

On small routers, disabling FastTrack raises CPU load. If the CPU struggles, you need a stronger router; to choose a model, see MikroTik devices and model names explained.

Step 6: outage alerts with Netwatch

Failover is automatic, but you still want to know when a line is down so you can chase the provider:

/tool netwatch
add host=203.0.113.1 interval=30s comment="ISP1" down-script=":log warning \"ISP1 down\"" up-script=":log info \"ISP1 up\""
add host=198.51.100.1 interval=30s comment="ISP2" down-script=":log warning \"ISP2 down\"" up-script=":log info \"ISP2 up\""

Instead of writing to the log, the scripts can also send an email or a message. For fuller monitoring, see Network monitoring tools compared.

Testing

  1. In IP › Firewall › Connections, look at the Connection Mark column; connections should be spread between ISP1_conn and ISP2_conn.
  2. In Interfaces, watch the traffic on both WAN ports at the same time.
  3. Unplug line one. After a few seconds everything should work over line two. Plug it back in and watch it return.
  4. Log in to a bank payment gateway from several computers to make sure the session does not drop.

Common problems

ProblemLikely causeFix
All traffic uses one lineFastTrack is on, or the mangle rules are in the wrong orderDisable FastTrack and check the rule order
The bank site keeps logging you outboth-addresses-and-ports is usedChange to both-addresses
After a line fails, the internet does not come backThe modem is on and check-gateway does not see the outageSet up recursive routing
Port forwarding does not work on one lineIncoming connections are not markedAdd the second and third mangle lines
VoIP calls to an outside provider keep droppingThe SIP connection moves between the linesPin SIP traffic to one line with policy routing

For the last problem, also see Why do IP phones keep dropping?.

Summary

Reliable internet needs three things: two lines over different infrastructure, a router that shares the load and detects outages, and backup power for the router and modems. With PCC and both-addresses you use the capacity of both lines without upsetting banking sites, and with check-gateway or recursive routing an outage on either line is handled automatically.

If you want us to combine your company's internet lines, see the MikroTik setup and configuration service or get in touch.

Official source: the RouterOS documentation on the MikroTik site, in the Mangle, Policy Routing and Netwatch sections.

  • MikroTik load balancing
  • PCC
  • MikroTik failover
  • dual WAN
  • reliable internet
  • multi-WAN
  • RouterOS 7