Forum threads are full of RouterOS rules that ban scanners, hide Winbox behind a secret knock and blacklist brute-forcers for weeks. Some of them help. Some of them hide a service that shouldn't be exposed in the first place, and one of them, fed spoofed packets, will happily block your own DNS resolver. This post builds each mechanism properly and then asks what it is actually protecting.
Address lists with timeouts make the RouterOS firewall self-updating: a rule notices something and adds the source to a list, another rule acts on the list. The same primitive powers brute-force traps, scan detection and port knocking.
Each of those is easy to build and easy to overrate. This post builds them correctly, shows how each can fail or be abused, and ends with the one change that makes most of them unnecessary: management only over WireGuard.
01
Every dynamic defence on RouterOS is the same trick: a rule that adds the source to an address list with a timeout, and another rule that matches the list.
# side effect only: the packet continues to the next rule add chain=input protocol=tcp dst-port=22 connection-state=new \ action=add-src-to-address-list address-list=ssh_seen address-list-timeout=1m # a later rule (or an earlier one, on the next packet) acts on membership add chain=input src-address-list=ssh_seen ... /ip firewall address-list print where list=ssh_seen
The firewall post already uses it for the staged SSH trap. This post looks at three bigger uses, port-scan detection, port knocking and connection limits, and at the question that post left open: when is any of this worth having?
02
RouterOS can score a source by how many ports it touches in a short time and list it. It works, and it can be turned against you.
/ip firewall address-list
add list=never-block address=10.0.0.0/8 comment="our own networks"
add list=never-block address=9.9.9.9 comment="DNS resolver"
add list=never-block address=203.0.113.50 comment="monitoring server"
/ip firewall raw
add chain=prerouting in-interface-list=WAN src-address-list=port_scanners action=drop
/ip firewall filter
# psd = weight threshold, delay threshold, low-port weight, high-port weight
add chain=input in-interface-list=WAN protocol=tcp psd=21,3s,3,1 \
src-address-list=!never-block action=add-src-to-address-list \
address-list=port_scanners address-list-timeout=1d
With these values a source that touches seven privileged ports (weight 3 each) or 21 high ports within three seconds is listed for a day, and RAW drops it before connection tracking spends anything on it.
PSD scores the source address of TCP packets, and a SYN's source is trivial to forge. Anyone who knows the trap exists can send a burst of SYNs "from" your DNS resolver, your monitoring server or your upstream's gateway and make the router drop them for a day. That is why never-block exists, why the timeout is one day and not two weeks, and why PSD belongs only on WAN-facing input where nothing important arrives unsolicited.
On Starlink or most 4G, unsolicited traffic never reaches the router's IPv4 WAN at all. Scan detection there only protects IPv6, which needs the rules in /ipv6 firewall (see dual-stack parity).
03
A secret sequence of packets that opens the management port for your address only. Clever, cheap, and weaker than it looks.
/ip firewall filter
add chain=input in-interface-list=WAN protocol=udp dst-port=41231 \
action=add-src-to-address-list address-list=knock1 address-list-timeout=10s
add chain=input in-interface-list=WAN protocol=udp dst-port=17702 src-address-list=knock1 \
action=add-src-to-address-list address-list=knock2 address-list-timeout=10s
add chain=input in-interface-list=WAN protocol=udp dst-port=29013 src-address-list=knock2 \
action=add-src-to-address-list address-list=knocked address-list-timeout=1h
add chain=input in-interface-list=WAN protocol=tcp dst-port=8291 src-address-list=knocked \
action=accept comment="Winbox after the knock"
# these rules go above the final input drop; the knocks themselves are dropped by it
| Weakness | What it means in practice |
|---|---|
| The sequence travels in clear | Anyone on the path (the hotel Wi-Fi you knocked from, an ISP, a compromised router) sees three UDP ports and can replay them. |
| It opens an address, not a person | Knock from a hotel, an airport or any CGNAT network and everybody behind that public address gets Winbox for an hour. |
| Out-of-order and noise | A scan that happens to hit the first port resets nothing; a careless sequence can be stumbled into. |
| What it protects is still Winbox | Behind the knock sits a service with a history of pre-auth vulnerabilities. Knocking hides it; it doesn't fix it. |
A WireGuard interface sends nothing back to a packet that isn't signed by a known peer key, so it is invisible to scanners like a knock, and it is authenticated, encrypted and tied to a key rather than an address. Accept UDP for WireGuard on the WAN, accept management only from the WireGuard interface, and the knock becomes unnecessary.
04
Ten lines that make every dynamic trap on the management ports unnecessary.
/interface wireguard add name=wg-admin listen-port=13231
/interface wireguard peers add interface=wg-admin public-key="<laptop public key>" \
allowed-address=10.10.10.2/32 comment="admin laptop"
/ip address add address=10.10.10.1/24 interface=wg-admin
/interface list member add list=MGMT interface=wg-admin
/ip firewall filter
add chain=input in-interface-list=WAN protocol=udp dst-port=13231 action=accept \
comment="WireGuard: silent to anything unsigned" \
place-before=[find comment="FINAL DROP input"]
add chain=input in-interface-list=MGMT action=accept \
place-before=[find comment="FINAL DROP input"]
/ip service set winbox address=10.10.10.0/24,10.0.99.0/24
/ip service set ssh address=10.10.10.0/24,10.0.99.0/24
Behind CGNAT nothing can reach UDP 13231 on the router. Turn it around: the router dials out to a small cloud VPS or a fixed-IP site that acts as the WireGuard hub, with persistent-keepalive so the CGNAT mapping stays open, and admins connect to the hub.
05
Not a trap, just arithmetic: no single source should hold hundreds of connections to the router.
/ip firewall filter # more than 10 simultaneous TCP connections from one /32 to the router: drop add chain=input protocol=tcp connection-limit=10,32 action=drop \ comment="per-source cap" place-before=[find comment="FINAL DROP input"] # DNS for the LAN: limit new queries per source, protects the resolver from a looping client add chain=input in-interface-list=LAN protocol=udp dst-port=53 connection-state=new \ dst-limit=50,100,src-address/1m action=accept add chain=input in-interface-list=LAN protocol=udp dst-port=53 connection-state=new \ action=drop
connection-limit counts tracked connections per source mask; dst-limit is a token bucket per source (here 50 per second with a burst of 100). Neither needs a list, so neither can be poisoned with spoofed sources the way PSD can.
06
Each mechanism is good at one thing. Pointed at the wrong problem, it adds complexity and a new way to lock yourself out.
| Threat | Theatre | What actually helps |
|---|---|---|
| Password guessing on SSH/Winbox from the internet | Staged brute-force lists on a service that shouldn't be exposed | Not exposing it: WireGuard (section 4); keys for SSH; services limited by address= |
| Internet-wide scanning | PSD on a CGNAT link, two-week blacklists | A default-deny input chain; nothing listening on the WAN |
| Winbox pre-auth bugs | Port knocking in front of an unpatched router | Upgrades on the long-term channel, and Winbox off the internet |
| A looping or infected LAN client flooding the router | nothing | connection-limit, dst-limit |
| Floods towards a public service | blacklists of spoofed sources | RAW drops of bogons, upstream filtering, a CDN for the service |
IOS has its own versions of each: login block-for 120 attempts 3 within 60 with a login quiet-mode access-class for admins (the brute-force trap), dynamic ACLs or "lock-and-key" (an older relative of port knocking, with the same weaknesses), and parameter-map type inspect limits on half-open sessions in zone-based firewall (the connection limit). The verdict is the same: keep management off the internet and the traps matter much less.
07
Trigger every mechanism from a test host, and make sure you can still get in.
| Test | Expected |
|---|---|
nmap -Pn -p 1-1024 <router WAN> from a VPS | The VPS appears in port_scanners; further probes are dropped in RAW. |
Spoof a scan from a never-block address in the lab | Not listed. |
| Knock from a phone hotspot, then Winbox | Winbox opens for that public address only, for one hour. |
| WireGuard admin laptop off-site | Winbox and SSH work through the tunnel; nothing answers on the WAN. |
| Open 20 SSH sessions from one LAN host | The eleventh is dropped; the counter on the cap rule increments. |
Takeaways
Part of a set on RouterOS security rules: rule order & performance · dual-stack parity · dynamic defences · templates for villas, shops & hotels. Foundations: the RouterOS firewall, properly.
I review RouterOS edges for exposed services and self-inflicted traps, and move management behind WireGuard without anyone losing access.
Book a Discovery Call →