Tutorial 3 min read

MikroTik Static Routing Mastery: Distance, Scope, Recursive Routes & Failover

Static routing on MikroTik goes far beyond "add a gateway." Distance for failover, check-gateway for health monitoring, scope/target-scope for recursive routes, routing marks for policy routing, and VRF for multi-tenant isolation. This guide covers every static routing feature.

MI
MikroRadius Team
MikroRadius Engineering Team

Every MikroTik admin adds a default route on day one. But static routing goes much deeper – it's the foundation for failover, policy routing, VRF, and even complex architectures where dynamic protocols aren't justified. This guide covers every aspect of MikroTik static routing.

Static Route Basics

/ip route add dst-address=0.0.0.0/0 gateway=192.168.1.1 comment="Default route"

This sends all traffic to 192.168.1.1 (your ISP gateway). Simple. But let's go deeper.

Route Properties

PropertyDescriptionDefault
dst-addressDestination networkRequired
gatewayNext-hop IP or interfaceRequired
distanceAdministrative distance (priority)1
check-gatewayHealth check method (ping/arp)none
scopeScope of the route30
target-scopeScope of the gateway lookup10
routing-tableRouting table (for policy routing)main
pref-srcPreferred source IP for outgoingauto
vrf-interfaceVRF membershipnone

Distance (Administrative Distance)

The distance determines route priority. Lower distance = preferred route. When two routes exist for the same destination, the one with lower distance wins.

# Primary WAN (distance 1 – preferred)
/ip route add dst-address=0.0.0.0/0 gateway=203.0.113.1 distance=1 comment="Primary WAN"

# Backup WAN (distance 2 – used when primary fails)
/ip route add dst-address=0.0.0.0/0 gateway=198.51.100.1 distance=2 comment="Backup WAN"

Normally, all traffic goes through the primary (distance 1). If the primary gateway goes down AND check-gateway is enabled, the route is deactivated and the backup (distance 2) takes over.

Check-Gateway (Health Monitoring)

/ip route add dst-address=0.0.0.0/0 gateway=203.0.113.1 distance=1 check-gateway=ping comment="Primary with health check"
/ip route add dst-address=0.0.0.0/0 gateway=198.51.100.1 distance=2 comment="Backup"
  • check-gateway=ping – Periodically pings the gateway. If the ping fails, the route is marked as unreachable.
  • check-gateway=arp – Uses ARP to check if the gateway is reachable at Layer 2. Faster but only works if the gateway is directly connected.

This is the simplest WAN failover mechanism. See our dual-WAN guide for advanced failover with PCC.

Recursive Routes

A recursive route resolves the gateway through another route, not a directly connected interface. This is powerful for detecting upstream failures.

The Problem with check-gateway

check-gateway only checks if the directly connected gateway is alive. If your ISP gateway (192.168.1.1) is up but the ISP backbone is down, check-gateway still shows the route as active – even though internet is unreachable.

The Solution: Recursive Routing

# Check if we can reach 8.8.8.8 (Google DNS)
/ip route add dst-address=8.8.8.8/32 gateway=203.0.113.1 scope=10 comment="Health check target"

# Default route through 8.8.8.8 (recursive)
/ip route add dst-address=0.0.0.0/0 gateway=8.8.8.8 distance=1 target-scope=11 check-gateway=ping comment="Primary (recursive)"

# Backup
/ip route add dst-address=8.8.8.8/32 gateway=198.51.100.1 scope=10 comment="Backup health target"
/ip route add dst-address=0.0.0.0/0 gateway=8.8.4.4 distance=2 target-scope=11 check-gateway=ping comment="Backup (recursive)"

Now the default route is only active if 8.8.8.8 is actually reachable – not just if the local gateway responds. If the ISP backbone fails, the route deactivates and the backup WAN takes over.

Scope and Target-Scope

  • scope – How "visible" this route is to other routes looking for a gateway.
  • target-scope – The maximum scope value the gateway lookup will search in.
  • A recursive route resolves its gateway by looking for routes with scope <= its target-scope.

Default scopes: connected routes = 10, static routes = 30, OSPF = 20-110, BGP = 40.

Policy Routing (Routing Tables)

