Community discussions

MikroTik App
 
Yuna
just joined
Topic Author
Posts: 11
Joined: Fri Dec 16, 2016 8:12 am

Simple Script for enabling Interfaces for FailOver

Fri Jan 13, 2017 9:45 pm

Hi,

Can someone help me in this simple script? I'd like to ping ISP1 and if there is no answer, the script should enable the second (Failover) interface.

# Please fill the WAN interface names
:local InterfaceISP1 ether1;
:local InterfaceISP2 myLTE;

# Please fill the gateway IPs
:local GatewayISP1 192.168.50.1;
:local GatewayISP2 192.168.30.1;

# Please fill the ping check host - currently: google.com
:local PingTarget 8.8.8.8;
:local PingResult 0;

# Editing the script after this point may break it
# -------------- stop editing here --------------

:if (ping $PingTarget count=1 interface=$InterfaceISP1 != 0) do={ /interface enable $InterfaceISP2; } else={ /interface enable $InterfaceISP2; }
 
magchiel
Member Candidate
Member Candidate
Posts: 133
Joined: Mon Jan 06, 2014 2:13 pm

Re: Simple Script for enabling Interfaces for FailOver

Sat Jan 14, 2017 1:46 pm

If it's all the same to you, you can also achieve this by setting routing distances for the default routes on both devices. As soon as the default route with the lowest distance will become unavailable (check gateway) it'll switch to next in line.
 
Yuna
just joined
Topic Author
Posts: 11
Joined: Fri Dec 16, 2016 8:12 am

Re: Simple Script for enabling Interfaces for FailOver

Sat Jan 14, 2017 2:01 pm

I know, but the second Gateway is a 3G stick and should only exchange data in the worst case. That's the reason, why I am looking for the way by script. But if you have a possibility to do this without any script, please explain. Thx.


Gesendet von iPhone mit Tapatalk Pro
 
magchiel
Member Candidate
Member Candidate
Posts: 133
Joined: Mon Jan 06, 2014 2:13 pm

Re: Simple Script for enabling Interfaces for FailOver

Sat Jan 14, 2017 7:43 pm

Assuming you're paying for data and not for uptime the routing distances should suffice (as - bar a keepalive - no data should be transferred so long a lower weighted route is active).

If you're adamant that the interface is to be disabled when the landline is working, scripting is your solution as the netwatch is still functionally impaired (HELLO MikroTik @ http://forum.mikrotik.com/viewtopic.php?f=1&t=83251).

Several issues with your script:
-both cases are doing the same thing (i.e. it is enabling whether ping is succesful and not); as you'r evaluating negatively (!=) change the 'do' case to disable.
-the syntax of the ping evaluation should be like :if ([/ping ... ] != 0)
-could clean-up some unnecessary variables (e.g. gateways, pingresult)

Fixing above issues should make the script functional.

Use the scheduler to run the script on the interval of your choosing.

Good luck.
 
Yuna
just joined
Topic Author
Posts: 11
Joined: Fri Dec 16, 2016 8:12 am

Re: Simple Script for enabling Interfaces for FailOver

Sun Jan 15, 2017 8:24 am

Thanks for the recommendation and hints for the script. I would try again the solution by routing. Can you refer to an working example? Do I need to remove the automatically generated routings? Do I only need to configure the routings or is there something else?

Thanks


Gesendet von iPhone mit Tapatalk Pro
 
Yuna
just joined
Topic Author
Posts: 11
Joined: Fri Dec 16, 2016 8:12 am

Simple Script for enabling Interfaces for FailOver

Sun Jan 15, 2017 11:00 pm

Last edited by Yuna on Sun Jan 15, 2017 11:00 pm, edited 1 time in total.
 
Yuna
just joined
Topic Author
Posts: 11
Joined: Fri Dec 16, 2016 8:12 am

Re: Simple Script for enabling Interfaces for FailOver

Tue Jan 17, 2017 12:03 am

If it's all the same to you, you can also achieve this by setting routing distances for the default routes on both devices. As soon as the default route with the lowest distance will become unavailable (check gateway) it'll switch to next in line.
Hi magchiel
Can you tell me,what I need to configure? I prepared the routing rules, but it doesn't work. Default routes are off. What do I need...?


Gesendet von iPhone mit Tapatalk Pro
 
Yuna
just joined
Topic Author
Posts: 11
Joined: Fri Dec 16, 2016 8:12 am

Re: Simple Script for enabling Interfaces for FailOver

Tue Jan 17, 2017 12:27 am

If it's all the same to you, you can also achieve this by setting routing distances for the default routes on both devices. As soon as the default route with the lowest distance will become unavailable (check gateway) it'll switch to next in line.
Hi magchiel
Can you tell me,what I need to configure? I prepared the routing rules, but it doesn't work. Default routes are off. What do I need...?


Gesendet von iPhone mit Tapatalk Pro
 
magchiel
Member Candidate
Member Candidate
Posts: 133
Joined: Mon Jan 06, 2014 2:13 pm

Re: Simple Script for enabling Interfaces for FailOver

Sun Feb 05, 2017 10:59 pm

Can you tell me,what I need to configure? I prepared the routing rules, but it doesn't work. Default routes are off. What do I need...?
Depends how you populate your routing table; if you're using static routes you can modify the distance in the /ip routing entries. If you're getting your default routes from the DHCP client or PPP you configure the distance at the designated DHCP or PPP entry. In any case just set a higher distance for the backup WAN compared to your main WAN.

Please provide the relevant portion of /ip route print if you're stuck.