Disable and Enable interface

Greetings friends:
I have the following script that disables an interface of my RB when it pings google DNS and they do not respond, I need that same interface to be enabled when google DNS respond to ping, someone can help me.

I leave the script that I have.

:if ( [/ping 8.8.8.8 interface= “ETHERT 2” count=6 ] = 0) do={/interface disable numbers=1}


Thank you.

Can someone give me a hand?

Very limited info you provide, but if my understanding is correct, then there is a problem with your logic.

i.e. you ping 8.8.8.8 from ether 2, if no response, you disable interface, with this interface disabled, you will not be able to ping from it.
If reasons for doing this is dual WAN purposes, then rather look at disabling routes or something instead of the interface

The purpose is to balance two different isps, so how would you disable the routes?

Thank you.

http://forum.mikrotik.com/t/advanced-routing-failover-without-scripting/136599/1

You should do like this.
Make a netwatch with 8.8.8.8 and for UP you use UP_ETHER script, and for DOWN you use DOWN_ETHER script or any name you want.

/tool netwatch
add down-script=down_ether host=8.8.8.8 interval=15s \
    up-script=up_ether
    /system script
/system script
add dont-require-permissions=yes name=up_ether owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="/interface enable ether2"
add dont-require-permissions=yes name=down_ether owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="/interface disable ether2"

Friends, how do I disable a rule in ip route?
And then how do I enable that same rule when the script responds to the ping I do to DNS 8.8.8.8


Thank you.

do you tried what i wrote?

If I try my friend and it does not work, I need a script where I ping the DNS 8.8.8.8 and if it does not respond disable the route of that interface in IP ROUTE, and the script continues pinging the DNS 8.8.8.8, when answer re-enable the route of that interface wn IP ROUTE.

I don’t know if they understood me

Thank you.

msatter understood your question and pointed you in the right direction. The linked post contains all you need to know to create a failover solution.

Next time, don’t quite entire posts especially if it’s the most recent post you are replying to.. thanks :slight_smile:

I understand what you say friend, but there is no way to create a script that does what I need?

Thank you

first, where are you from?

first, add a comment into that route and do something like this

/tool netwatch
add  down-script="/ip route enable [find comment=ISP2]" host=\
    8.8.8.8 interval=2s up-script="/ip route enable [find comment=ISP1]"

This if you have two ISP and want some to be active or not.
If you want just one ether to deal with, just put same comment

/tool netwatch
add  down-script="/ip route enable [find comment=ISP1]" host=\
    8.8.8.8 interval=2s up-script="/ip route enable [find comment=ISP1]"

but you need to put comment to that route. Double click and on the left you will have tab COMMENT

Greetings, I have a load balancing of 2 ISPs, what I need is for WAN 2 to constantly ping DNS 8.8.8.8, so that when the ping does not respond, it disables that route and that clients leaving through WAN 2 can hear to WAN 1 due to the failover, and when WAN 2 has internet again, the clients that go out there will return again, I don’t know if you understand me friend.

Tank you

So if you say this works:

:if ( [/ping 8.8.8.8 interface= "ETHERT 2" count=6 ] = 0) do={/interface disable numbers=1}

Then the following should work if you add the comment label “ISP2” to the route going to your second provider. ETHERT 2 is not disabled this way, this because you can never detect when it is active again because it is disabled by you.

Down? then disable the route.

:if ( [/ping 8.8.8.8 interface= "ETHERT 2" count=6 ] = 0) do={/ip route disable [find comment=ISP2]}

Up? then enable the route again.

:if ( [/ping 8.8.8.8 interface= "ETHERT 2" count=6 ] != 0) do={/ip route enable [find comment=ISP2]}

This is really crude/simple/basic and I don’t know if the traffic is routed through ISP1 when the label is not found/active in routing.

Msatter, there is no way that they are not 2 script, but only one? I do not know if you understand me, it would be something like that where 8.8.8.8 is pinged and if it does not respond, disable the rule in IP ROUTE, and that same script follows pinging 8.8.8.8 and if it responds enable the rule. It is something like the 2 scripts in one, if you can.
Tank you.

OK.

{
:if ( [/ping 8.8.8.8 interface= "ETHERT 2" count=6 ] = 0) do={/ip route disable [find comment=ISP2]}
:if ( [/ping 8.8.8.8 interface= "ETHERT 2" count=6 ] != 0) do={/ip route enable [find comment=ISP2]}
}

I’m going to try it and tell him, but apparently it fit.
Tank you

You should try to use recursive routes.
It will automatically ping a specific destination but you will need to have a static ping address per route.
for one route you can use 8.8.8.8
and the other 1.1.1.1

https://help.mikrotik.com/docs/display/ROS/Failover