Community discussions

MikroTik App
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Disable and Enable interface

Wed Dec 16, 2020 6:35 pm

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.
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Disable and Enable interface

Wed Dec 16, 2020 10:29 pm

Can someone give me a hand?
 
User avatar
CZFan
Forum Guru
Forum Guru
Posts: 2098
Joined: Sun Oct 09, 2016 8:25 pm
Location: South Africa, Krugersdorp (Home town of Brad Binder)
Contact:

Re: Disable and Enable interface

Thu Dec 17, 2020 10:08 am

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
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Disable and Enable interface

Thu Dec 17, 2020 11:34 am

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.
 
msatter
Forum Guru
Forum Guru
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Disable and Enable interface

Thu Dec 17, 2020 1:22 pm

 
tomislav91
Member
Member
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: Disable and Enable interface

Thu Dec 17, 2020 2:48 pm

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.
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"

 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Disable and Enable interface

Thu Dec 17, 2020 3:45 pm

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
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.
 
tomislav91
Member
Member
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: Disable and Enable interface

Thu Dec 17, 2020 9:33 pm

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
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?
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Disable and Enable interface

Thu Dec 17, 2020 10:01 pm

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
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.
 
nescafe2002
Forum Veteran
Forum Veteran
Posts: 897
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: Disable and Enable interface

Fri Dec 18, 2020 12:13 am

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 :)
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Disable and Enable interface

Fri Dec 18, 2020 3:51 pm

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 :)
I understand what you say friend, but there is no way to create a script that does what I need?

Thank you
 
tomislav91
Member
Member
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: Disable and Enable interface

Mon Dec 21, 2020 2:47 pm

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 :)
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
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Disable and Enable interface

Mon Dec 21, 2020 3:40 pm

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 :)
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
 
msatter
Forum Guru
Forum Guru
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Disable and Enable interface

Mon Dec 21, 2020 4:50 pm

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.
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Disable and Enable interface

Mon Dec 21, 2020 6:33 pm

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.
 
msatter
Forum Guru
Forum Guru
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Disable and Enable interface

Mon Dec 21, 2020 9:24 pm

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]}
}
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Disable and Enable interface

Mon Dec 21, 2020 10:59 pm

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
 
elico
Member Candidate
Member Candidate
Posts: 143
Joined: Mon Nov 07, 2016 3:23 am

Re: Disable and Enable interface

Mon Apr 05, 2021 10:45 am

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

Who is online

Users browsing this forum: No registered users and 15 guests