Introduction to MikroTik Recursive Routing
In modern networking, the concept of recursive routing plays a pivotal role in optimizing data transfer across complex networks. At its core, recursive routing involves a multi-step process where a router resolves the best path to a destination by analyzing and resolving intermediate routes. This methodology ensures that data packets are forwarded efficiently by resolving the next-hop and its associated path seamlessly.
Recursive routing is a cornerstone in the functionality of dynamic routing protocols, VPN configurations, and failover setups, providing the scalability and reliability needed for today’s demanding network environments. MikroTik, a leading name in network devices, offers robust support for recursive routing, allowing administrators to build versatile and resilient networks.
Read more about Recursive Routing here
What is Recursive Routing in MikroTik?
In MikroTik devices, recursive routing operates similarly, resolving the next-hop address in a multi-step process. This feature is critical for complex network setups like VPNs, GRE tunnels, or advanced failover mechanisms.
hanging the target-scope
higher than 11 on the 0.0.0.0/0
recursive routing route in MikroTik is necessary to ensure proper resolution of the recursive route without conflicts or misinterpretations by the router. Here’s why:
- Recursive Resolution: The default
target-scope
of directly connected routes is 10. By setting thetarget-scope
on the recursive0.0.0.0/0
route higher than 11, you allow the router to correctly reference other routes (e.g., next-hop routes with a scope of 10 or 11). - Avoid Routing Loops: A
target-scope
that’s too low may cause the router to misinterpret routes or create a loop during recursive resolution, leading to network instability. - Proper Next-Hop Lookup: Higher
target-scope
values ensure that the router prioritizes direct routes or lower-scoped routes for the initial hop while still allowing recursion for subsequent lookups. - Failover Stability: Adjusting the
target-scope
helps the router reliably switch between primary and backup routes, maintaining seamless failover functionality.
This configuration ensures that recursive routing resolves efficiently and that failover works as intended without compromising performance or stability.
The topology consists of a MikroTik with dual internet connections.
WAN1 = Ether 1 provided by a Static IP address
WAN2 = Ether 2 provided by PPPoE
Click here to view other tutorials for MikroTik Internet Failover Solutions
Routing
Here we have the routing table as-is. Both gateways for each interface are static and the second (WAN2/PPPoE) has a distance of 2 making it the backup.
We then need to add 2 additional static routes pointing at our public IPs. We’re using both Google DNS servers (8.8.8.8 & 8.8.4.4) so needs to be something at is likely to always be accessible/online.
Each route has one of the servers and the next hop gateway. We then also the scope to be 10 so it seems like they are directly connected routes.
We then either change or remove and add the default gateways, but this time the Gateway/Next-Hop are the public IP addresses (8.8.8.8 = Primary/ether1 & 8.8.4.4 = Secondary/PPPoE1).
Now we also need to set the Target Scope to 11 and enable the Check Gateway to ping option.
Now our recursive routing is complete.
Using Dynamic Gateways
Ether1 is configured statically as is the Gateway, however if we were to receive our IP and next-hop gateway via DHCP, we can use the following config to update the recursive route pointing to 8.8.8.8.
On our DHCP-Client, untick Add Default Route and on the Advanced Tab add the below script. It will run every time there is a change to the DHCP-client and if it receives a valid IP (bound) it will get the received Gateway and update the route with the comment “primary_check”.
if (($"bound")=1) do={
:local gwip ($"gateway-address")
:log info $gwip
ip route set gateway=$gwip [find comment="primary_check"]
}
Then we just need to give the recursive route using that interface a comment of “primary_check” and if the gateway IP changes the route gets automatically updated.