Networks

Backup internet for the office: two ISPs and automatic failover on MikroTik

How to set up a second internet connection so the office switches to it automatically and back again when the main provider recovers. Recursive routing on MikroTik, reachability checks and the pitfalls.

Alexei Sergeev 3 min read

When an office loses internet today, almost everything stops: cloud accounting, CRM, telephony, email. Meanwhile, a second connection from another provider usually costs noticeably less than an hour of the whole company standing idle. But a second cable in the rack solves nothing on its own: the switchover has to happen automatically and correctly.

Why checking the gateway is not enough

The simplest option is two default routes with different distances and check-gateway=ping. The problem is that this only checks whether the provider's nearest gateway is reachable. A common situation: the gateway responds, but the internet beyond it does not work because the outage is deeper in the provider's network. The router considers the link healthy, and the office stays offline.

It is better to check the reachability of something beyond the provider, such as a public DNS server, and to do it through a specific link. RouterOS uses recursive routing for this.

Recursive routes: configuration

The idea: a route to a chosen external address (a different one for each provider) is set strictly via that provider's gateway. The default route then points not at the gateway but at that external address. If the address stops answering ping, the default route becomes inactive and traffic moves to the backup link.

failover.rsc
# gateway addresses are documentation examples (203.0.113.1 and 198.51.100.1); use your own
/ip route
add dst-address=8.8.8.8/32 gateway=203.0.113.1 scope=10 comment="ISP1 check"
add dst-address=1.1.1.1/32 gateway=198.51.100.1 scope=10 comment="ISP2 check"

add dst-address=0.0.0.0/0 gateway=8.8.8.8 target-scope=11 check-gateway=ping distance=1 comment="ISP1 primary"
add dst-address=0.0.0.0/0 gateway=1.1.1.1 target-scope=11 check-gateway=ping distance=2 comment="ISP2 backup"

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

What else to consider

Returning to the main link

With this setup, the return happens on its own: as soon as the check address answers through the first provider again, the route with the lower distance becomes active. Connections that are already open will keep using the backup link for a while, which is normal.

Inbound connections and VPN

If people connect to the office from outside (VPN for remote staff, access to a server), you need to plan which address they connect to and how replies go back through the same link the request came in on. This is solved with connection marking (mangle) and separate routing tables, a topic for a separate article. For a site-to-site VPN, it is convenient to build tunnels over both links.

A metered backup link

If the backup is an LTE modem with limited traffic, it is worth limiting what goes through it: for example, allow only work services and block operating system updates and cloud sync of large files.

How to check that it works

Setting up failover is half the job. The other half is testing it under controlled conditions, not during a real outage. Here is what I do:

  1. Unplug the main provider's cable and time how long a test computer loses and regains connectivity.
  2. Simulate the gateway-up-but-no-internet case: block ping to the check address on the router and make sure the route becomes inactive.
  3. Check that telephony and VPN work, since they are the most sensitive to a switchover.
  4. Set up a notification on switchover: the office should not run on the backup link for months without knowing it.

Link redundancy is one of the tasks within network infrastructure work. If the infrastructure is maintained on an ongoing basis, it makes sense to include failover testing in scheduled maintenance.

Want your office not to depend on a single provider?

Tell me which links you have now and what is critical for your work. I will propose a redundancy scheme and test it before handover.

Discuss your task

Alexei SergeevEngineer, IT infrastructure and DevOps

Read next

Office network segmentation on MikroTik: VLANs for staff, guests and servers

Why a flat network where every device sees every other one is the main source of trouble in a small office, and how to split it into VLANs on MikroTik with RouterOS 7: the layout, bridge configuration, firewall rules an…

Site-to-site VPN on MikroTik: WireGuard for branch offices and remote staff

How to connect two offices and remote employees with WireGuard on MikroTik running RouterOS 7: the addressing plan, tunnel and route configuration, firewall rules and what to test before handover.

Corporate Wi-Fi: why office coverage is poor and how to fix it

Dead zones, drops when walking between rooms and slowness in the meeting room: I go through the common causes of office Wi-Fi problems and how I design a wireless network so that it works reliably.