How the firewall reads rules
a packet to the router itself (Winbox, DNS, ping 192.168.88.1) → the input chain
a packet through the router (computer — internet) → the forward chain
a packet from the router itself → the output chain (empty in the factory config)
In each chain rules are checked top to bottom; the first match with an accept or drop action decides the
packet’s fate. If nothing matches, the packet passes. That’s why the factory firewall ends with denies: whatever wasn’t
allowed above is dropped by the chains’ last rules.
A rule checks connections rather than individual packets: the first packet is new, replies to it are established,
auxiliary packets for it (an ICMP error, FTP data) are related. Once a connection is allowed, the rest of its packets
go through the first rule.
The config, block by block
/interface list
add comment=defconf name=WAN
add comment=defconf name=LAN
/interface list member
add comment=defconf interface=bridge list=LAN
add comment=defconf interface=ether1 list=WANTwo lists are the foundation of the whole firewall: the rules below say “from LAN” and “from WAN”, not “from ether1”. A new home network, PPPoE or a second ISP becomes protected once it’s in its list.
/ip firewall filter
add action=accept chain=input \
comment="defconf: accept established,related,untracked" \
connection-state=established,related,untrackedFirst come replies to what’s already allowed: they pass without further checks. Otherwise every packet would go through the whole chain. untracked are packets with connection tracking turned off in raw; the factory config has none.
add action=drop chain=input \
comment="defconf: drop invalid" \
connection-state=invalidPackets that belong to no connection and don’t open a new one are garbage or someone’s probing. Drop them right away.
add action=accept chain=input \
comment="defconf: accept ICMP" protocol=icmpPinging the router is allowed from anywhere, the internet included: that shows the router is alive. ICMP errors for the router’s own connections — “packet too big”, “unreachable” — pass earlier anyway, as related. You can close ping from outside by adding in-interface-list=LAN, but it adds almost no protection.
add action=accept chain=input \
comment="defconf: accept to local loopback (for CAPsMAN)" \
dst-address=127.0.0.1 in-interface=lo \
src-address=127.0.0.1The router’s internal traffic to itself. CAPsMAN needs it when the router manages its own radio. In 7.22 the rule was tightened: it also checks the lo interface and the source address.
add action=drop chain=input \
comment="defconf: drop all not coming from LAN" \
in-interface-list=!LANThe key rule for the router: nothing that didn’t come from the home network reaches it — not Winbox, SSH, DNS or the web UI. It’s the last in input. Put your own allows above it with place-before; never delete or disable it — the router becomes visible from the internet.
add action=accept chain=forward \
comment="defconf: accept in ipsec policy" \
ipsec-policy=in,ipsec
add action=accept chain=forward \
comment="defconf: accept out ipsec policy" \
ipsec-policy=out,ipsecThese let ipsec-policy traffic through before fasttrack, which would break it. Without configured policies the lines never match — leave them as they are.
add action=fasttrack-connection chain=forward \
comment="defconf: fasttrack" \
connection-state=established,related \
hw-offload=yes
add action=accept chain=forward \
comment="defconf: accept established,related, untracked" \
connection-state=established,related,untracked
add action=drop chain=forward \
comment="defconf: drop invalid" \
connection-state=invalidAlready allowed connections then bypass the firewall, NAT and queues: internet speed depends on this (Wired on MikroTik). Queues don’t see such traffic (Fasttrack and queues). hw-offload=yes only does something on chips with hardware routing; on other models the parameter may be missing from the export.
add action=drop chain=forward \
comment="defconf: drop all from WAN not DSTNATed" \
connection-nat-state=!dstnat in-interface-list=WANThe key rule for the network: a new connection from the internet inward is dropped unless there’s a port forward (dstnat) for it. From inside out anything goes; from outside in, only what’s forwarded. The rule has no connection-state=new: open connections were already let through above. It’s the last in forward — don’t delete it.
/ip firewall nat
add action=masquerade chain=srcnat \
comment="defconf: masquerade" \
ipsec-policy=out,none out-interface-list=WANAddress translation: computers with 192.168.88.x go out to the internet with the router’s address. It works for every interface in the WAN list — that’s why PPPoE and a second ISP must be in it.
/ip neighbor discovery-settings set \
discover-interface-list=LAN
/tool mac-server set allowed-interface-list=LAN
/tool mac-server mac-winbox set \
allowed-interface-list=LANNot the firewall, but the same idea: neighbor discovery and Winbox by MAC address work only on the home network. Without these lines the router can be found and opened by MAC from the ISP’s network.
IPv6 has its own firewall in /ipv6 firewall filter on the same principles: established traffic, ICMPv6, prefix
delegation from the ISP over DHCPv6 and traceroute are allowed; everything else from outside LAN is dropped. IPv6 has
no NAT — every device gets its own public address, and without the “drop everything else not coming from LAN” rule in
the forward chain it can be reached directly from the internet.
Where to put your own rules
| What you need | Chain | Place |
|---|---|---|
| open a port on the router itself (say, its DNS for the guest network) | input |
before “drop all not coming from LAN” |
| block something between your own networks (guests to home) | forward |
after “drop invalid”; the end is fine |
| forward a port to a server at home | /ip firewall nat, dstnat |
nothing to add in filter |
| block an address from the internet | /ip firewall raw or first in input and forward |
in raw it acts before connection tracking, cheaper for the CPU |
Set the place when adding:
/ip firewall filter add chain=input in-interface-list=GUEST protocol=udp dst-port=53 \
action=accept comment="guest: DNS" \
place-before=[find comment="defconf: drop all not coming from LAN"]
If it doesn’t work
Added a port forward rule — the port is closed from outside
- Cause
- A port forward needs nothing in the filter: “drop all from WAN not DSTNATed” lets through connections that went through
dstnat. So the NAT rule didn’t match — a differentin-interface, the wrong protocol or port. Or the ISP gives you a CGNAT address, and nothing from outside can reach the router at all. - Fix
/ip firewall nat print stats— does the rule’s counter grow on an attempt from outside. If the WAN address in/ip addressdiffers from what ifconfig.me shows, you’re behind CGNAT, and a port forward won’t help.
Added an accept for a port on the router, and it’s still closed
- Cause
- The rule landed at the end of the
inputchain — after “drop all not coming from LAN”. Packets never reach it. - Fix
- Move it up:
/ip firewall filter add … place-before=[find comment="defconf: drop all not coming from LAN"], or drag it with the mouse in Winbox.
The router is visible from outside: Winbox, DNS or the web UI answers
- Cause
- “drop all not coming from LAN” was deleted or disabled; or an allow rule without an interface condition sits above it — say, an
acceptfor port 8291 withoutin-interface-list=LAN; or the ISP port ended up in theLANlist. - Fix
/interface list member print—LANholds onlybridgeand home networks,WANholdsether1andpppoe-out1. “drop all not coming from LAN” is the last rule ininputand enabled.
The “drop invalid” counter grows by thousands per minute
- Cause
- Usually asymmetry: replies come back a different way than the requests left — two ISPs without routing rules, or a device on the same network with its own gateway.
- Fix
- Turn on
log=yeson the rule for a minute and look at the addresses in/log print. A little background noise is normal: dropped connections produce a few invalid packets.
How to check
From outside — a port scanner on the router’s address, as in First MikroTik setup: every port filtered. From
inside — the rule counters while the scan runs:
/ip firewall filter print stats
# Columns: CHAIN, ACTION, BYTES, PACKETS
# # CHAIN ACTION BYTES PACKETS
# 5 input drop 184 220 3 102 ← "drop all not coming from LAN" grows
If the last input rule’s counter grows, attempts from outside reach the deny and stop there.