MikroTik Load Balancing: Dual WAN and Failover Management
MikroTik load balancing configuration with the PCC, ECMP and Nth methods. Adding failover, DNS problems and testing methods. ISP customer scenario: fiber + backup VDSL.
MikroTik load balancing configuration with the PCC, ECMP and Nth methods. Adding failover, DNS problems and testing methods. ISP customer scenario: fiber + backup VDSL.
İçindekiler▾
- Failover or Load Balance?
- Scenario
- Method 1: PCC (Per Connection Classifier), the recommended method
- Step 1: Interface Lists
- Step 2: IP Addresses (DHCP or static)
- Step 3: Mangle Rules (PCC)
- Step 4: Policy Route
- Step 5: NAT
- Method 2: ECMP
- Method 3: Nth
- Adding Failover
- Line Monitoring with Netwatch
- DNS Problems
- DNS Leak
- Sticky Connection (Banks, E-government)
- Testing and Verification
- Traffic Monitoring with Torch
- Routing Table Check
- Line-Cut Test
- Bandwidth Test
- Common Mistakes
- “One line went down and all connections dropped”
- “The VoIP connection dropped but the line is working”
- “The PCC rules are not working”
- Capacity Calculation
You have two internet lines: one fiber, one backup VDSL. Under normal conditions you only use the fiber, and the backup sits idle. With load balancing you use both lines actively, and when one goes down you switch to the other automatically. When it is not done correctly, though, banking logins get cut off, VoIP starts acting up, and asymmetric routing becomes a headache.
Failover or Load Balance?
| Feature | Failover | Load Balance |
|---|---|---|
| Line usage | Active line only | Both lines |
| Bandwidth gain | ❌ | ✅ |
| Load distribution | ❌ | ✅ |
| High availability | ✅ | ✅ (if failover is added) |
| Complexity | Low | Medium-High |
| Asymmetric routing risk | Low | Must be managed |
Scenario
- WAN1: ether1, Fiber 100 Mbps (primary line)
- WAN2: ether2, VDSL 25 Mbps (backup/additional line)
- LAN: bridge-lan, 192.168.88.0/24
- Goal: Both together in normal operation, full switchover to the other when one goes down
Method 1: PCC (Per Connection Classifier), the recommended method
PCC assigns each connection to a specific line by computing a hash. It uses the same line for the duration of a session, so there is no asymmetric routing problem.
Step 1: Interface Lists
/interface list
add name=WAN
add name=LAN
/interface list member
add interface=ether1 list=WAN comment="WAN1: Fiber"
add interface=ether2 list=WAN comment="WAN2: VDSL"
add interface=bridge-lan list=LAN
Step 2: IP Addresses (DHCP or static)
# Fiber line (example)
/ip address add address=83.45.12.10/30 interface=ether1 comment="WAN1 IP"
/ip route add gateway=83.45.12.9 distance=1 comment="WAN1 GW"
# VDSL line
/ip address add address=176.89.21.100/30 interface=ether2 comment="WAN2 IP"
/ip route add gateway=176.89.21.97 distance=2 comment="WAN2 GW (backup)"
Step 3: Mangle Rules (PCC)
/ip firewall mangle
# Established/related connections: use the line they came in on
add chain=prerouting action=accept connection-state=established,related \
in-interface=ether1 comment="WAN1 established: mark inherit"
add chain=prerouting action=accept connection-state=established,related \
in-interface=ether2 comment="WAN2 established: mark inherit"
# Distribute new connections across the two lines (with PCC)
# per-connection-classifier: src-dst-address, source+destination IP hash
add chain=prerouting action=mark-connection new-connection-mark=conn-wan1 \
in-interface=bridge-lan \
per-connection-classifier=both-addresses:2/0 \
passthrough=yes comment="PCC: connections falling into the WAN1 group"
add chain=prerouting action=mark-connection new-connection-mark=conn-wan2 \
in-interface=bridge-lan \
per-connection-classifier=both-addresses:2/1 \
passthrough=yes comment="PCC: connections falling into the WAN2 group"
# Connection mark -> route mark
add chain=prerouting action=mark-routing new-routing-mark=route-wan1 \
connection-mark=conn-wan1 in-interface=bridge-lan \
passthrough=no
add chain=prerouting action=mark-routing new-routing-mark=route-wan2 \
connection-mark=conn-wan2 in-interface=bridge-lan \
passthrough=no
Step 4: Policy Route
/ip route
add gateway=83.45.12.9 routing-table=route-wan1 comment="WAN1 policy route"
add gateway=176.89.21.97 routing-table=route-wan2 comment="WAN2 policy route"
Step 5: NAT
/ip firewall nat
add chain=srcnat action=masquerade out-interface=ether1 comment="NAT WAN1"
add chain=srcnat action=masquerade out-interface=ether2 comment="NAT WAN2"
Method 2: ECMP
ECMP (Equal-Cost Multi-Path) adds multiple equal-cost routes to the routing table. RouterOS distributes packets in round-robin fashion.
/ip route
add gateway=83.45.12.9 distance=1 comment="WAN1: ECMP"
add gateway=176.89.21.97 distance=1 comment="WAN2: ECMP (same distance)"
Drawback: Sessions can land on different lines. Sites that check the IP, such as banking or e-government portals, may drop the session.
Method 3: Nth
Packet-based round-robin. Every N packets are sent to one line:
/ip firewall mangle
add chain=prerouting action=mark-connection new-connection-mark=conn-wan1 \
nth=2,1 in-interface=bridge-lan passthrough=yes
add chain=prerouting action=mark-connection new-connection-mark=conn-wan2 \
nth=2,2 in-interface=bridge-lan passthrough=yes
| Method | Session Persistence | Distribution Accuracy | Complexity |
|---|---|---|---|
| PCC | ✅ Excellent | ✅ Good | Medium |
| ECMP | ❌ None | ✅ Good | Low |
| Nth | ⚠️ Weak | ⚠️ Packet-based | Low |
Adding Failover
Add failover to the load balance configuration so that when one line goes down, traffic moves to the other:
Line Monitoring with Netwatch
/tool netwatch
# WAN1 check: ping Google DNS
add host=8.8.8.8 interval=30s timeout=5s \
up-script="
/ip route set [find comment=\"WAN1 GW\"] distance=1
/ip firewall mangle set [find comment=\"PCC: connections falling into the WAN1 group\"] disabled=no
:log info \"WAN1 UP: normal routing\"" \
down-script="
/ip route set [find comment=\"WAN1 GW\"] distance=3
/ip firewall mangle set [find comment=\"PCC: connections falling into the WAN1 group\"] disabled=yes
:log warning \"WAN1 DOWN: switched to WAN2\""
# WAN2 check
add host=8.8.4.4 interval=30s timeout=5s \
up-script="
/ip route set [find comment=\"WAN2 GW\"] distance=2
:log info \"WAN2 UP\"" \
down-script="
/ip route set [find comment=\"WAN2 GW\"] distance=4
:log warning \"WAN2 DOWN\""
Caution: Specify which line Netwatch sends its ping from; otherwise it may send the ping over the wrong line, for example over the secondary line.
/tool netwatch
set [find host=8.8.8.8] src-address=83.45.12.10 # WAN1 IP
set [find host=8.8.4.4] src-address=176.89.21.100 # WAN2 IP
DNS Problems
DNS Leak
While traffic is sent over one line, the DNS query can go out over the other. Solution: a separate DNS per line:
/ip dns
set servers=8.8.8.8,1.1.1.1 allow-remote-requests=yes
# Or use the ISP DNS servers:
# WAN1 ISP: 212.156.24.200
# WAN2 ISP: 88.255.5.5
Sticky Connection (Banks, E-government)
Some sites prevent the source IP from changing. Solution: always use the same line for these sites’ IPs:
/ip firewall address-list
add address=204.152.184.0/23 list=sticky-wan1 comment="Visa/Mastercard"
add address=193.255.0.0/16 list=sticky-wan1 comment="Turkish banking"
/ip firewall mangle
add chain=prerouting action=mark-routing new-routing-mark=route-wan1 \
dst-address-list=sticky-wan1 in-interface=bridge-lan passthrough=no \
comment="Banking: always WAN1"
Testing and Verification
Traffic Monitoring with Torch
# Real-time traffic over WAN1
/tool torch interface=ether1
Check whether traffic flows over WAN1 and WAN2 in equal proportions.
Routing Table Check
/ip route print
# Are both gateways active and are the distance values correct?
# Policy route tables
/ip route print routing-table=route-wan1
/ip route print routing-table=route-wan2
Line-Cut Test
- Pull the WAN1 cable
- Watch the Netwatch log: the message
WAN1 DOWN: switched to WAN2should appear - Check that internet access continues
- Plug the cable back in: the message
WAN1 UP: normal routingshould appear - Check that both lines are active again
# Log monitoring
/log print follow where topics~"netwatch"
Bandwidth Test
With two lines up, does the total bandwidth increase?
# Measure each line's usage with Zabbix or Torch
/tool bandwidth-test address=8.8.8.8 direction=download
Common Mistakes
“One line went down and all connections dropped”
The route table was not cleaned up, or the mangle rules were not updated. The Netwatch down-script must raise the distance high enough:
# distance=3 may not be enough, use 10
/ip route set [find comment="WAN1 GW"] distance=10
“The VoIP connection dropped but the line is working”
If a VoIP session is marked on a different line and that line goes down, the session drops. Solution: always pin VoIP traffic to a single line:
/ip firewall mangle
add chain=prerouting action=mark-routing new-routing-mark=route-wan1 \
protocol=udp dst-port=5060,10000-20000 in-interface=bridge-lan \
comment="VoIP: always WAN1"
“The PCC rules are not working”
Verify that the mangle rules are checking connection-state=new. Established connections must go through a different chain:
/ip firewall mangle print
# Are the established/related rules before the PCC rules?
Capacity Calculation
| Scenario | Total Capacity | Practical Note |
|---|---|---|
| Fiber 100 + VDSL 25 | ~125 Mbps | PCC does not produce a balanced split |
| 2x Fiber 100 | ~200 Mbps | Balanced with PCC |
| 2x Fiber 100 + failover | 200 Mbps, redundant | Optimal setup |
On two lines of different speeds, PCC can be tuned to use the slower line less:
# 75/25 split: WAN1 3 units, WAN2 1 unit
# per-connection-classifier=both-addresses:4/0 -> WAN1 (0,1,2)
# per-connection-classifier=both-addresses:4/3 -> WAN2 (3)
Practical tip: Test the load balancing configuration in a lab environment before trying it on a live network. If the rule order is wrong, it is possible to cut off all internet access. Work with safe mode enabled or keep console access open.
Kaynaklar
- PCC (Per Connection Classifier) pins connections to a specific WAN — MikroTik RouterOS Documentation, PCC (2025)
- The hourly cost of an internet outage to SMBs averages 8,000-74,000 dollars — Gartner Downtime Cost Analysis (2023)
- Dual-WAN failover can reduce unplanned downtime by 95% — Fortinet SD-WAN Report (2024)
Sıkça Sorulan Sorular
Can load balancing and failover be used at the same time on MikroTik?+
Yes. The PCC + Netwatch combination provides exactly this. In normal operation traffic is distributed across the two lines. When one line goes down, Netwatch is triggered, the mangle and route rules are updated, and all traffic shifts to the working line.
Should I choose PCC or ECMP?+
PCC 'sticks' each connection to a specific line and uses the same line for the duration of a session. ECMP does round-robin, so sessions can be spread across different lines (which can cause problems with banks' security systems). For general use PCC is the safer choice.
Why does asymmetric routing cause problems?+
If a request goes out over one line and the reply comes back over another, it can break the firewall's connection tracking and the connection drops. PCC prevents this: the outbound and return traffic of the same session travel over the same line.
Does using two lines at the same time violate the ISP contract?+
Generally no; you are taking lines from two different ISPs and using each for its own traffic. But some ISP contracts may include restrictions on NAT or connection sharing. Checking is good practice.
Profesyonel Destek mi Lazım?
Bu konuda yardıma ihtiyacın varsa yanındayız. Kurulum, konfigürasyon ve sorun giderme için ulaş.
