Guide  →  NAT & Firewall on RouterOS

MikroTik NAT + Firewall:
the reasoning behind the script

The generator builds the config in seconds. This page covers why each rule exists — for any MikroTik gateway, not just PPPoE or Hotspot deployments.

Why masquerade should be scoped to your LAN, not "all traffic"

The simplest NAT rule on RouterOS is a masquerade with no source condition at all — translate everything going out the WAN interface, no exceptions. It works, but it's imprecise: if the router ever gets a second internal network added later (a management VLAN, a second office segment), that traffic gets silently masqueraded too, with no record of where it actually came from.

Scoping the rule to your actual LAN subnetsrc-address=192.168.1.0/24 — means only traffic that's supposed to be there gets translated. It costs nothing in performance and saves a confusing debugging session six months later when a new subnet appears and traffic from it doesn't behave the way the untouched masquerade rule assumed.

Which ports actually get scanned, and why it matters

MikroTik routers with a public IP on the WAN interface get scanned constantly — not because anyone specifically targets a given router, but because RouterOS's management ports sit on the same well-known numbers on every deployment. Bots sweep public IP ranges looking for exactly these:

PortServiceWhy it's a target
8291WinboxFull GUI router management — the highest-value target if compromised.
23TelnetUnencrypted management — credentials visible to anyone on the path.
21FTPFile access to the router's own filesystem.
8728 / 8729API / API-SSLProgrammatic access — used by billing platforms, but only from your own IP, not the WAN.

None of these need to be reachable from the public internet. You manage the router from the LAN, or through a VPN tunnel (WireGuard is the simplest option on modern RouterOS) if you need remote access. Closing them on the WAN interface specifically — not globally — keeps LAN-side management untouched.

SSH is a judgment call: unlike the ports above, SSH has legitimate remote-management use cases and is harder to brute-force meaningfully with a strong key-based login. The generator's hardening option treats it as optional rather than closing it by default.

Port forwarding: the door you're choosing to open

A dst-nat rule that forwards one external port to an internal device — a camera, a small web server — is sometimes necessary, but it's worth being deliberate about it. Every forwarded port is reachable from the entire public internet, not just from you. The generator's port-forwarding block is opt-in and scoped to exactly one port pair for this reason: it should be something you consciously add, not a default.

If you only need occasional access rather than an always-open port, a WireGuard tunnel or a reverse SSH connection is usually a better trade-off than a permanent forward.

How brute-force protection actually works

Closing management ports on the WAN stops most scanning cold, but it's still worth adding a second layer: an address-list rule that tracks repeated connection attempts to router services and temporarily blacklists the source. In RouterOS terms, this is usually two rules working together — one that adds an offending address to a list after repeated attempts, and one earlier in the chain that drops anything already on that list.

This catches what static port-closing alone doesn't: an address hammering a port left open for a legitimate reason (like SSH), or probing before a rule further down the chain would otherwise catch it.

How a packet is actually evaluated

Packet arrives on WAN To router To LAN Input chain Forward chain + NAT Accept established/related Drop invalid Drop WAN mgmt ports Brute-force blacklist check Reaches router service Accept established/related Drop invalid dst-nat (if port forward on) Delivered to internal device LAN device sends a packet out Forward chain → src-nat masquerade → WAN

Reading the generated script

In order, here's what each block in the generator's output does:

BlockPurpose
/ip firewall natMasquerade rule scoped to your LAN subnet, plus an optional dst-nat port-forward if enabled.
/ip firewall filter (input)Accept established/related, drop invalid, then drop the specific WAN-side management ports selected.
Brute-force blockAddress-list rules that blacklist repeated connection attempts before they reach the login prompt.
/ip firewall filter (forward)Same established/related and invalid-drop baseline used in the PPPoE and Hotspot generators — applies regardless of which side traffic originates from.

Test before you trust it: if you manage this router remotely, keep a Winbox or console session open while applying firewall changes for the first time — a misordered rule can lock you out of your own router. Test on a device you can reach physically before relying on this in production.

This generator vs the PPPoE and Hotspot generators

If you're already using the PPPoE generator or Hotspot generator, note that both already include their own baseline firewall rules (established/related accept, invalid drop, optional Winbox/Telnet block). This NAT + Firewall generator is most useful for a standalone gateway that isn't running PPPoE or Hotspot at all, or when you want the extra layers this page covers — scoped masquerade, port forwarding, and brute-force protection — on top of what those two already set up.

Every parameter, explained

FieldAcceptsDefaultNotes
WAN interfaceInterface name (e.g. ether1)ether1The masquerade and hardening rules apply to this interface specifically. Required.
LAN subnetIPv4 CIDR block192.168.1.0/24Scopes the masquerade rule — only traffic from this subnet gets translated.
Port forwarding toggleCheckboxoffEnable only if a specific internal service needs to be reachable from the internet.
External / Internal portNumber, 1–655358080The public-facing port and the port the internal device actually listens on — can differ.
Internal IPIPv4 address192.168.1.100Should fall inside the LAN subnet above.
Block Winbox/Telnet/FTP/APICheckboxonThe single highest-impact hardening option — closes the most commonly scanned ports on the WAN.
Block SSHCheckboxonOptional judgment call — SSH has legitimate remote-access uses, unlike the ports above.
Brute-force protectionCheckboxonAdds address-list rules that blacklist repeated connection attempts.

Full example: hardening a standalone gateway router

A common scenario: a MikroTik router acting as a plain internet gateway for an office LAN, with one internal NVR that needs remote camera access.

FieldValue used
WAN interfaceether1
LAN subnet192.168.1.0/24
Port forwardingEnabled — TCP, external port 8080 → internal 192.168.1.100:8080 (the NVR)
Service hardeningWinbox/Telnet/FTP/API blocked, SSH blocked
Brute-force protectionEnabled

Everything on the router is managed from the LAN or through a WireGuard tunnel — the one forwarded port is deliberately the NVR's port and nothing else.

Common mistakes and how to fix them

SymptomLikely causeFix
Devices on the LAN lose internet after applying the scriptMasquerade rule scoped to the wrong subnet — doesn't match actual LAN addressingConfirm the LAN subnet field matches the router's real internal network exactly
Locked out of Winbox after running the scriptManaging the router through the WAN interface the script just hardenedReconnect from the LAN, or via a VPN tunnel set up before hardening — see the security guide
Forwarded service unreachable from outsideInternal IP or port typo, or the internal device's own firewall blocking the connectionDouble-check the internal IP is correct and the device itself accepts connections on that port
Brute-force rule doesn't seem to block anythingAddress-list timeout too short, or the rule order has the accept rule before the blacklist checkConfirm the blacklist-drop rule appears before any accept rule for the same port in /ip firewall filter print

Best practices

RouterOS version: this generator's output is built and tested against RouterOS v7.x. It hasn't been separately verified against RouterOS v6.

Ready to generate your config?

Fill in your WAN interface and LAN subnet and get a ready-to-import .rsc file in seconds.

Open the generator →