I’m writing a script for my RB5009ug. The assumption is that the script gets applied on a freshly-reset device, on top of the default configuration.
One of the script’s objectives is to configure the firewall. My (naive?) plan was to first remove all default rules/chains and then recreate them from scratch.
Incidentally, I wish the script could be applied on a blank device instead of on top of existing defaults. Working on a blank device would be more robust and cleaner as the final state of the device would be completely described by a single file (a purely declarative approach). Contrarily, working on top of existing defaults means that the script may first have to undo some of the defaults and then apply its changes. The result is no longer determined by a single file, rather by the interaction of the script plus the defaults. This makes things more brittle, for example should the defaults change over time. I might be wrong but I understand that the purely declarative approach is not possible?
I’use theses commands to bootstrap every rb5009 i deploy ; the goal is to remove everything and have a dedicated outofband eth for mgmt (and this one is securised after). And now, i lost a time with the fuc___g default password.
After that, i use the newly created outofband mgmt port and inject the main configuration generated for this dev, reboot it, and it’s ready to use.
plan was to first remove all default rules/chains - that’s a bad idea!
Don’t write any long scripts, don’t complicate the whole configuration. Default rules are used for everything. If you don’t like the default config, then I can recommend another version - drop everything and allow only what is needed. This is good practice.
If, for example, it is necessary to open a port for Wiregurd, then we do it in “Input chain”. If there is a need to release a port through the router, then we do it in the “forward” chain. And we must use the address list. It should be remembered that in Mikrotik the firewall policy is executed from top to bottom. Sequence is also important.
INPUT CHAIN → To the Router or to Router Services. Directional flow is WAN to Router, and LAN to Router.
FORWARD CHAIN → Through the Router. Direction flow is LAN to LAN, LAN to WAN, WAN to LAN.
OUTPUT CHAIN → From the Router. Directional flow is Router to WAN.
Ok, I understand. I think I’ll follow your advice. (I suppose it’s then a matter of adding new rules while specifying the correct position with ‘place-before’ then.)
Hi, thanks so much! Your script has been very helpful, I’ve taken inspiration from various of its parts. In the end I may abandon the idea of nuking the default configuration to the ground, rather I think I’ll apply more targeted changes on top of defconf.
I’m still in the process of understanding the whole RouterOS workflow, I’d have hoped for a more declarative approach, but it is what it is.