top of page
Writer's picturegraham9113

Mikrotik Dual WAN Failover Configuration: A Technical Guide

Ensuring Constant Connectivity: Mikrotik Dual WAN Failover Explained

In today's interconnected world, a stable internet connection is crucial for businesses and individuals alike. But what happens when your primary internet connection fails? This is where a dual WAN (Wide Area Network) failover system comes into play. While there are numerous approaches to this problem from various networking vendors, the solution offered by Mikrotik routers stands out due to its exceptional flexibility and the low cost of the hardware. This combination of versatility and affordability makes Mikrotik an attractive option for businesses of all sizes, from small home offices to larger enterprises looking for a cost-effective yet powerful networking solution.

What is Dual WAN Failover?

Dual WAN failover is a network configuration that uses two internet connections to ensure continuous internet access. If the primary connection fails, the system automatically switches to the secondary connection, minimizing downtime and maintaining connectivity.

Why is it Important?

  1. Reliability: It provides a backup in case your main internet connection fails.

  2. Business Continuity: Ensures that your operations can continue without interruption.

  3. Load Balancing: Can distribute traffic across both connections for improved performance.

How Does Mikrotik Dual WAN Failover Work?

Mikrotik's RouterOS allows for a sophisticated failover setup using a combination of routing tables, rules, and scripts. Here's a high-level overview of how it works:

  1. Two Internet Connections: Your Mikrotik router is connected to two separate internet services.

  2. Routing Tables: The router uses two routing tables:

  • A main table for the primary connection

  • A secondary table for the backup connection

  1. Routing Rules: These determine which traffic uses which table.

  2. Monitoring Script: A script continuously checks the health of the primary connection.

  3. Automatic Switching: If the primary connection fails, the script activates a rule that routes traffic through the secondary connection.

  4. Restoration: When the primary connection is restored, traffic is automatically switched back.

Key Components of the Mikrotik Failover System

  1. Ping Test: The system regularly pings a reliable external IP address (like Google's DNS at 8.8.8.8) to check the primary connection's health.

  2. Threshold: A predefined threshold (e.g., 3 out of 10 successful pings) determines when to consider the connection as failed.

  3. Email Alerts: The system can send email notifications when failover occurs and when the primary connection is restored.

  4. Logging: All failover events are logged for later analysis.

Benefits of Using Mikrotik for Dual WAN Failover

  1. Cost-Effective: Mikrotik routers offer enterprise-level features at a fraction of the cost of many competitors.

  2. Flexible Configuration: RouterOS allows for highly customizable setups to suit various network needs.

  3. Powerful Scripting: The ability to write custom scripts enables advanced automation and monitoring.

  4. Community Support: A large community of users and extensive documentation make troubleshooting easier.

Implementing Dual WAN Failover

While the actual implementation involves technical configurations (routing tables, rules, and scripts), the concept is straightforward:

  1. Connect your Mikrotik router to two internet connections.

  2. Set up routing tables for each connection.

  3. Create rules to manage traffic flow between these tables.

  4. Implement a monitoring script to check the primary connection's health.

  5. Configure the script to switch traffic to the secondary connection when needed.

Conclusion

Mikrotik's dual WAN failover capability offers a robust solution for ensuring constant internet connectivity. By automatically switching between two internet connections, it provides peace of mind for businesses and individuals who rely on uninterrupted internet access.

While setting up such a system requires some technical knowledge, the benefits in terms of reliability and business continuity are significant. Whether you're running a small business, managing a home office, or simply want to ensure you're always connected, a Mikrotik dual WAN failover setup could be the solution you need.

However, implementing this solution effectively requires expertise in network configuration and management. That's where SeraphimGate Systems (SGS) comes in. Our team of skilled professionals specializes in setting up and optimizing network systems of all types, including Mikrotik dual WAN failover configurations.

Don't let technical challenges hold you back from achieving a more reliable and robust network. Contact SeraphimGate Systems today for expert assistance in implementing your Mikrotik dual WAN failover solution. We're here to help you navigate the complexities of network setups, ensuring you get the most out of your internet connectivity.

Ready to upgrade your network resilience? Reach out to SGS now, and let's work together to create a network that never lets you down.

For those interested in the technical details of implementation, including the actual scripts and routing configurations, please refer to the code below.

 

# Mikrotik RouterOS Failover and Monitoring Script

# By Graham Fischer-Corners for SeraphimGate Systems


# Set local variables

# ipPing: The IP address to ping for testing the connection

# pingip: Variable to store the number of successful pings

:local ipPing "8.8.8.8" # Using Google's DNS server as a reliable target

:local pingip


# Set global variable and define scope in code block

# previousState: Keeps track of the connection state between script runs

# 0 = connection was previously reliable, 1 = connection was previously unreliable

:global previousState

:if ([:typeof $previousState] = "nothing") do={

:set previousState "0" # Initialize to "reliable" state if not set

:log info "GlobalVarSet"

}


# Test the connection and parse the result

# Ping the target IP 10 times through the primary interface (ether1)

# The result (number of successful pings) is stored in pingip

:set pingip [/ping $ipPing count=10 interface=ether1]


# Check if the connection has become unreliable

# If 3 or fewer pings succeed and the previous state was reliable (0)

:if ($pingip <= 3 && $previousState = "0") do={

:global previousState

:log info "Interface unreliable! Enabling routing rule and sending email."

# Send an email alert about the unreliable connection

/tool e-mail send to="[email protected]" subject="$[/system identity get name] Internet Unreliable" \

body="$[/system clock get time] TimeStamp"

# Enable the failover routing rule

# Make sure to set up the failover routing rule with the same comment used here

/routing rule enable [find comment="Enable routing rule"]

# Update the state to unreliable

:set previousState "1"


# Check if the connection has been restored

# If more than 3 pings succeed and the previous state was unreliable (1)

} else={

:if ($pingip > 3 && $previousState = "1") do={

:global previousState

# Send an email alert about the restored connection

/tool e-mail send to="[email protected]" subject="$[/system identity get name] Internet Restored" \

body="$[/system clock get time] TimeStamp"

:log info "Interface reliable! Disabling routing rule."

# Disable the failover routing rule

/routing rule disable [find comment="Enable routing rule"]

# Update the state to reliable

:set previousState "0"

}

}


 

Note: This script should be scheduled to run at regular intervals (e.g., every 1-5 minutes) to continuously monitor the connection and perform failover when necessary.


FAQ

What exactly is dual WAN failover?

Dual WAN failover is a network setup that uses two internet connections. If the primary connection fails, the system automatically switches to the secondary connection, ensuring continuous internet access.

Do I need special hardware to set up dual WAN failover with Mikrotik?

How quickly does the failover occur?

Can I use two different types of internet connections (e.g., fiber and 4G)?

Is it difficult to set up dual WAN failover on a Mikrotik router?

 Is this solution suitable for small businesses or home offices?


312 views0 comments

Recent Posts

See All

©2024 BY SERAPHIMGATE SYSTEMS

  • linkedin
bottom of page