Plenty of RouterOS firewalls work, but nobody can say why. They grew one rule at a time: a broad accept that shadows the drop added later, the same interface match copied into thirty rules, a forgotten server still allowed. This post is about the structure: reading counters, finding what never fires, jump chains, lists, and measuring whether the firewall even costs anything.
The RouterOS firewall, properly built the two chains from first principles. This post assumes that firewall exists and asks the next questions: is every rule still needed, is it in the right place, and could someone else read it?
The tools are all built in: per-rule counters, jump chains, address and interface lists, /tool profile and RAW. None of them change what the firewall allows. They change whether you can trust that it does what you think.
01
First match wins, and every rule above the match is a cost paid by every packet that reaches it. Order is both correctness and performance.
A filter chain is read top to bottom. The first rule whose matchers all fit decides the packet with accept, drop, reject, or hands it elsewhere with jump and return. A rule that only logs, or only adds to an address list, lets the packet continue to the next rule. Everything that follows comes from those few facts.
| Action | What happens to the packet |
|---|---|
| accept / drop / reject | Decision made; nothing below in this chain is evaluated. |
| jump jump-target=X | Evaluated in chain X from the top. If X ends without a decision, the packet comes back to the rule after the jump. |
| return | Leave the current user chain now and continue after the jump that brought the packet here. |
| log, add-src-to-address-list, passthrough | Side effect only; the packet carries on to the next rule. |
Two consequences matter in practice. A broad accept placed early shadows every narrower rule below it, so those rules never fire and their counters stay at zero. And since only connection-state=new packets usually get past the first two rules, the length of the chain they walk is what costs CPU on a busy router.
02
Counters are the only honest description of a firewall. Reset them, wait a week, and read what is actually doing the work.
/ip firewall filter reset-counters-all # ...a normal business week later: /ip firewall filter print stats where chain=forward # Flags: X - disabled, I - invalid; D - dynamic # # CHAIN ACTION BYTES PACKETS # 0 D forward passthrough ... ... <- the dummy FastTrack counter rule # 1 forward fasttrack-connection 91 GiB 71 834 112 # 2 forward accept 3 214 MiB 4 102 774 # 3 forward drop 88 KiB 1 207 # 7 forward accept 0 0 <- why is this here? # 12 forward drop 0 0 <- shadowed, or nothing ever tries
A rule at zero after a week is one of three things: shadowed by a broader rule above it, obsolete (the server it allowed was retired), or a guard that should stay at zero, like "drop guest to CCTV". Comment the guards so nobody deletes them, and investigate the rest.
# rule 4 accepts all TCP from the staff VLAN... add chain=forward in-interface=vlan20-staff protocol=tcp action=accept # ...so rule 9, written later to block staff from the CCTV NVR, never matches add chain=forward in-interface=vlan20-staff dst-address=10.0.40.10 action=drop \ comment=staff-no-nvr # fix: move the specific drop above the broad accept /ip firewall filter move [find comment="staff-no-nvr"] destination=4
The D rule at the top of the forward chain is the dummy that RouterOS adds to show FastTrack counters; it is not yours and can't be moved. Rules added by scripts or by features such as Hotspot also appear as dynamic. Leave them out when you decide what is dead.
03
Instead of forty rules that each repeat in-interface and out-interface, ask once where the packet is going and hand it to a short chain written for exactly that case.
/interface list
add name=WAN
add name=LAN
add name=GUEST
/ip firewall filter
add chain=forward connection-state=established,related,untracked action=accept
add chain=forward connection-state=invalid action=drop
add chain=forward in-interface-list=LAN out-interface-list=WAN action=jump \
jump-target=lan-wan comment="LAN to internet"
add chain=forward in-interface-list=GUEST action=jump jump-target=guest
add chain=forward in-interface-list=WAN action=jump jump-target=wan-in
add chain=forward action=drop comment="anything not routed into a sub-chain"
# each sub-chain is a small, readable policy
add chain=guest out-interface-list=WAN protocol=tcp dst-port=80,443 action=accept
add chain=guest out-interface-list=WAN protocol=udp dst-port=53,443 action=accept
add chain=guest action=drop comment="guests: web and DNS out, nothing else"
add chain=wan-in connection-nat-state=dstnat action=accept comment="port forwards"
add chain=wan-in action=drop
add chain=lan-wan src-address-list=no-internet action=drop
add chain=lan-wan action=accept
Each sub-chain ends in its own decision, so a packet never falls back into the main chain by accident. The final drop in forward catches anything that matched none of the jumps: a new interface nobody added to a list, or traffic between two LAN VLANs that should go through its own sub-chain when it is needed.
If guest ended after its two accepts, a guest packet to the CCTV subnet would fall off the end of guest, return to forward, continue to the next jump, and possibly be accepted further down. End every sub-chain with an explicit drop or accept, even when it looks redundant.
04
When the same match appears in more than one rule, it belongs in an address list or an interface list. The firewall becomes data you edit, not code you rewrite.
/ip firewall address-list
add list=mgmt address=10.0.99.0/24 comment="management VLAN"
add list=mgmt address=10.10.10.0/24 comment="WireGuard admins"
# a DNS name is resolved and kept current by the router itself
add list=payment address=payments.example-processor.com
add list=bogons address=0.0.0.0/8
add list=bogons address=100.64.0.0/10
add list=bogons address=169.254.0.0/16
add list=bogons address=192.0.2.0/24
/ip firewall filter
add chain=input src-address-list=mgmt protocol=tcp dst-port=22,8291 action=accept
Starlink and many 4G providers give the router a CGNAT address from 100.64.0.0/10, and the gateway sits in that range too. A bogon drop on WAN input or in RAW that includes it cuts the router off from its own ISP. Keep the list per site: include 100.64/10 on fibre with a public address, leave it out on CGNAT links.
Interface lists do the same for interfaces. A rule that says in-interface-list=LAN keeps working when a new VLAN is added to the list, where in-interface=vlan20 would silently leave the new VLAN out of a policy.
05
Most routers never need firewall tuning. The ones that do show it plainly, and the fix is usually to make fewer packets reach the filter at all.
/tool profile duration=10s # NAME CPU USAGE # networking all 18% # firewall all 41% <- now it's worth reading on # ethernet all 6% /ip firewall connection tracking print # total-entries: 48 112 max-entries: 524 288 /ip firewall connection print count-only where connection-state=new
| If you see | Do this |
|---|---|
| firewall high, chains long | Jump chains (section 3); move the busiest accepts up; lists instead of copies. |
| firewall high, mostly established traffic | FastTrack for LAN↔WAN, if there is no queue or mangle that needs it (see the firewall post). |
| Huge bulk flows between two internal VLANs | action=notrack in RAW for exactly that pair (below). |
| Connection table near max-entries | A flood, or a misbehaving client: lower UDP timeouts, drop in RAW, find the source. |
# nightly backup: NAS (VLAN 12) to the off-site replica router, 400 GB /ip firewall raw add chain=prerouting src-address=10.0.12.20 dst-address=10.0.200.0/24 action=notrack add chain=prerouting src-address=10.0.200.0/24 dst-address=10.0.12.20 action=notrack # untracked packets must be accepted explicitly in filter (defconf already does) /ip firewall filter add chain=forward connection-state=established,related,untracked action=accept \ place-before=0
Untracked traffic is not stateful-filtered, not NATed and not FastTracked. Use it only between internal networks you trust, for both directions, and keep the filter rule that accepts untracked narrow if the rest of the network shouldn't inherit it.
06
Six months from now the person reading this firewall will be you, under pressure. Write it for them.
| Convention | Why |
|---|---|
Every rule has a comment= that states intent, not mechanics | "guests: web only" survives a review; "tcp 80,443" doesn't say whether that was the goal. |
| Fixed order: state → invalid → jumps → final drop | Anyone can find where a new rule goes. |
| Guards commented as guards | "GUARD: guest→CCTV, expected 0 hits" stops someone deleting a zero-counter rule that is doing its job. |
Add with place-before=, never at the end | A rule added after the final drop is a rule that never runs. |
| Export and diff before and after every change | /ip firewall export terse gives one line per rule: easy to diff, easy to store. |
# Safe Mode (Ctrl+X) first; a lost session rolls everything back /ip firewall export terse file=fw-before /ip firewall filter add place-before=[find comment="FINAL DROP forward"] \ chain=lan-wan dst-address-list=blocked-sites action=drop \ comment="block list for staff, ticket #214" /ip firewall export terse file=fw-after # compare the two on your laptop, then leave Safe Mode to commit
On IOS, the counters are show access-lists hit counts and show policy-map type inspect zone-pair; object-groups play the part of address lists; and zone-based firewall is already "decide the direction once": each zone-pair is a sub-chain. The habits translate one to one: comment intent, keep guards, read counters before deleting.
07
Prove the reorganised firewall makes the same decisions as the old one, before anyone notices you changed it.
| Test | Expected |
|---|---|
| Guest laptop: browse, then ping 10.0.40.10 (NVR) | Web works; ping fails; the guard in guest counts the attempt. |
| Staff PC to the NVR after the shadow fix | Dropped by the specific rule, which now has hits. |
print stats one week later | No unexplained zero-hit rules; guards commented. |
/tool profile at peak | Firewall share lower than before, or unchanged on a router that never needed tuning. |
Takeaways
/tool profile tells you whether the firewall costs anything before you optimise it.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 audit RouterOS firewalls from their counters and exports, remove what never fires, and leave behind a structure your next engineer can read.
Book a Discovery Call →