MMM MMM KKK TTTTTTTTTTT KKK
MMMM MMMM KKK TTTTTTTTTTT KKK
MMM MMMM MMM III KKK KKK RRRRRR OOOOOO TTT III KKK KKK
MMM MM MMM III KKKKK RRR RRR OOO OOO TTT III KKKKK
MMM MMM III KKK KKK RRRRRR OOO OOO TTT III KKK KKK
MMM MMM III KKK KKK RRR RRR OOOOOO TTT III KKK KKK
MikroTik RouterOS 5.18 (c) 1999-2012 [url]http://www.mikrotik.com/[/url]
I've been recommending Mikrotik products for ages, so I decided to put up a thread where we can post some config, tips and tricks. This code can be pasted straight into a terminal in Winbox and is effective immediately, no reboot required
This is a basic firewall that covers everything, it also blacklists IP's for 10 days after a few ssh attempts and logs all login attempts. You can see the logged and blacklisted IP addresses in ip-->firewall-->address lists
/ip firewall filter
add action=accept chain=input comment="allow ICMP" disabled=no protocol=icmp
add action=accept chain=input comment="allow winbox" disabled=no dst-port=8291 protocol=tcp
add action=accept chain=input comment="allow api" disabled=no dst-port=8728 protocol=tcp
add action=add-src-to-address-list address-list=trying_to_login address-list-timeout=1d chain=input comment="list IP's who try remote login" disabled=no dst-port=20-23 protocol=tcp
add action=drop chain=input comment="drop ssh brute forcers" disabled=no dst-port=22 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 disabled=no dst-port=22 protocol=tcp src-address-list=ssh_stage3
add action=add-src-to-address-list address-list=ssh_stage3 address-list-timeout=1h chain=input connection-state=new disabled=no dst-port=22 protocol=tcp src-address-list=ssh_stage2
add action=add-src-to-address-list address-list=ssh_stage2 address-list-timeout=1h chain=input connection-state=new disabled=no dst-port=22 protocol=tcp src-address-list=ssh_stage1
add action=add-src-to-address-list address-list=ssh_stage1 address-list-timeout=1h chain=input connection-state=new disabled=no dst-port=22 protocol=tcp
add action=accept chain=input comment="allow ssh" disabled=no dst-port=22 protocol=tcp
add action=accept chain=input comment="accept vpn" disabled=no dst-port=1723 in-interface=ether1-gateway protocol=tcp
add action=accept chain=input comment="accept vpn gre" disabled=no in-interface=ether1-gateway protocol=gre
add action=drop chain=input comment="drop ftp" disabled=no dst-port=21 protocol=tcp
add action=drop chain=forward comment="drop invalid connections" connection-state=invalid disabled=no
add action=accept chain=forward comment="allow already established connections" connection-state=established disabled=no
add action=accept chain=forward comment="allow related connections" connection-state=related disabled=no
add action=drop chain=input comment="drop Invalid connections" connection-state=invalid disabled=no
add action=accept chain=input comment="allow established connections" connection-state=established disabled=no
add action=accept chain=input comment="acccept lan" disabled=no in-interface=!ether1-gateway src-address=192.168.88.0/24
add action=drop chain=input comment="drop everything else" disabled=no
Here's 2 sample portforwards (disabled), a UDP and a TCP from port 5000 to lan ip 192.168.88.254 on port 5000. Add them, you can click copy and edit the copy and enable them
/ip firewall nat
add action=dst-nat chain=dstnat comment="sample udp from port 5000 to 5000 (lan ip 192.168.1.254)" disabled=yes dst-port=5000 protocol=udp to-addresses=192.168.88.254 to-ports=5000
add action=dst-nat chain=dstnat comment="sample tcp from port 5000 to 5000 (lan ip 192.168.1.254)" disabled=yes dst-port=5000 protocol=tcp to-addresses=192.168.88.254 to-ports=5000
This adds NTP so you never need to set time after rebooting
/system ntp client
set enabled=yes mode=unicast primary-ntp=140.203.204.77 secondary-ntp=0.0.0.0
This sets the DNS cache, change the servers to whatever DNS you use. You can check the cache in ip-->dns
/ip dns
set allow-remote-requests=yes cache-max-ttl=1w cache-size=4096KiB max-udp-packet-size=512 servers=88.81.100.2,88.81.98.4
If you set the DNS cache you're going to need to make the DHCP server give out the router IP as the DNS
/ip dhcp-server network
add address=192.168.88.0/24 comment="default configuration" dhcp-option="" dns-server=192.168.88.1 \
gateway=192.168.88.1 ntp-server="" wins-server=""
I'll post more and get some scripts up later.