1. Diagnosis
You connected a second internet link. Plugged in the cable. Traffic still goes through the first one. Sound familiar?
Two internet links on MikroTik is a task you either solve after a couple of hours of downtime, or after a call from your boss. One ISP goes down, and the office sits without connectivity. The accountant can’t file reports. Sales can’t process orders. You remember that second cable just hanging in the switch, doing nothing.
In this article we’ll set up failover and load balancing. You’ll get a config that keeps the office online 24/7. Setup time: 40 minutes. You need a MikroTik with two free ports and two ISPs. Static IPs aren’t required, DHCP works fine too.
Here’s what’s inside:
- Basic addressing for both WAN links
- Routing marks: splitting traffic by link
- Recursive routing: checking the gateway via 8.8.8.8, not just pinging the local IP
- PCC: load balancing without breaking sessions
- Auto-switch script: if the primary link dies, the backup takes over in 5 seconds
- Firewall: close everything you don’t need open
If you haven’t done the basic MikroTik setup yet, start there. And if you need remote access after setup, check out the WireGuard article.
2. Causes
Why is one internet link a problem? Let’s break it down.
Your ISP goes down during peak hours
Your primary carrier decides to fix a switch in the basement exactly when a client is waiting for an urgent contract. Without a backup, you’re powerless. With a backup, you won’t even notice.
Load on one link maxes out
An office of 30 people, cloud CRM, video calls, Windows updates. A single 100 Mbit link turns into a bottleneck. The second link costs money but sits unused. It’s like buying a spare tire and strapping it to the roof instead of using it.
The router picks one default gateway
MikroTik sees two 0.0.0.0/0 routes. Without routing marks it only uses one. The second stays silent. You think you have two internet links. In reality you have one, plus a cable in the wall.
Failover by distance works intermittently
The standard approach is two routes with different distance values. If the gateway responds to ping but there’s a black hole behind it, MikroTik doesn’t switch. Distance only checks whether a neighbor exists, not whether there’s actual internet access behind it. You need recursive routing.
Load balancing without PCC breaks sessions
Simple packet-based balancing sends your banking app’s requests through the first link, then the second. The bank drops the connection. The accountant calls you with a string of curses. PCC fixes this by pinning a session to one link.
Manual switching requires you, personally
Without a script, you get woken up at 3 AM by a phone call. With a script, MikroTik switches itself and you sleep through it. That’s the difference 25 years of experience makes: it teaches you to automate everything that moves.
3. The recipe
Preparation
Before you touch the terminal, check your environment. Lose access to the router and you’ll be running to the office at night.
| Parameter | Requirement |
|---|---|
| RouterOS version | 7.x (7.18 is current at publication time. Check for newer releases at mikrotik.com before installing) |
| Device | Any MikroTik with two free Ethernet ports |
| WAN 1 | Primary ISP, DHCP or static |
| WAN 2 | Backup ISP, DHCP or static |
| LAN | Internal network, e.g. 192.168.88.0/24 |
| Access | WinBox or WebFig. Don’t do this over SSH from your phone. |
Port layout for our setup:
| Port | Purpose | Protocol | Exposed externally |
|---|---|---|---|
| ether1 | WAN 1: primary ISP | DHCP / PPPoE | Yes |
| ether2 | WAN 2: backup ISP | DHCP / PPPoE | Yes |
| ether3 | LAN: local network | Internal | No |
| 8291 | WinBox | TCP | LAN only (we’ll close it in the firewall) |
| 22 | SSH | TCP | LAN only |
Here’s the network architecture:

