Stabilizing Multi-WAN Load Balancing in RouterOS v7: Fixing the "Local Subnet Blindspot"
In our previous article, we successfully implemented a Server Name Indication (SNI) bypass mechanism using dynamic wildcard TLS matching (tls-host="*.gov.ph") to stabilize session persistence for sensitive production portals like the PRC CPDAS platform. This allowed network administrators to retain aggressive multi-WAN load balancing across local client subnets without introducing authentication session drops.
However, moving the policy-based routing enforcement from the firewall mangle table over to the native RouterOS v7 /routing rule lookup system introduces an unintended structural anomaly: The Local Subnet Blindspot.
1. The Symptom of the "Local Blindspot"
Immediately after activating client-subnet-to-ECMP routing rules, inter-VLAN communications collapse. Clients localized within the production subnets (e.g., UniFi Management, Hotspot Bridges, or standard LANs) abruptly lose access to critical internal corporate resources.
Local infrastructure assets—such as localized AdGuard Home DNS servers (172.21.0.5), internal file servers (NAS), and network monitoring engines like Zabbix (172.16.1.253)—fail to return ICMP echoes (Request Timed Out) and experience total service interruption.
2. Root Cause Analysis: The Inversion of Connected Routes
The breakdown of local routing is caused by the strict procedural logic of the RouterOS v7 policy routing engine. Consider the standard implementation route rule:
/routing rule add src-address=172.16.0.0/23 action=lookup table=ecmp_route
When a device within the localized subnet initiates a transaction to an internal destination (such as a query directed to the AdGuard DNS instance), the MikroTik CPU evaluates the routing rules first. Because the rule matches the client's source IP block, it executes an immediate, unconditional lookup inside the specified custom table (ecmp_route).
[ Client Frame Initiated ]
│
▼
[ Routing Rules Audited ]
│
Matches Client Subnet?
├──► YES: Forces lookup inside 'ecmp_route' table
│ │
│ ▼
│ [ Evaluates 0.0.0.0/0 Gateways ] ──► Packet sent to WAN ISPs (Dropped)
│
└──► NO: Falls back to 'main' table (Normal Local Routing)
The functional failure stems from the fact that the custom routing table only contains the default gateways (0.0.0.0/0) assigned to the external WAN ISPs. It completely lacks the dynamically populated connected flags (DAC) that designate local interface routes. Consequently, the router treats local inter-subnet frames as standard external internet bound traffic and forwards them directly to the active WAN providers. The upstream ISP gateways do not possess routing knowledge of your private IP spaces (RFC 1918), causing the packets to be dropped immediately.
3. The Solution: Implementing a Local Inter-Subnet Bypass Rule
Rather than manually constructing an exhaustive matrix of bidirectional routing exception rules or cluttering the configuration with destination address lists, RouterOS v7 introduces a highly optimized architectural parameter designed specifically to handle this lookup behavior: min-prefix=0.
In MikroTik's routing logic, applying a rule configured with min-prefix=0 that references the main routing table acts as an inline connected-route pre-check. This instructs the routing engine to inspect the destination IP address against the existing connected subnets actively bound to the hardware interfaces before applying any custom multi-WAN policies. If a direct subnet match is discovered locally, it routes the packet via the default main table; otherwise, it passes the frame down the chain for external load balancing.
4. Implementation Guide
Step 1: Execute High-Priority Connected Bypass Command
Open the RouterOS v7 terminal and inject the following lookup rule. This configuration bypasses the policy table specifically for all locally reachable networks:
/routing rule
add min-prefix=0 action=lookup table=main comment="LOCAL BYPASS - Allow Inter-Subnet Routing"
Step 2: Establish Proper Priority Sequence (Winbox Order)
Because routing rules are processed sequentially from top to bottom (Index 0 downward), the configuration is order-dependent. The local bypass exception must evaluate first to prevent downstream ECMP rules from intercepting internal traffic.
Navigate to Routing > Rules inside the Winbox interface.
Locate the newly injected rule containing the comment
LOCAL BYPASS - Allow Inter-Subnet Routing.Click and drag the rule to the absolute top of the stack (Index 0 / Rule #0), positioning it directly above the active client-to-ECMP routing rules.
[Rule 0] min-prefix=0 table=main --> Matches connected subnets (Ensures Local/AdGuard/Zabbix Connectivity)
[Rule 1] src=10.0.0.0/21 table=ecmp_route --> Internet bound traffic dropped to ECMP pool
[Rule 2] src=172.16.0.0/23 table=ecmp_route --> Internet bound traffic dropped to ECMP pool
5. Complete RouterOS v7 Configuration Script
Here is the complete configuration stack incorporating tables, routes, and ordered routing rules:
###############################################################################
# 1. ROUTING TABLES
###############################################################################
/routing table
add fib name=ecmp_route comment="Custom Table for Multi-WAN Load Balancing"
###############################################################################
# 2. IP ROUTES
###############################################################################
/ip route
# Default Route in 'main' table (Router-originated & fallback traffic)
add dst-address=0.0.0.0/0 gateway=192.168.1.1 distance=1 routing-table=main comment="WAN1 Main"
add dst-address=0.0.0.0/0 gateway=192.168.2.1 distance=2 routing-table=main comment="WAN2 Backup"
# ECMP Load-Balancing Routes in 'ecmp_route' table
add dst-address=0.0.0.0/0 gateway=192.168.1.1,192.168.2.1 routing-table=ecmp_route comment="ECMP WAN1 + WAN2"
###############################################################################
# 3. ROUTING RULES (Order is critical!)
###############################################################################
/routing rule
# [RULE 0] HIGH PRIORITY LOCAL BYPASS
add min-prefix=0 action=lookup table=main comment="LOCAL BYPASS - Allow Inter-Subnet Routing"
# [RULE 1+] CLIENT POLICY RULES
add src-address=10.0.0.0/21 action=lookup table=ecmp_route comment="Client Subnet 1 -> ECMP"
add src-address=172.16.0.0/23 action=lookup table=ecmp_route comment="Client Subnet 2 -> ECMP"
###############################################################################
# 4. NAT / MASQUERADE
###############################################################################
/ip firewall nat
add chain=srcnat out-interface=ether1-WAN1 action=masquerade comment="NAT WAN1"
add chain=srcnat out-interface=ether2-WAN2 action=masquerade comment="NAT WAN2"
6. Outcomes & Structural Benefits
Immediate Inter-Subnet Restoration: Once positioned at Index 0, queries directed to internal services like AdGuard instances or cross-subnet monitoring polls immediately resolve successfully without requiring interface restarts.
Preserved Multi-WAN Efficiency: Publicly routed traffic (e.g., standard HTTPS web navigation, media streaming, software updates) fails the local
min-prefix=0connected network check, transparently falling through to the subsequent policy rules to be hashed symmetrically across the external internet paths.Elimination of Administrative Overhead: Unlike manual static address list exclusions, using
min-prefix=0dynamically scales with your ecosystem. If you provision new VLAN interfaces, virtual bridges, or secondary local networks in the future, the rule automatically encompasses them without requiring manual additions to the script.

Comments
Post a Comment