
MikroTik, part 4: two providers, automatic switching, and monitoring
🌐 Machine-translated from Russian. Show original
In this part:
Why choose a second provider#
If the office has a cash register, 1C over the internet, IP telephony, or cloud services, a break in one channel stops working. The second provider (another operator, another physical channel — for example, fiber + mobile internet) solves the problem.
Simple option: distance and check-gateway#
/ip route add dst-address=0.0.0.0/0 gateway=IP_шлюза_ISP1 distance=1 check-gateway=ping
/ip route add dst-address=0.0.0.0/0 gateway=IP_шлюза_ISP2 distance=2 check-gateway=ping
NAT — for both interfaces (both in the WAN list, masquerade rule from part 1.
Limitation: the check-gateway only checks the availability of the provider's gateway. If the gateway responds but there is no further internet — no switching will occur.
Reliable option: recursive routes#
We check the availability of an external address through a specific provider:
/ip route add dst-address=1.1.1.1/32 gateway=IP_шлюза_ISP1 scope=10
/ip route add dst-address=8.8.8.8/32 gateway=IP_шлюза_ISP2 scope=10
/ip route add dst-address=0.0.0.0/0 gateway=1.1.1.1 distance=1 check-gateway=ping target-scope=11
/ip route add dst-address=0.0.0.0/0 gateway=8.8.8.8 distance=2 check-gateway=ping target-scope=11
If 1.1.1.1 stops responding via ISP1, the main route becomes inactive and traffic leaves ISP2. Use different addresses for different providers to check.
Notifications: netwatch#
/tool netwatch add host=1.1.1.1 interval=30s \
down-script="/log warning \"ISP1 down\"" up-script="/log info \"ISP1 up\""
In scripts, you can send notifications to Telegram or e-mail — then you will learn about the problem from the provider before the users do. It's better to include routers in the overall monitoring system (the infrastructure series).
What to consider#
- Requested ports work through the provider whose IP the request came to; for correct responses on two active channels, connection marking (mangle) is required — this is an advanced setup.
- VPN between offices when switching providers: use the domain name (DDNS,
/ip cloud) instead of IP at the branch endpoint. - Mobile backup: monitor traffic and cost.
Configuration backups#
- Regular
/exportto a text file and storage outside the router (git, backup server). - Before every significant change —
/system backup save. - Documentation: network diagram, addressing, VLAN, VPN peer list.
🎉 Series completed. Return to contents.
Comments · 0
No comments yet.Sign in to comment, rate and see all comments.