beginner

Firewall and NAT in RouterOS 7

Learn how to secure your MikroTik router and configure Network Address Translation (NAT).

45-60 min

Firewall and NAT in RouterOS 7

A factory-default RouterOS device has an empty firewall (unless you used the default configuration script). Before connecting any router to the public internet, you must implement basic firewall filters and configure Network Address Translation (NAT) so internal devices can route externally.

1. Network Address Translation (NAT)

NAT is configured under /ip firewall nat. The two most common types are Source NAT (for internet access) and Destination NAT (for port forwarding).

Source NAT (Masquerade)

To allow LAN devices to access the internet, their private IP addresses must be translated (masqueraded) behind the router’s public WAN IP.

/ip firewall nat
add chain=srcnat out-interface=ether1 action=masquerade comment="Default Masquerade"
  1. Go to IPFirewallNAT tab.
  2. Click [+].
  3. On the General tab, set Chain to srcnat.
  4. Set Out. Interface to your WAN port (e.g., ether1).
  5. On the Action tab, set Action to masquerade. Click OK.

Destination NAT (Port Forwarding)

To allow internet users to access an internal server (like a web server on 192.168.88.50:80).

/ip firewall nat
add chain=dstnat in-interface=ether1 protocol=tcp dst-port=80 action=dst-nat to-addresses=192.168.88.50 to-ports=80 comment="Forward HTTP"
  1. Go to IPFirewallNAT tab. Click [+].
  2. Chain: dstnat.
  3. Protocol: tcp, Dst. Port: 80.
  4. In. Interface: ether1.
  5. On the Action tab, set Action to dst-nat.
  6. To Addresses: 192.168.88.50, To Ports: 80. Click OK.

2. Firewall Filter Rules

RouterOS processes firewall rules from top to bottom. The first rule that matches a packet is executed, and subsequent rules are ignored. Therefore, rule order is critical.

There are three primary chains:

  • Input: Traffic destined to the router itself (e.g., WinBox, Ping, SSH).
  • Forward: Traffic passing through the router (e.g., LAN to Internet).
  • Output: Traffic originating from the router itself.

Basic Input Rules (Protecting the Router)

/ip firewall filter
add chain=input connection-state=established,related,untracked action=accept comment="Accept established/related"
add chain=input connection-state=invalid action=drop comment="Drop invalid"
add chain=input in-interface=ether1 action=drop comment="Drop all other WAN input"
  1. Go to IPFirewallFilter Rules tab.
  2. Accept Established/Related: Click [+]. Chain: input. Connection State: check established, related, untracked. Action: accept.
  3. Drop Invalid: Click [+]. Chain: input. Connection State: check invalid. Action: drop.
  4. Drop WAN Input: Click [+]. Chain: input. In. Interface: ether1. Action: drop.

Basic Forward Rules (Protecting the LAN)

/ip firewall filter
add chain=forward connection-state=established,related,untracked action=accept comment="Accept established/related"
add chain=forward connection-state=invalid action=drop comment="Drop invalid"

# Optional: If using Port Forwarding, you must explicitly accept DST-NAT'd traffic
add chain=forward connection-nat-state=dstnat action=accept comment="Accept Port Forwards"

add chain=forward in-interface=ether1 action=drop comment="Drop all other WAN forward"
  1. Accept Established/Related (Forward): Click [+]. Chain: forward. Connection State: check established, related, untracked. Action: accept.
  2. Drop Invalid (Forward): Click [+]. Chain: forward. Connection State: check invalid. Action: drop.
  3. Accept Port Forwards: Click [+]. Chain: forward. Connection NAT State: check dstnat. Action: accept.
  4. Drop WAN Forward: Click [+]. Chain: forward. In. Interface: ether1. Action: drop.

Tip: Drag and drop rules in WinBox to reorder them, making sure your ‘Accept’ rules are at the top and the ‘Drop’ rules are at the bottom of their respective chains.