DEV Community

parsa shahmohammadi
parsa shahmohammadi

Posted on AI-assisted

MikroTik Firewall Hardening on RouterOS 7: A Safe Baseline (Without Locking Yourself Out)

A MikroTik router with a public IP gets scanned within minutes, just like a server. The usual problems are the same every time: Winbox or SSH open to the internet, the DNS resolver answering the whole world (and being used for DNS amplification attacks), the default admin user, and firmware that hasn't been updated in years.

This guide gives you a RouterOS 7 baseline you can apply to a small office or home-lab router, step by step, in an order that won't cut you off halfway.

Assumptions: ether1 is the WAN (internet) port and bridge is your LAN, as in the default configuration. Change the names to match your router before pasting anything.

Step 0: Turn on Safe Mode first

This one habit prevents most lockouts. In a terminal session press Ctrl+X (in Winbox, click Safe Mode at the top left). While Safe Mode is on, if your session drops because of a change you just made, RouterOS rolls back every change made in that session.

Press Ctrl+X again to leave Safe Mode and keep the changes, once you've confirmed you can still connect.

Step 1: Interface lists

The firewall rules below refer to lists, not ports, so they keep working if you add a second WAN or LAN interface later. If you started from the default configuration, the lists already exist and you can skip this.

/interface list
add name=WAN
add name=LAN
/interface list member
add list=WAN interface=ether1
add list=LAN interface=bridge
Enter fullscreen mode Exit fullscreen mode

Step 2: Protect the router itself (input chain)

The input chain is traffic to the router: Winbox, SSH, DNS, the web UI. The rule is simple: accept what belongs to existing connections, accept the LAN, drop everything else.

/ip firewall filter
add chain=input action=accept connection-state=established,related,untracked comment="input: accept established,related,untracked"
add chain=input action=drop connection-state=invalid comment="input: drop invalid"
add chain=input action=accept protocol=icmp comment="input: accept ICMP"
add chain=input action=accept dst-address=127.0.0.1 comment="input: accept to local loopback (CAPsMAN)"
add chain=input action=drop in-interface-list=!LAN comment="input: drop all not coming from LAN"
Enter fullscreen mode Exit fullscreen mode

The last rule closes Winbox (8291), SSH (22), the web UI, the API and DNS (53) to the internet in one line. If you need remote management, use a VPN (step 5) instead of opening these ports.

Order matters: RouterOS reads the rules top to bottom and stops at the first match. Use /ip firewall filter print and make sure the drop rule is last in the input chain.

Step 3: Protect the LAN (forward chain)

The forward chain is traffic through the router:

/ip firewall filter
add chain=forward action=fasttrack-connection connection-state=established,related hw-offload=yes comment="forward: fasttrack"
add chain=forward action=accept connection-state=established,related,untracked comment="forward: accept established,related,untracked"
add chain=forward action=drop connection-state=invalid comment="forward: drop invalid"
add chain=forward action=drop connection-state=new connection-nat-state=!dstnat in-interface-list=WAN comment="forward: drop all from WAN not DSTNATed"
Enter fullscreen mode Exit fullscreen mode

The last rule means nothing from the internet can open a connection into your LAN unless you created a port forward (dst-nat) for it on purpose.

FastTrack speeds things up but bypasses queues and some firewall features (mangle, simple queues) for the fast-tracked traffic. If you shape bandwidth with queues, remove the first rule.

Step 4: Close the doors you don't use

# services: keep only what you use, and only from the LAN
/ip service
set telnet disabled=yes
set ftp disabled=yes
set www disabled=yes
set api disabled=yes
set api-ssl disabled=yes
set ssh address=192.168.88.0/24
set winbox address=192.168.88.0/24

# layer-2 discovery and MAC access only on the LAN
/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=LAN

# bandwidth test server is a DoS helper if left on
/tool bandwidth-server set enabled=no
Enter fullscreen mode Exit fullscreen mode

Replace 192.168.88.0/24 with your LAN subnet.

DNS: if LAN clients use the router as their DNS server, allow-remote-requests=yes is fine, as long as the input drop rule from step 2 is in place. Without it, your router becomes an open resolver that attackers use to amplify DDoS traffic. This is one of the most common MikroTik misconfigurations on the internet.

Step 5: Remote access through WireGuard, not open ports

RouterOS 7 includes WireGuard. A minimal server side:

/interface wireguard add name=wg-admin listen-port=13231
/ip address add address=10.10.10.1/24 interface=wg-admin
/interface wireguard peers add interface=wg-admin public-key="CLIENT_PUBLIC_KEY" allowed-address=10.10.10.2/32
/interface list member add list=LAN interface=wg-admin

/ip firewall filter
add chain=input action=accept protocol=udp dst-port=13231 comment="input: allow WireGuard" place-before=[find comment="input: drop all not coming from LAN"]
Enter fullscreen mode Exit fullscreen mode

Get the router's public key with /interface wireguard print and put it in your client config. Because wg-admin is in the LAN list, connected admins can reach Winbox and SSH. Nobody else can.

Step 6: Users and updates

/user add name=netadmin group=full password="a-long-unique-password"
Enter fullscreen mode Exit fullscreen mode

Log in as netadmin, check that it works, then remove the default account:

/user remove admin
Enter fullscreen mode Exit fullscreen mode

Then update RouterOS and the RouterBOARD firmware:

/system package update check-for-updates
/system package update install
# after the reboot:
/system routerboard upgrade
/system reboot
Enter fullscreen mode Exit fullscreen mode

Most mass compromises of MikroTik routers (including large botnets) used vulnerabilities that had been patched long before. Updating is the single most effective step on this list.

Step 7: Check from the outside

Your own LAN can't tell you what the internet sees. Check the router's public IP from outside:

  • From a machine outside your network: nmap -Pn -p 22,53,80,443,8291,8728 YOUR_PUBLIC_IP. Everything should show as filtered or closed.
  • Check DNS specifically: dig @YOUR_PUBLIC_IP example.com from outside should time out, not answer.
  • Or use a browser-based open port checker for single ports (Persian interface: enter the IP and port).

Common mistakes

Mistake Result Fix
Adding the input drop rule from a WAN connection You lock yourself out Safe Mode (step 0), or work from the LAN
drop rule placed above the accept rules LAN can't reach the router Check order with /ip firewall filter print
allow-remote-requests=yes without an input firewall Open DNS resolver, used in DDoS attacks Step 2 drop rule
Winbox open to the internet "with a strong password" Brute-force and exploit attempts all day VPN only (step 5)
RouterOS never updated Known, public exploits work Step 6

A shortcut

If you'd rather not assemble the rules by hand, the MikroTik firewall script generator for RouterOS 7 builds a script like the one above from your interface names and options (interface in Persian, output is a standard RouterOS script). Read whatever it produces before you paste it, the same as any script from the internet. For office networks that need more than a baseline (VLANs, multiple WANs, site-to-site VPN), there's also MikroTik configuration as a service.

References: MikroTik: Firewall filter, MikroTik: Securing your router, MikroTik: WireGuard


Parsa Shahmohammadi works with the team at ConfigServer.cloud, which configures and secures Linux servers and MikroTik networks for businesses in Iran.

Top comments (0)