Firewall · Topic 2 of 6

Firewall Filter in Action, Protecting the Router and the Customers

Build RouterOS filter rules that protect the router with the input chain and protect the hosts behind it with the forward chain, using common actions.

  • 5 min
In a nutshell
  • Accept established and related traffic first, then drop invalid traffic.
  • Protect the router in the input chain, and protect the hosts in the forward chain.
  • A final drop at the end of input blocks everything that was not explicitly allowed.

What it is

Filter rules turn the principles of the firewall into real protection.

Two jobs matter most. The first is to protect the router itself, using the input chain. The second is to protect the customers, which means the hosts behind the router, using the forward chain.

Both jobs follow the same pattern: accept the traffic you expect, drop the traffic you do not, and put the rules in the right order.

Internetuntrustedinput chainRouterprotectedforward chainLAN hostsprotected

How it works

Start with the safe replies, add the explicit allows, and finish with a drop for everything else.

Filter actions

ActionUse
acceptAllow the traffic you expect
dropBlock unwanted traffic without any reply
rejectBlock traffic and tell the sender, which suits internal networks
logRecord matching packets, then keep checking rules
passthroughCount matching packets without any other effect

Use drop for traffic from the Internet, because it gives an attacker no information. Use reject on an internal network where users should learn that access was refused.

Protecting the router with the input chain

The input chain sees everything addressed to the router. The usual pattern has five rules.

/ip firewall filter add chain=input connection-state=established,related action=accept comment="allow replies"
/ip firewall filter add chain=input connection-state=invalid action=drop comment="drop invalid"
/ip firewall filter add chain=input protocol=icmp action=accept comment="allow ping"
/ip firewall filter add chain=input in-interface=bridge1 action=accept comment="allow LAN"
/ip firewall filter add chain=input action=drop comment="drop everything else"

Read them from the top:

  1. Replies to traffic that the router started or accepted are allowed.
  2. Packets that belong to no valid connection are dropped.
  3. ICMP is allowed so that ping and path discovery keep working.
  4. Traffic from the LAN interface is accepted, so the administrator can still manage the router.
  5. Everything else is dropped. This is the rule that does the real protecting.

The order is critical. The final drop must come last, or it blocks the allow rules below it.

Watch out

Adding a final drop in the input chain before an allow rule for your own access can lock you out of the router, so use Safe Mode or keep a second session open.

You can narrow the allow rules further. For instance, allow management only from one address list instead of the whole LAN.

Protecting the customers with the forward chain

The forward chain sees traffic that crosses the router. The goal is to stop unwanted traffic from reaching the LAN while letting replies and LAN initiated traffic through.

/ip firewall filter add chain=forward connection-state=established,related action=accept
/ip firewall filter add chain=forward connection-state=invalid action=drop
/ip firewall filter add chain=forward connection-state=new connection-nat-state=!dstnat in-interface=ether1 action=drop

The first rule lets replies and related traffic through. The second drops invalid packets. The third drops new connections that arrive from the WAN, except those that were created by a destination NAT rule.

The connection-nat-state=!dstnat condition keeps port forwarding working. Without it, the drop rule would also block the servers that you published on purpose.

New connections that come from the LAN are not matched by that drop, so the LAN hosts can still reach the Internet.

Blocking unwanted services for customers

You can also block specific services in the forward chain. For example, a rule can drop file sharing ports that should never cross to the Internet.

/ip firewall filter add chain=forward protocol=tcp dst-port=135-139,445 out-interface=ether1 action=drop

A rule like this belongs above the general accept rules for LAN traffic, so that it is checked first.

Checking the rules

Use the counters to confirm that the rules work as you intend.

/ip firewall filter print stats

The drop rule at the end of input should show a growing counter if the Internet is probing the router. If it stays at zero, either no traffic reaches it, or an earlier rule is accepting it.

Exam tip

Add a log rule just before a final drop while testing, and remove it afterwards so the log does not fill up.

What to remember for the exam

Seven facts cover this topic.

  • Accept established and related traffic first, then drop invalid traffic.
  • Protect the router in the input chain, and protect the hosts in the forward chain.
  • A final drop at the end of input blocks everything that was not explicitly allowed.
  • Drop gives no reply, and reject sends an error to the sender.
  • connection-nat-state=!dstnat keeps published servers reachable.
  • Rule order decides the result, and the first match wins.
  • Counters from /ip firewall filter print stats show whether a rule is used.

Common mistakes

These four mistakes are common.

Locking yourself out. A final drop in input without an allow for your own address cuts off management.

Placing the drop first. The allow rules below it never match.

Blocking port forwarding by accident. Without the dstnat exception, a forward drop also blocks published servers.

Protecting only one chain. The input chain protects the router, and the forward chain protects the hosts, so both need rules.

Check yourself

Work through these three questions.

  • Why do the first input rules accept established and related traffic?

    They let replies to allowed connections through. The rest of the rules then focus on who may start new connections.

  • What does the drop rule with connection-nat-state=!dstnat do in the forward chain?

    It drops new connections from the WAN that were not created by a destination NAT rule. Published servers stay reachable and other new connections from the Internet are blocked.

  • Why must the final drop come last?

    Rules are checked from the top and the first match wins. A drop placed earlier would block the allow rules below it.

Topic 2 of 6 in Firewall

Test yourself on Firewall

The full MikroTik MTCNA question bank has 558 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by MikroTik. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.