Community discussions

MikroTik App
 
ik3umt
Member Candidate
Member Candidate
Topic Author
Posts: 271
Joined: Tue Jul 08, 2014 3:58 pm

Enable a rule just for specific time

Sun Mar 22, 2020 6:26 pm

How can I set a timer to trigger a firewall rule enabling and automatically disabling after X minutes ?
Not a scheduled rule (made by schedule or rule "time" option) , a "one shot" rule to be triggered when needed.

Thanks
 
msatter
Forum Guru
Forum Guru
Posts: 1459
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Enable a rule just for specific time

Sun Mar 22, 2020 7:05 pm

You can do that in scheduler with one activating the rule and a second onedisabling it again.
In a scipt you can also put a :delay 2m between to script lines.
Two RB760iGS (hEX S) in series. One does PPPoE and both do IKEv2.
Running:
RouterOS 6.47.beta.x / Winbox 3.21 / MikroTik APP 1.3.12
NordVPN viewtopic.php?f=2&t=158439&p=781009 for multiple connections.
 
ik3umt
Member Candidate
Member Candidate
Topic Author
Posts: 271
Joined: Tue Jul 08, 2014 3:58 pm

Re: Enable a rule just for specific time

Mon Mar 23, 2020 11:52 am

Thanks,
What about to simply enable the rule and disable it after x minutes ?
/ip firewall filter enable <rule>
delay 3600;
/ip firewall filter disable <rule>
any issue in leaving script hung for a long time ?
 
Zacharias
Forum Guru
Forum Guru
Posts: 1603
Joined: Tue Dec 12, 2017 12:58 am
Location: Greece

Re: Enable a rule just for specific time

Mon Mar 23, 2020 12:33 pm

Obvioulsy it will consume some memory and CPU...
 
FRANKMUNOZ
just joined
Posts: 6
Joined: Mon Feb 24, 2020 12:59 am

Re: Enable a rule just for specific time

Mon Mar 23, 2020 4:12 pm

/system scheduler
add interval=31s name=schedule1 on-event="/ip firewall filter disable 2" policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-time=startup

add interval=14s name=schedule2 on-event="/ip firewall filter enable 2" policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-time=startup




there you have the two scripts, you just have to adapt it to your demands, I hope they serve you.
 
FRANKMUNOZ
just joined
Posts: 6
Joined: Mon Feb 24, 2020 12:59 am

Re: Enable a rule just for specific time

Mon Mar 23, 2020 5:39 pm

/system scheduler
add disabled=yes interval=30s name="Scheduler10" on-event=\
"/ip firewall filter disable 2\r\
\ndelay 10;\r\
\n/ip firewall filter enable 2" policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=dec/01/2018
start-time=00:00:00

there you have another script, you just have to adapt it to your demands, I hope it works for you
 
User avatar
Abduljbbar
just joined
Posts: 2
Joined: Sun Mar 22, 2020 12:21 am

Re: Enable a rule just for specific time

Wed Mar 25, 2020 12:42 am

Thanks,
What about to simply enable the rule and disable it after x minutes ?
/ip firewall filter enable <rule>
delay 3600;
/ip firewall filter disable <rule>
any issue in leaving script hung for a long time ?
I think now you just inform the rb to do some thing and take a rest for some second and then do other things so it will not spend cpu and ram
this is my opinion
Oh, Allah save my peoples and all in the earth

Who is online

Users browsing this forum: No registered users and 51 guests