Hey dear team and community I got to know Mikrotik through a friend. And I love it!I would really appreciate a function for copying firewall rules.So that I can copy a rule and then only have to make minimal adjustments to the settings.Or also for other settings such as interfaces, WireGuard, routing rules, or IP routes.That would be great because it would make it even easier to repeat things when setting up networks or VMs from Proxmox. But it also minimizes “problems” in general if you accidentally type something wrong.(I hope RouterOS General is the right topic!)
I just copy the pertinent bits in mmy export config file and then paste back in using the command line interface of terminal in winbox
"Copy" a firewall rule is tricky.
A "function" is stored as a variable (:global typically), and can be use as a "macro" to create new entires. The basic form to create one is:
:global allowAddress do={
/ip/firewall/filter add action=accept chain=input dst-address=$1 place-before=1
}
As shown you can set dst-address based on parameter when function is called. Defining a function, does not run it. So to call it, using a "positional parameter" you'd use:
$allowAddress 127.0.0.1
RouterOS also supports using "named parameters" and conditionals, so you can change the above to control whether the new filter rule is placed first:
:global allowAddress do={
:if ($position > 0) do={
/ip/firewall/filter add action=accept chain=input dst-address=$address place-before=$position
} else={
/ip/firewall/filter add action=accept chain=input dst-address=$address
}
}
Then to use it:
$allowAddress address=127.0.0.1 position=5
These function will be usable until RouterOS reboots. If you want it be available after reboot, you'll need to add it a /system/schedule script that runs at "startup".
And you can use export to figure what commands you want to parameterize in a function. But there is no "copy".
To @anav's point, about config export...
And... If you're doing this more than once, you can also use variables when importing a configuration. So that you can parametrized some configuration using variables at top of the export file to act as a "template" (of sorts).
Often this is easier if you want to "copy with changes" for a new routers, since you can use /system/reset-configuration no-defaults=yes keep-users=yes run-after-reset=paramconfig.rsc to just load the entire config file with any edits stored in variables.
For example, if you want an export from a router you want to then bring load into a new CHR, you can just use that export as a "template" using variable you can in a file before importing via reset-configuration.
# 2025-11-09 02:31:45 by RouterOS 7.20.2
# software id = RGLC-XXXX
#
# model = C52iG-5HaxD2HaxD
# serial number = XXXXX
# customizable variables:
:global ipaddress 10.88.2.1/24
# modified `export` with variables:
... more config
/ip address
add address=$ipaddress comment=defconf interface=bridge
... more config
And then re-use the above for future routers, changing the ipaddress or whatever.
Ah, okay, I didn't know that, but thanks for the quick info. Thanks, I guess that feature is broken then!
Thanks, I love this software!