Back to blog

MikroTik / RouterOS  ·  Security Rules  ·  November 2026

Firewall Rule Order,
Jump Chains & Performance

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.

RouterOS Firewall Jump Chains Address Lists Performance RAW Auditing

FLAT: every new packet walks the whole list rule 40: drop · guest packet checked 39 times first STRUCTURED: decide the direction once, then a short list forward est/rel · invalidjump → lan-wanjump → guestjump → wan-in lan-wan · 4 rulesguest · 3 ruleswan-in · 2 rules a guest packet now meets at most 6 rules, and each sub-chain reads like a policy

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.

Prerequisites

01

How RouterOS Walks a Chain

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.

ActionWhat happens to the packet
accept / drop / rejectDecision made; nothing below in this chain is evaluated.
jump jump-target=XEvaluated in chain X from the top. If X ends without a decision, the packet comes back to the rule after the jump.
returnLeave the current user chain now and continue after the jump that brought the packet here.
log, add-src-to-address-list, passthroughSide 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

Find the Rules That Never Fire

Counters are the only honest description of a firewall. Reset them, wait a week, and read what is actually doing the work.

RouterOS — reset, wait, read the counters Safe to Run
/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.

RouterOS — a classic shadow
# 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
⚠ Gotcha — Dynamic rules are counted too

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

Jump Chains: Decide the Direction Once

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.

RouterOS — a forward chain of jumps
/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.

⚠ Gotcha — A sub-chain without a final decision returns

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

One Rule, Many Addresses

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.

RouterOS — lists instead of copies
/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
⚠ Gotcha — Don't put 100.64.0.0/10 in bogons behind Starlink

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

Measure Before You Optimise

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.

RouterOS — is the firewall what costs CPU? Safe to Run
/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 seeDo this
firewall high, chains longJump chains (section 3); move the busiest accepts up; lists instead of copies.
firewall high, mostly established trafficFastTrack for LAN↔WAN, if there is no queue or mangle that needs it (see the firewall post).
Huge bulk flows between two internal VLANsaction=notrack in RAW for exactly that pair (below).
Connection table near max-entriesA flood, or a misbehaving client: lower UDP timeouts, drop in RAW, find the source.
RouterOS — skip tracking for one trusted bulk flow
# 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
⚠ Gotcha — notrack means no state and no NAT

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

A Layout Someone Else Can Review

Six months from now the person reading this firewall will be you, under pressure. Write it for them.

ConventionWhy
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 dropAnyone 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 endA 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.
RouterOS — the change routine
# 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
💡 The Cisco side of the same idea

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

Verify It

Prove the reorganised firewall makes the same decisions as the old one, before anyone notices you changed it.

TestExpected
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 fixDropped by the specific rule, which now has hits.
print stats one week laterNo unexplained zero-hit rules; guards commented.
/tool profile at peakFirewall share lower than before, or unchanged on a router that never needed tuning.

Takeaways

  1. First match wins. A broad accept above a narrow drop means the drop never runs; counters show it.
  2. Zero hits after a week is a question: shadowed, obsolete or a guard. Comment the guards.
  3. Jump chains decide the direction once and turn the firewall into short, readable policies. End every sub-chain with a decision.
  4. Lists, not copies. An address or interface list changes in one place and new members inherit the policy.
  5. Measure first. /tool profile tells you whether the firewall costs anything before you optimise it.
  6. notrack is a scalpel. No state, no NAT: only for named internal flows, both directions.

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.

Does anyone know why your firewall rules are there?

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 →