Yes we can do it through static routes. Having two static exit routes to the Internet for each of the providers and using the distance option on the route. The main provider should be given a low distance and the secondary provider a high distance. The route with the lowest distance is the one that will remain active. The distance is a number that can be within the range 1 to 255.
It is possible to connect two Internet providers to the same MikroTik device and configure it so that, if one stops having an Internet connection, the traffic is automatically redirected to the other provider. This configuration is known as WAN failover or load balancing with failover. Although load balancing distributes traffic between two or more connections, failover ensures that if one connection fails, traffic is automatically redirected to another active connection.
Here we explain how to configure WAN failover in MikroTik RouterOS:
Step 1: Configure WAN Interfaces
First, you need to configure both WAN interfaces with the IP addresses provided by your ISPs. This is usually done in IP > Addresses.
Step 2: Configure the Default Gateway
Next, configure the default gateway for each of the Internet providers in IP > Routes. You must add a route for each provider:
- For the primary ISP, add a route with the gateway provided by the ISP and leave it with a distance of 1.
- For the backup ISP, add a route with the gateway provided by this ISP and set a longer distance, for example, 2.
Step 3: Configure Failover
Failover can be configured using the verification script and recursive routes. You'll need to create a script that verifies the Internet connection, for example by pinging a trusted public IP address (such as Google DNS 8.8.8.8). If the ping fails, the script can change the distance of the routes to cause the traffic to be redirected to the other ISP.
Step 4: Create a Verification Script
Create a script in System > Scripts verify connectivity and adjust route distances as necessary. Here's a basic example of what the script might look like:
:if ([/ping 8.8.8.8 count=3] = 0) do={
/ip route set [find comment="ISP1"] distance=2
/ip route set [find comment="ISP2"] distance=1
} else={
/ip route set [find comment="ISP1"] distance=1
/ip route set [find comment="ISP2"] distance=2
}
This script tries to ping 8.8.8.8 three times. If it fails (indicating that the primary ISP is down), it changes the distance of the routes to prioritize the backup ISP.
Step 5: Schedule the Script
Finally, schedule the script to run periodically on System > Scheduler. This will ensure that the script runs at regular intervals, allowing for automatic detection and failover.
Additional considerations
- Testing: After configuring failover, test by physically disconnecting one of your ISPs to ensure that failover is working as expected.
- Load balancing: If you want to use both ISPs at the same time, you can consider setting up load balancing in addition to failover. However, load balancing requires additional configurations.
- Structural: Keep track and monitor connections so you can react quickly to any problems.
This basic failover setup should provide you with automatic switching between two Internet providers in case one fails, improving the reliability of your Internet connection.
There are no tags for this post.