Step 1. Reset and basic addressing
If the router already has a messed-up config from a previous admin, reset everything. It’s easier to start clean than to hunt down which route is interfering.
/system reset-configuration no-defaults=yes
After reboot, log in via WinBox. Assign the ports. ether1 becomes WAN1, ether2 becomes WAN2, ether3 becomes LAN.
/interface ethernet set [ find default-name=ether1 ] name=wan1
/interface ethernet set [ find default-name=ether2 ] name=wan2
/interface ethernet set [ find default-name=ether3 ] name=lan
Result: ports renamed. No more confusion about which is which.
Step 2. Configure WAN1 and WAN2
Add a DHCP Client on both WAN interfaces. Set different default-route-distance values. The primary link gets distance 1, the backup gets distance 2.
/ip dhcp-client add interface=wan1 disabled=no add-default-route=yes default-route-distance=1 use-peer-dns=yes use-peer-ntp=yes comment="WAN1-MAIN"
/ip dhcp-client add interface=wan2 disabled=no add-default-route=yes default-route-distance=2 use-peer-dns=yes use-peer-ntp=yes comment="WAN2-BACKUP"
Check that both clients got an IP.
/ip dhcp-client print
/ip address print
Result: wan1 and wan2 both have addresses. The routing table shows two default routes.
Step 3. Configure LAN
Assign an address to LAN and enable the DHCP server for the local network.
/ip address add address=192.168.88.1/24 interface=lan comment="LAN"
/ip pool add name=lan-pool ranges=192.168.88.10-192.168.88.254
/ip dhcp-server network add address=192.168.88.0/24 gateway=192.168.88.1 dns-server=8.8.8.8,1.1.1.1
/ip dhcp-server add name=lan-dhcp interface=lan address-pool=lan-pool disabled=no
Result: LAN clients get addresses from the pool. DNS is Google and Cloudflare, so you don’t depend on a single ISP.
Step 4. NAT for both links
Without masquerade, packets leave with a private address and the ISP drops them. Add src-nat on both WAN interfaces.
/ip firewall nat add chain=srcnat out-interface=wan1 action=masquerade comment="NAT-WAN1"
/ip firewall nat add chain=srcnat out-interface=wan2 action=masquerade comment="NAT-WAN2"
Result: any packet from LAN gets a public IP when leaving through either WAN.
Step 5. Routing marks: splitting traffic by link
This is where the magic starts. Without routing marks, MikroTik has no idea which packet should go where. We’ll mark connections and packets.
First, create routing tables. One for WAN1, one for WAN2.
/routing table add name=to-wan1 fib
/routing table add name=to-wan2 fib
Now mark connections in mangle. PCC runs at the prerouting stage.
/ip firewall mangle add chain=prerouting in-interface=lan connection-mark=no-mark action=mark-connection new-connection-mark=wan1_conn passthrough=yes per-connection-classifier=both-addresses:2/0 comment="PCC-WAN1"
/ip firewall mangle add chain=prerouting in-interface=lan connection-mark=no-mark action=mark-connection new-connection-mark=wan2_conn passthrough=yes per-connection-classifier=both-addresses:2/1 comment="PCC-WAN2"
PCC essentially splits connections into two streams. both-addresses means classification is based on the src-dst pair. One user’s session stays on one link. Your banking app won’t break.
Now mark packets for each connection.
/ip firewall mangle add chain=prerouting connection-mark=wan1_conn action=mark-routing new-routing-mark=to-wan1 passthrough=yes comment="ROUTE-WAN1"
/ip firewall mangle add chain=prerouting connection-mark=wan2_conn action=mark-routing new-routing-mark=to-wan2 passthrough=yes comment="ROUTE-WAN2"
Result: every new connection from LAN gets a mark. That connection’s packets go into its own routing table.
Step 6. Recursive routing: checking the gateway via 8.8.8.8
Distance only checks whether the gateway responds to ARP. But the gateway can be alive while the internet behind it is dead. Recursive routing checks whether a remote host is reachable through a specific gateway.
First, add static routes to the check hosts through each WAN. Use scope 10 so they don’t land in the main table directly.
/ip route add dst-address=8.8.8.8/32 gateway=wan1 scope=10 target-scope=14 check-gateway=ping comment="CHECK-WAN1"
/ip route add dst-address=1.1.1.1/32 gateway=wan2 scope=10 target-scope=14 check-gateway=ping comment="CHECK-WAN2"
Now add default routes through these check hosts. This is recursive routing. If 8.8.8.8 doesn’t respond through wan1, the route becomes unreachable.
/ip route add dst-address=0.0.0.0/0 gateway=8.8.8.8 routing-table=to-wan1 distance=1 check-gateway=ping comment="DEFAULT-WAN1-RECURSIVE"
/ip route add dst-address=0.0.0.0/0 gateway=1.1.1.1 routing-table=to-wan2 distance=2 check-gateway=ping comment="DEFAULT-WAN2-RECURSIVE"
Important detail: check-gateway=ping sends ICMP every 10 seconds. If three packets in a row fail, the route goes down. MikroTik shifts traffic to the second link.
Result: the route stays active only when the internet behind that gateway is actually reachable. Checks run against 8.8.8.8 and 1.1.1.1.
Step 7. Add plain default routes as a fallback
If recursive routing breaks for some reason, you need a fallback. Add regular routes with a higher distance.
/ip route add dst-address=0.0.0.0/0 gateway=wan1 distance=10 comment="FALLBACK-WAN1"
/ip route add dst-address=0.0.0.0/0 gateway=wan2 distance=20 comment="FALLBACK-WAN2"
Result: if the recursive routes fail, traffic falls back to the plain routes. Not ideal, but better than total outage.
Step 8. PCC balancing details
PCC works like this. It takes src-address and dst-address, hashes them, and divides by the number of links. The remainder determines which link the connection goes through.
Our rules are already created in step 5. But if you need to exclude some traffic from balancing, add an accept rule above them.
For example, traffic to the bank should always go through WAN1.
/ip firewall mangle add chain=prerouting dst-address=195.XXX.XXX.0/24 action=accept comment="BANK-THROUGH-WAN1"
The accept rule must sit above the PCC rules. Order matters in mangle.
Result: excluded traffic doesn’t get a connection-mark from PCC and goes through the main routing table.
Step 9. Auto-switch script when the primary link fails
Recursive routing switches routes. But sometimes you need to physically disable an interface or change the distance. Let’s write a script that pings 8.8.8.8 through WAN1. If the ping stops, it disables the WAN1 route and logs a warning.
/system script add name=failover-check source={
:local pingCount 3;
:local wan1Gateway [/ip dhcp-client get [find interface=wan1] gateway];
:if ([:len $wan1Gateway] = 0) do={
:set wan1Gateway "0.0.0.0";
}
:local pingResult [/ping 8.8.8.8 count=$pingCount interface=wan1];
:if ($pingResult = 0) do={
/ip route set [find comment="DEFAULT-WAN1-RECURSIVE"] disabled=yes;
/log warning "WAN1 FAILED: switched to WAN2";
} else={
/ip route set [find comment="DEFAULT-WAN1-RECURSIVE"] disabled=no;
/log info "WAN1 OK: primary route restored";
}
}
Now attach the script to the scheduler. Let it check every 10 seconds.
/system scheduler add name=failover interval=10s on-event="/system script run failover-check" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon comment="Auto-failover check"
Result: every 10 seconds MikroTik checks WAN1. If three pings in a row fail, the primary route is disabled. Traffic instantly moves to WAN2.
Step 10. Firewall: close everything unnecessary
Two WAN links mean two holes to the internet. Let’s block external access to the router and protect the LAN.
/ip firewall filter add chain=input action=drop in-interface=wan1 comment="DROP-WAN1-INPUT"
/ip firewall filter add chain=input action=drop in-interface=wan2 comment="DROP-WAN2-INPUT"
/ip firewall filter add chain=input action=accept connection-state=established,related comment="ALLOW-ESTABLISHED"
/ip firewall filter add chain=input action=accept in-interface=lan comment="ALLOW-LAN"
/ip firewall filter add chain=input action=drop comment="DROP-ALL-OTHER"
If you need WinBox access from outside through one of the WANs, forward the port or set up WireGuard. Don’t expose WinBox directly to the internet. That’s like leaving your keys under the doormat.
Add protection against SSH brute force.
/ip firewall filter add chain=input protocol=tcp dst-port=22 src-address-list=ssh_blacklist action=drop comment="DROP-BLACKLIST-SSH"
/ip firewall filter add chain=input protocol=tcp dst-port=22 connection-state=new recent-add name=ssh_blacklist comment="ADD-TO-BLACKLIST"
Result: the router doesn’t respond to incoming traffic from the internet, except for established connections. LAN works without restrictions.
Step 11. A separate user for management
Don’t work under admin. Create a limited-privilege user for daily tasks and a separate one for configuration.
/user group add name=read-only policy=read,test,winbox,web,api
/user add name=operator group=read-only password=YourStrongPassword123 comment="Daily operator"
/user add name=admin-sre group=full password=AnotherStrongPass comment="Full admin"
/user disable admin
Result: the default admin account is disabled. Access is split by role.
4. Verification
Set it up? Verify everything works before you report success to anyone.
Check routes
/ip route print
Make sure DEFAULT-WAN1-RECURSIVE is active. FALLBACK-WAN2 should be inactive.
Check marking
/ip firewall mangle print stats
Counters for PCC-WAN1 and PCC-WAN2 should grow as LAN traffic flows.
Check ping through each link
/tool ping 8.8.8.8 interface=wan1 count=5
/tool ping 8.8.8.8 interface=wan2 count=5
Both should succeed. If one fails, check the DHCP lease and cable.
Check load balancing
Start a torrent or download from two different computers. Watch Tools → Traffic Monitor. Load should distribute between WAN1 and WAN2.
Check failover
Unplug the WAN1 cable. Wait 15 seconds. Ping 8.8.8.8 from a LAN computer. You shouldn’t lose any packets. The log will show a WAN1 FAILED entry.
/log print where topics~"failover"
Plug the cable back in. Within 10 to 20 seconds the route recovers.
Check speed
/tool bandwidth-test address=speedtest.tele2.net protocol=tcp direction=both user=password=
Run the test through WAN1, then through WAN2. Combined throughput under PCC should come close to the sum of both links across multiple TCP connections.
5. Complications
What breaks most often and how to fix it.
Error: internet completely gone after marking
Cause: the routing mark sends packets to the to-wan1 table, but there’s no default route in it. Or NAT didn’t trigger because the out-interface in the nat rule doesn’t match the real one.
Fix: check that the to-wan1 table has a default route. Check NAT.
/ip route print table=to-wan1
/ip firewall nat print
Error: PCC breaks your banking app and 1C
Cause: the banking app’s session starts through WAN1, but the next packet goes out via WAN2. The bank drops the connection when the IP changes.
Fix: add an accept rule for the bank’s IP above the PCC rules. Or apply PCC only to specific ports, excluding 443 for certain destinations.
/ip firewall mangle add chain=prerouting dst-address=194.54.14.0/24 action=accept place-before=0 comment="BANK-EXCLUDE-PCC"
Error: recursive routing shows unreachable
Cause: the ISP’s gateway doesn’t forward pings to 8.8.8.8. Or the ISP filters ICMP. Or the target-scope on the route to 8.8.8.8 doesn’t match the gateway’s scope.
Fix: ping manually.
/ping 8.8.8.8 interface=wan1
If it doesn’t respond, switch the check host to the ISP’s own IP. Or make sure target-scope is greater than the gateway’s scope.
Error: the failover script doesn’t disable the route
Cause: the script resolves the gateway incorrectly. Or the script runs without write permission.
Fix: run it manually.
/system script run failover-check
Check the log. If the gateway is empty, hardcode it in the script instead of relying on auto-detection.
Error: gateway pings fine, but there’s no internet
Cause: the ISP handed out an address, but their upstream is down. The gateway is locally reachable but has no path out to the world.
Fix: this is exactly why we use recursive routing. If you only set distance without recursive routing, nothing switches. Double-check your step 6 config.
Error: speed is low after switching to WAN2
Cause: WAN2 is genuinely slower. Or WAN2 runs PPPoE with an MTU of 1480, and packets get fragmented.
Fix: check MTU on both interfaces.
/interface print detail where name~"wan"
Set matching MTU values. Enable clamp-tcp-mss in the firewall.
/ip firewall mangle add chain=forward protocol=tcp tcp-flags=syn action=change-mss new-mss=clamp-to-pmtu comment="CLAMP-MSS"
6. Alternatives
There are other approaches. Briefly, here’s why we didn’t go with them.
VRRP instead of a script
VRRP works if you have two routers. One fails, the other takes over the virtual IP. But we have one router with two WAN links. VRRP doesn’t apply here. It solves router failure, not link failure.
BGP with two ISPs
BGP is elegant. Automatic balancing, automatic failover, your own AS announcement. But both ISPs need to support BGP. For a 30-person office this is overkill. Setup takes a day. PCC plus recursive routing gets the job done in 40 minutes.
Plain distance, no recursive routing
Two default routes with distance 1 and 2. This works if the gateway dies physically. But if the gateway is alive and the internet behind it is dead, the router won’t switch. We’ve seen this happen at 3 AM. Don’t repeat it.
Balancing via ECMP
Equal Cost Multi Path: just two routes with the same distance. MikroTik balances per-packet. But sessions break, guaranteed. Banking apps, VoIP, VPN, all of it falls apart. PCC solves this through per-connection classification.
Policy routing over WireGuard
You can tunnel all traffic through WireGuard and route inside the tunnel. But that adds a point of failure: the WireGuard server itself. For a local office, working with ISPs directly is simpler.
7. Maintenance
Setting it up doesn’t mean you’re done. Keep the config in shape.
Monitoring
Set up The Dude or Zabbix. Track:
- Ping to 8.8.8.8 through each WAN
- Status of the wan1 and wan2 interfaces
- Number of active default routes
- CPU load under PCC
A trigger for missing default routes is critical. A 3 AM phone call should be the last resort, not the first line of defense.
Config backup
Export the config after every change.
/export file=backup-mikrotik-failover
Store the backup on an external server. MikroTik can send it over FTP or email.
/tool e-mail set address=smtp.yandex.ru port=587 user=backup@yourdomain.com password=YourPass
/tool fetch url="ftp://backup.server.com/mikrotik-backup.rsc" upload=yes src-path=backup-mikrotik-failover.rsc
What to back up: full /export, the .backup file, the list of scripts and scheduler jobs. How often: after every change, plus a weekly automated run. Where to store: external FTP and a local flash drive on the router.
Script auto-start
The scheduler is already set up in step 9. But check it stays enabled after a reboot.
/system scheduler print
Status should be enabled. Set start-time to startup if you want it to fire right after boot.
Logging switchovers
Set up remote logging to a syslog server. When a link goes down, you’ll see the exact time and duration of the outage.
/system logging action add name=remote target=remote remote=192.168.88.10 remote-port=514
/system logging add topics=critical action=remote
/system logging add topics=warning action=remote
RouterOS updates
Check for new versions quarterly. Test updates on a spare device first. In production, stick to the Long-term branch.
/system package update check-for-updates
/system package update download
/system reboot
What to check before updating: config export, a current backup, script compatibility. How to roll back: load the previous version via Netinstall, or restore it from the Files section.
8. FAQ
Why doesn’t failover work after setup?
Check three things. First, routing marks are present and traffic actually falls under PCC. Second, the recursive routes are active. Third, the firewall doesn’t block ICMP from the router to 8.8.8.8. If the ISP’s gateway filters ICMP, switch the check IP to the ISP’s own DNS server.
How do I check that balancing works correctly?
Start a download from two different computers. Open Tools → Traffic Monitor in WinBox. Load on wan1 and wan2 should be roughly even. If one link is at 90% and the other at 10%, check the PCC classifier. both-addresses might not fit your traffic pattern, try src-address for more even distribution.
What do I do if PCC breaks my banking app?
Add an accept rule in mangle for the bank’s IP, above the PCC rules. Or apply PCC only to specific ports, keeping 443 pinned to one channel for banking traffic. Alternative: tag banking traffic with a separate routing mark and route it only through WAN1.
How does recursive routing differ from plain distance?
Distance only checks whether the gateway responds to ARP or ICMP. Recursive routing checks whether a remote host is reachable through a specific gateway. If the gateway is alive but there’s an outage further up the ISP’s backbone, distance alone won’t switch. Recursive routing disables the route and sends traffic through the backup.
Can I use three WAN links?
Yes. Increase the denominator in PCC: both-addresses:3/0, 3/1, 3/2. Add a third routing table. Recursive routing scales the same way, just add another checked route. The main constraint is router CPU. A hEX S handles three WAN links under PCC comfortably. An older RB2011 might lag.
How do I force specific sites to always use WAN1?
Create an address-list with those sites’ IPs. Add a mangle rule that marks connections to that list with routing mark to-wan1. Place the rule above the PCC rules.
/ip firewall address-list add list=force-wan1 address=194.54.14.0/24 comment="BANK-IP"
/ip firewall mangle add chain=prerouting dst-address-list=force-wan1 action=mark-routing new-routing-mark=to-wan1 passthrough=no place-before=0 comment="FORCE-WAN1"
9. What to expect
You’ve set up two internet links on MikroTik with failover and load balancing. Routing marks split traffic. Recursive routing checks gateways via 8.8.8.8. PCC distributes load across both links. A scheduled script switches routes in 5 seconds if the primary ISP drops.
The office no longer notices when one link goes down. The accountant files reports on time. Managers run video calls without a hitch. You sleep through the night instead of driving to the office to fix the internet.
If it didn’t work, leave a comment and we’ll sort it out. Attach the output of /export hide-sensitive. Without that, diagnosis turns into guesswork.
And if you want remote access to this MikroTik from home, set up WireGuard. It’s safer than port forwarding and works over any WAN link.
Оставайтесь на связи
Рецепты от IT-боли. Без воды, без рекламы, без маркетинговой шелухи.
Подписаться на IT-Аптеку →



