shieldFirewall

circle-info

RouterOS firewall is a powerful packet filtering and manipulation system that provides stateful packet inspection, NAT, traffic shaping, and advanced security features for network protection and traffic control.

In WinBox you can configure firewall in IP -> Firewall, or you can use terminal with command /ip firewall

The RouterOS firewall operates on multiple chains and provides comprehensive control over network traffic through filtering, NAT, and mangle rules.


Firewall fundamentals

How RouterOS firewall works

Core components:

  • Filter rules - Accept, drop, or reject packets based on criteria

  • NAT rules - Network Address Translation for routing and security

  • Mangle rules - Mark packets for QoS and advanced routing

  • Connection tracking - Stateful inspection of network connections

  • Address lists - Dynamic IP address groupings for rules

Processing order:

  1. Raw - Before connection tracking (advanced users)

  2. Mangle - Packet marking and modification

  3. NAT - Address translation

  4. Filter - Accept/drop decisions

  5. Connection tracking - State management throughout


Basic firewall concepts

Chains and processing

RouterOS uses predefined chains for packet processing:

Filter chains:

  • input - Packets destined for the router itself

  • forward - Packets routed through the router

  • output - Packets originating from the router

NAT chains:

  • srcnat - Source NAT (typically for internet access)

  • dstnat - Destination NAT (port forwarding, load balancing)

Mangle chains:

  • prerouting - Before routing decision

  • input - To router (before input filter)

  • forward - Through router (before forward filter)

  • output - From router (before output filter)

  • postrouting - After routing decision

Connection states


Basic firewall configuration

Default secure firewall setup

Essential firewall rules for basic security:

Create address lists

Define network groups for easier rule management:


Advanced filtering rules

Protect against common attacks

Port knocking for enhanced security


Connection tracking and optimization

Connection tracking settings

FastTrack for performance

Enable FastTrack to bypass firewall for established connections:


Service protection

Secure management services

DNS and NTP security


IPv6 firewall basics

IPv6 firewall configuration


Monitoring and logging

Traffic monitoring

Logging configuration


Troubleshooting firewall

Debugging connectivity issues

Performance troubleshooting


Firewall topics

Detailed configurations

This firewall section covers several specialized topics:

  • NAT - Network Address Translation

    • Masquerade for internet sharing

    • Destination NAT for port forwarding

    • Source NAT for network routing

    • Advanced NAT scenarios and load balancing

  • Mangle - Packet marking and manipulation

    • QoS packet marking for traffic shaping

    • Policy-based routing with packet marks

    • Connection marking for bandwidth management

    • Advanced traffic manipulation

  • Layer-7 - Application protocol filtering

    • Deep packet inspection patterns

    • Protocol-specific blocking and shaping

    • Custom protocol detection

    • Application-aware firewall rules


chevron-rightShow complete basic firewall setuphashtag

Best practices

Security recommendations

  1. Default deny policy - Block everything not explicitly allowed

  2. Least privilege - Grant minimum necessary access

  3. Regular monitoring - Watch logs and connection tables

  4. Address list management - Use dynamic lists for threats

  5. Service hardening - Disable unnecessary services

Performance optimization

  1. Use FastTrack - Bypass firewall for established connections

  2. Optimize rule order - Most frequent matches first

  3. Connection limits - Prevent resource exhaustion

  4. Interface lists - Use instead of individual interfaces

  5. Regular cleanup - Remove unused rules and lists

Maintenance tips

  1. Document rules - Use meaningful comments

  2. Version control - Export configurations regularly

  3. Test changes - Verify in lab environment first

  4. Monitor impact - Check performance after changes

  5. Emergency access - Always maintain management access

Last updated

Was this helpful?