Send different traffic through different gateways:

# Mark traffic from specific source
/ip firewall mangle add chain=prerouting src-address=192.168.88.100 action=mark-routing new-routing-mark=wan2-table passthrough=yes

# Route in separate table
/ip route add dst-address=0.0.0.0/0 gateway=198.51.100.1 routing-table=wan2-table comment="WAN2 for .100"

Now 192.168.88.100 uses WAN2, while everyone else uses the default route. See our mangle guide for detailed packet marking.

VRF (Virtual Routing and Forwarding)

Completely separate routing tables for multi-tenant isolation:

/ip vrf add name=customer-a interfaces=ether3
/ip address add address=192.168.100.1/24 interface=ether3
/ip route add dst-address=0.0.0.0/0 gateway=10.0.0.1 vrf=customer-a

Customer A's traffic is completely isolated in its own routing table. See our MPLS guide for VRF with L3VPN.

Blackhole & Unreachable Routes

# Silently drop traffic to a specific network
/ip route add dst-address=10.99.99.0/24 type=blackhole comment="Drop silently"

# Return ICMP unreachable
/ip route add dst-address=10.99.98.0/24 type=unreachable comment="Return unreachable"

Blackhole routes are used for DDoS mitigation (RTBH), preventing routing loops, and discarding traffic to unused subnets.

Route Selection Order

When multiple routes match a destination, MikroTik selects based on:

  1. Most specific (longest prefix match) – /32 > /24 > /16 > /0.
  2. Lowest distance – Distance 1 > Distance 2.
  3. Route type – Connected > Static > OSPF > BGP (by default distance).

Complete Failover Script

# ============================================
# Dual-WAN Failover with Recursive Routes
# WAN1: ether1, gateway 203.0.113.1
# WAN2: ether2, gateway 198.51.100.1
# ============================================

# Health check targets
/ip route add dst-address=8.8.8.8/32 gateway=203.0.113.1 scope=10 comment="WAN1 health"
/ip route add dst-address=8.8.4.4/32 gateway=198.51.100.1 scope=10 comment="WAN2 health"

# Recursive default routes
/ip route add dst-address=0.0.0.0/0 gateway=8.8.8.8 distance=1 target-scope=11 check-gateway=ping comment="Primary WAN1"
/ip route add dst-address=0.0.0.0/0 gateway=8.8.4.4 distance=2 target-scope=11 check-gateway=ping comment="Backup WAN2"

# NAT for both WANs
/ip firewall nat add chain=srcnat out-interface=ether1 action=masquerade
/ip firewall nat add chain=srcnat out-interface=ether2 action=masquerade

Troubleshooting

  • Route shows "inactive": The gateway is unreachable (check-gateway failed or gateway IP not in routing table). Verify with /ping <gateway>.
  • Failover not working: Ensure check-gateway=ping is set on the primary route. Without it, the route stays active even when the gateway is down.
  • Recursive route not resolving: Check target-scope is greater than the scope of the resolving route. Default connected routes have scope=10, so set target-scope=11.
  • Traffic goes through wrong WAN after failover: Existing connections stick to the old route. Use /ip firewall connection remove [find] to reset connections (briefly drops all active connections).
  • ECMP (equal-cost multi-path): Two routes with the same destination and distance create ECMP – traffic is load-balanced across both. If you want failover (not load-balance), use different distances.

Conclusion

Static routing on MikroTik is far more powerful than most admins realize. Distance-based failover, recursive routes for upstream health checking, policy routing with routing tables, VRF for multi-tenant isolation, and blackhole routes for security – all without a single dynamic routing protocol. Master these concepts before moving to OSPF or BGP.

Found this guide helpful?

Share it with fellow network engineers and ISP operators.

MI
MikroRadius Team MikroRadius Engineering Team • RADIUS Authentication & Invoicing

Get Our Next MikroTik Tutorial In Your Inbox

Join 2,500+ ISP engineers. RouterOS scripts, invoicing tips, and zero spam.

Related Guides

MikroTik Questions?

Need guidance setting up RADIUS authentication, optimizing RouterOS queues, or managing subscriber invoicing? Our engineering team is available for live chat.