Community discussions

MikroTik App
 
soran1
just joined
Topic Author
Posts: 17
Joined: Mon Sep 06, 2021 11:17 am

script for failover swap between 2 link-2ethernet one main and one backup

Sat Dec 09, 2023 10:22 pm

hi :-D ,i will share you a useful simple script that i was searching for it and i didnt find it so i wrote it by myself and let all get it if some time they need it
what is the idea ?
if you have 2 wireless link going to one mikrotik routerboard as 4011rb ccr1016 and you dont want to use bonding for (failover layer2) such active-backup or bgb, ospf failover and others so the script will do it for you so example
ether1 -link 1 main enabled
ether2 -link 2 backup - disabled

when the ether1 goes down and the ether status will be(no-link) it will enable the ether2 if the ether1 goes up and (link ok) it will stop the ether2link
and enable the ether1 no matter how you configuration is inside bridge port or take service from vlans so let you with script and note that you should change the name of ether inside the script

#this code just to on or off the main or backup ethers if the main fails and no link status it will run the ether2 link backup#
interface ethernet monitor ether1 once do={:if (status =no-link) do={:interface ethernet set ether2 disabled=no} else={:interface ethernet set ether2 disabled=yes}} 


#if you have vlans coming from the ap or the isp and should change the interfaces when swap between the main and backup links as my configuration it will be 

interface ethernet monitor ether1 once do={:if (status =no-link) do={:interface ethernet set ether2 disabled=no; /interface vlan set vlan60,vlan61 interface=ether2} else={:interface ethernet set ether2 disabled=yes; /interface vlan set vlan61,vlan60 interface=ether1}} 
i wish it will be useful for you :D
 
eldoncito2019
Member
Member
Posts: 331
Joined: Fri Jun 14, 2019 1:07 pm

Re: script for failover swap between 2 link-2ethernet one main and one backup

Sun Dec 10, 2023 1:01 pm

:if ([/ping 1.1.1.1 interface="ether1" count=6]= 0) do={
    /interface enable "ether2"} else={
    /interface disable "ether2"}

For this case I use this, I hope it helps you.
 
soran1
just joined
Topic Author
Posts: 17
Joined: Mon Sep 06, 2021 11:17 am

Re: script for failover swap between 2 link-2ethernet one main and one backup

Sun Dec 10, 2023 3:14 pm

thank you its useful when it have reachability to internet but what you do if its work just with l2 without ping or any reachability when its depends only just on ethers

Who is online

Users browsing this forum: No registered users and 9 guests