Community discussions

MikroTik App
 
Naomie
just joined
Topic Author
Posts: 1
Joined: Tue Nov 09, 2021 9:33 am

firewall configuration in Mikrotik

Tue Nov 09, 2021 9:43 am

good day, to all

please I need your help, in the situation that I found myself into, and I need your assistance please???

automatically enables Firewall Rules in Mikrotik if it cannot ping a partilucar IP??

Example: if IP address 192.168.0.1 goes down, the script needs to then disable 2 NAT rules and then enable 2 others ??

i really need help and I'm grateful.
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 725
Joined: Tue Dec 17, 2019 1:08 pm

Re: firewall configuration in Mikrotik

Fri Nov 12, 2021 11:59 am

Step 1: Trigger
You can use "Scheduler" or "Netwatch" to trigger Scripts.

Step 2: Script A (IP-Online)
The quick and easy way is to use "comment" to find the correct NAT-Rules
After Creating the needed NAT-Rules simply add a unique string to you comments.
In the following exemple the comment must contain "abcdef" or "123456"
/ip firewall nat set [find where comment~"abcdef"] disabled=yes
/ip firewall nat set [find where comment~"123456"] disabled=no
Step 3: Script B (IP-Offline)
For Script B you just have to do the reverse
/ip firewall nat set [find where comment~"abcdef"] disabled=no
/ip firewall nat set [find where comment~"123456"] disabled=yes
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: firewall configuration in Mikrotik

Fri Nov 12, 2021 8:11 pm

Right, but I prefer this syntax:
/ip firewall nat disable [find where comment~"abcdef"]
/ip firewall nat enable [find where comment~"123456"]

# or better

/ip firewall nat
disable [find where comment~"abcdef"]
enable [find where comment~"123456"]
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 725
Joined: Tue Dec 17, 2019 1:08 pm

Re: firewall configuration in Mikrotik

Fri Nov 12, 2021 9:03 pm

As always, thank you @rextended !

Who is online

Users browsing this forum: grayfoxbsd and 43 guests