Bookmark

MikroTik Firewall Filter Rules for Better Security

MikroTik security problems often come from configuration mistakes: unchanged admin passwords, weak credentials, factory-reset devices, or unnecessary SSH and Telnet services left enabled. These settings can allow attackers to take control of the router or use it for abuse.

The following filter rules are collected from public references. Review every rule against your own RouterOS version and network before applying it.

Copy each command and paste it into the Terminal in WinBox.

Memcrashed — major amplification attacks from UDP port 11211
/ip firewall filter add chain=forward dst-port=11211 protocol=udp action=drop comment="Memcrashed - Amplification Attacks UDP 11211"
Anti-DDoS attacks
/ip firewall filter add chain=forward connection-state=new action=jump jump-target=block-ddos comment="Anti DDoS Attacks" add chain=forward connection-state=new src-address-list=ddoser dst-address-list=ddosed action=drop add chain=block-ddos dst-limit=50,50,src-and-dst-addresses/10s action=return add chain=block-ddos action=add-dst-to-address-list address-list=ddosed address-list-timeout=10m add chain=block-ddos action=add-src-to-address-list address-list=ddoser address-list-timeout=10m
Block IP and port scanners
/ip firewall filter # Add port scanners to an address list. add chain=input protocol=tcp psd=21,3s,3,1 action=add-src-to-address-list address-list="port scanners" address-list-timeout=2w comment="Mark Source ip port scanner to Address list " disabled=no # NMAP FIN stealth scan. add chain=input protocol=tcp tcp-flags=fin,!syn,!rst,!psh,!ack,!urg action=add-src-to-address-list address-list="port scanners" address-list-timeout=2w comment="NMAP FIN Stealth scan" # SYN/FIN scan. add chain=input protocol=tcp tcp-flags=fin,syn action=add-src-to-address-list address-list="port scanners" address-list-timeout=2w comment="SYN/FIN scan" # SYN/RST scan. add chain=input protocol=tcp tcp-flags=syn,rst action=add-src-to-address-list address-list="port scanners" address-list-timeout=2w comment="SYN/RST scan" # FIN/PSH/URG scan. add chain=input protocol=tcp tcp-flags=fin,psh,urg,!syn,!rst,!ack action=add-src-to-address-list address-list="port scanners" address-list-timeout=2w comment="FIN/PSH/URG scan" # ALL/ALL scan. add chain=input protocol=tcp tcp-flags=fin,syn,rst,psh,ack,urg action=add-src-to-address-list address-list="port scanners" address-list-timeout=2w comment="ALL/ALL scan" # NMAP NULL scan. add chain=input protocol=tcp tcp-flags=!fin,!syn,!rst,!psh,!ack,!urg action=add-src-to-address-list address-list="port scanners" address-list-timeout=2w comment="NMAP NULL scan" # Drop port scanners. add chain=input src-address-list="port scanners" action=drop comment="Drop port scanners" disabled=no
Anti-brute-force attack
/ip firewall filter # Drop FTP brute-force sources. add action=drop chain=input comment="drop ftp BRUTE FORCErs" dst-port=21 protocol=tcp src-address-list=ftp_blacklist add action=accept chain=output content="530 Login incorrect" dst-limit=1/1m,9,dst-address/1m protocol=tcp add action=add-dst-to-address-list address-list=ftp_blacklist address-list-timeout=3h chain=output content="530 Login incorrect" protocol=tcp # Drop SSH/Telnet brute-force sources. add action=drop chain=input comment="drop ssh BRUTE FORCErs" dst-port=22-23 protocol=tcp src-address-list=ssh_blacklist add action=add-src-to-address-list address-list=ssh_blacklist address-list-timeout=1w3d chain=input connection-state=new dst-port=22-23 protocol=tcp src-address-list=ssh_stage3 add action=add-src-to-address-list address-list=ssh_stage3 address-list-timeout=1m chain=input connection-state=new dst-port=22-23 protocol=tcp src-address-list=ssh_stage2 add action=add-src-to-address-list address-list=ssh_stage2 address-list-timeout=1m chain=input connection-state=new dst-port=22-23 protocol=tcp src-address-list=ssh_stage1 add action=add-src-to-address-list address-list=ssh_stage1 address-list-timeout=1m chain=input connection-state=new dst-port=22-23 protocol=tcp add action=drop chain=forward comment="drop ssh brute downstream" dst-port=22-23 protocol=tcp src-address-list=ssh_blacklist

Also disable services that are not needed under IP > Services. Test rules carefully and keep a console or safe management path available before applying firewall changes.

If you have useful firewall rules, share them in the comments so they can be reviewed and added later.


0 Bình luận

Góp Ý / Bình Luận / Đánh giá