Community discussions

MikroTik App
 
amin137398
just joined
Topic Author
Posts: 5
Joined: Sat Jan 04, 2020 12:54 pm

need help for my first script

Sat May 25, 2024 11:59 pm

Hello everyone
I'm trying to get my problem solved using scripting and since it's my first time I hope someone could help me with it
I got 2 L2TP connections which randomly goes down and I need to disable them for couple of minutes and then enable them to make them work again!
I wanted to make Router OS automatically do this for me using scripting more explanations :

ping L2tp gateway
if down > disable interface X
delay ( wait )
enable interface X
Delay
and then start over again

best regards
 
UkRainUa
newbie
Posts: 43
Joined: Sun Mar 10, 2024 3:10 am

Re: need help for my first script

Sun May 26, 2024 4:02 pm

Hi!
:if ([:tobool [/tool/ping 1.1.1.1 interface=ether1 count=2]]) do={} else={/interface/ethernet/disable ether1; :delay 60s; /interface/ethernet/enable ether1};
Use the scheduler and your interface names.
 
optio
Forum Veteran
Forum Veteran
Posts: 964
Joined: Mon Dec 26, 2022 2:57 pm

Re: need help for my first script

Sun May 26, 2024 10:53 pm

Use Netwatch ROS feature for this, set host to IP on which you need to check connection and in down-script set script code which disables/enables interface, additionally check interval and timeout properties if you need to tweak how fast it will react on connection loss.
 
UkRainUa
newbie
Posts: 43
Joined: Sun Mar 10, 2024 3:10 am

Re: need help for my first script

Tue May 28, 2024 5:37 pm

Use Netwatch ROS feature for this, set host to IP on which you need to check connection and in down-script set script code which disables/enables interface, additionally check interval and timeout properties if you need to tweak how fast it will react on connection loss.
What about the interface?
/tool ping interface=
Netwatch can choose an interface?
 
optio
Forum Veteran
Forum Veteran
Posts: 964
Joined: Mon Dec 26, 2022 2:57 pm

Re: need help for my first script

Tue May 28, 2024 8:00 pm

Why interface is needed in this case? Unless destination not reachable over main vrf, since Netwatch is lacking vrf setting.

P.S.
Netwatch has src-address property, it can be set to IP of desired interface.
 
robert555
just joined
Posts: 5
Joined: Tue Mar 14, 2023 5:01 pm

Re: need help for my first script

Tue May 28, 2024 11:53 pm

Hi, I have a doubt. I have a network, separated by VRF for management and web access. But I have a problem is that I have ping between VRFs, for example: I have a router that contains the two vrfs (vrf1 and vrf2) each vrf has its own different network and the gateways are in router. Now if I have a pc on vrf1 with network 1 and I make the vrf2 gateway this ping is possible. This is counterintuitive because I understand that the vrfs are in different routing domains. And also if I ping vrf1's PC from vrf2 with a source from its own network, I can reach it. Please help.
 
UkRainUa
newbie
Posts: 43
Joined: Sun Mar 10, 2024 3:10 am

Re: need help for my first script

Fri Jun 07, 2024 2:19 pm

Why interface is needed in this case? Unless destination not reachable over main vrf, since Netwatch is lacking vrf setting.

P.S.
Netwatch has src-address property, it can be set to IP of desired interface.
If there is no src-address address, dhcp client? :)
 
optio
Forum Veteran
Forum Veteran
Posts: 964
Joined: Mon Dec 26, 2022 2:57 pm

Re: need help for my first script

Fri Jun 07, 2024 4:37 pm

Isn't that bound address then? This can be retrieved for interface and set into src-address property.