The official Mikrotik router thread

Mikrotik includes a pretty good default config, but it's always good to harden it further against common attacks. The most obvious changes are of course using a non-default username and a good password, and only allowing administrative access from restricted networks/subnetworks/VLANs.

Here is what I am running:

Code:
/ip firewall filter add action=accept chain=input comment="defconf: accept established,related,untracked" connection-state=established,related,untracked
/ip firewall filter add action=accept chain=forward comment="defconf: accept established,related, untracked" connection-state=established,related,untracked
/ip firewall filter add action=accept chain=input comment="defconf: accept ICMP" protocol=icmp
/ip firewall filter add action=accept chain=input comment="defconf: accept to local loopback (for CAPsMAN)" dst-address=127.0.0.1
/ip firewall filter add action=accept chain=forward comment="defconf: accept in ipsec policy" ipsec-policy=in,ipsec
/ip firewall filter add action=accept chain=forward comment="defconf: accept out ipsec policy" ipsec-policy=out,ipsec
/ip firewall filter add action=fasttrack-connection chain=forward comment="defconf: fasttrack" connection-state=established,related disabled=yes hw-offload=yes
/ip firewall filter add action=drop chain=forward comment="defconf: drop invalid" connection-state=invalid
/ip firewall filter add action=drop chain=input comment="defconf: drop invalid" connection-state=invalid
/ip firewall filter add action=drop chain=forward comment="defconf: drop all from WAN not DSTNATed" connection-nat-state=!dstnat connection-state=new in-interface-list=WAN
/ip firewall filter add action=drop chain=input comment="defconf: drop all not coming from LAN" in-interface-list=!LAN
/ip firewall nat add action=masquerade chain=srcnat comment="defconf: masquerade" ipsec-policy=out,none out-interface=pppoe0
##/ip firewall nat add action=dst-nat chain=dstnat comment=Wireguard dst-port=51820 protocol=udp to-addresses=10.0.0.5
##/ip firewall nat add action=dst-nat chain=dstnat comment=Transmission dst-port=51413 protocol=tcp to-addresses=10.0.0.5
/ip firewall raw add action=drop chain=prerouting comment="TCP invalid combination of flags attack (7 rules)" log=yes log-prefix=RAW protocol=tcp tcp-flags=!fin,!syn,!rst,!ack
/ip firewall raw add action=drop chain=prerouting log=yes log-prefix=RAW protocol=tcp tcp-flags=fin,syn
/ip firewall raw add action=drop chain=prerouting log=yes log-prefix=RAW protocol=tcp tcp-flags=fin,rst
/ip firewall raw add action=drop chain=prerouting log=yes log-prefix=RAW protocol=tcp tcp-flags=fin,!ack
/ip firewall raw add action=drop chain=prerouting log=yes log-prefix=RAW protocol=tcp tcp-flags=fin,urg
/ip firewall raw add action=drop chain=prerouting log=yes log-prefix=RAW protocol=tcp tcp-flags=syn,rst
/ip firewall raw add action=drop chain=prerouting log=yes log-prefix=RAW protocol=tcp tcp-flags=rst,urg
/ip firewall raw add action=drop chain=prerouting comment="TCP Port 0 attack (2 rules)" log=yes log-prefix=RAW protocol=tcp src-port=0
/ip firewall raw add action=drop chain=prerouting dst-port=0 log=yes log-prefix=RAW protocol=tcp
/ip firewall raw add action=drop chain=prerouting comment="UDP Port 0 attack (2 rules)" log=yes log-prefix=RAW protocol=udp src-port=0
/ip firewall raw add action=drop chain=prerouting dst-port=0 log=yes log-prefix=RAW protocol=udp
/ip firewall raw add action=drop chain=prerouting comment="SYN fragmented attack" fragment=yes log=yes log-prefix=RAW protocol=tcp tcp-flags=syn
/ip firewall raw add action=drop chain=prerouting comment="IP option loose-source-routing" ipv4-options=loose-source-routing log=yes log-prefix=RAW
/ip firewall raw add action=drop chain=prerouting comment="IP option strict-source-routing" ipv4-options=strict-source-routing log=yes log-prefix=RAW
/ip firewall raw add action=drop chain=prerouting comment="IP option record-route" ipv4-options=record-route log=yes log-prefix=RAW
/ip firewall raw add action=drop chain=prerouting comment="IP option router-alert" ipv4-options=router-alert log=yes log-prefix=RAW
/ip firewall raw add action=drop chain=prerouting comment="IP option timestamp" ipv4-options=timestamp log=yes log-prefix=RAW
/ip firewall raw add action=drop chain=prerouting comment="IP options left, except IP Stream used by the IGMP protocol" ipv4-options=any log=yes log-prefix=RAW protocol=!igmp

You will notice I use mostly standard rules, with a few added. It's controversial to allow ICMP pings in but I allow it for PMTU discovery to work properly. I've commented out some DSTNAT rules that you likely won't use as it's just port forwarding for my Wireguard server and Transmission. I also don't use Fasttrack, I think for another script that I used, but in my case, I can probably enable it again.

The raw rules are meant to stop most attacks that are commonly seen from botnets. I've only seen one or two actual attempts blocked, though.

These rules only allow access to router services from my local LAN:

Code:
/ip service set telnet address=10.0.0.0/24
/ip service set ftp address=10.0.0.0/24
/ip service set www address=10.0.0.0/24
/ip service set ssh address=10.0.0.0/24
/ip service set api address=10.0.0.0/24
/ip service set winbox address=10.0.0.0/24
/ip service set api-ssl address=10.0.0.0/24

IPv6 firewall rules:

Code:
/ipv6 firewall address-list add address=::/128 comment="defconf: unspecified address" list=bad_ipv6
/ipv6 firewall address-list add address=::1/128 comment="defconf: lo" list=bad_ipv6
/ipv6 firewall address-list add address=fec0::/10 comment="defconf: site-local" list=bad_ipv6
/ipv6 firewall address-list add address=::ffff:0.0.0.0/96 comment="defconf: ipv4-mapped" list=bad_ipv6
/ipv6 firewall address-list add address=::/96 comment="defconf: ipv4 compat" list=bad_ipv6
/ipv6 firewall address-list add address=100::/64 comment="defconf: discard only " list=bad_ipv6
/ipv6 firewall address-list add address=2001:db8::/32 comment="defconf: documentation" list=bad_ipv6
/ipv6 firewall address-list add address=2001:10::/28 comment="defconf: ORCHID" list=bad_ipv6
/ipv6 firewall address-list add address=3ffe::/16 comment="defconf: 6bone" list=bad_ipv6
/ipv6 firewall filter add action=accept chain=input comment="defconf: accept established,related,untracked" connection-state=established,related,untracked log=yes log-prefix=IPv6
/ipv6 firewall filter add action=drop chain=input comment="defconf: drop invalid" connection-state=invalid
/ipv6 firewall filter add action=accept chain=input comment="defconf: accept ICMPv6" protocol=icmpv6
/ipv6 firewall filter add action=accept chain=input comment="defconf: accept UDP traceroute" port=33434-33534 protocol=udp
/ipv6 firewall filter add action=accept chain=input comment="defconf: accept DHCPv6-Client prefix delegation." dst-port=546 protocol=udp src-address=fe80::/10
/ipv6 firewall filter add action=accept chain=input comment="defconf: accept IKE" dst-port=500,4500 protocol=udp
/ipv6 firewall filter add action=accept chain=input comment="defconf: accept ipsec AH" protocol=ipsec-ah
/ipv6 firewall filter add action=accept chain=input comment="defconf: accept ipsec ESP" protocol=ipsec-esp
/ipv6 firewall filter add action=accept chain=input comment="defconf: accept all that matches ipsec policy" ipsec-policy=in,ipsec
/ipv6 firewall filter add action=drop chain=input comment="defconf: drop everything else not coming from LAN" in-interface-list=!LAN
/ipv6 firewall filter add action=accept chain=forward comment="defconf: accept established,related,untracked" connection-state=established,related,untracked
/ipv6 firewall filter add action=drop chain=forward comment="defconf: drop invalid" connection-state=invalid
/ipv6 firewall filter add action=drop chain=forward comment="defconf: drop packets with bad src ipv6" src-address-list=bad_ipv6
/ipv6 firewall filter add action=drop chain=forward comment="defconf: drop packets with bad dst ipv6" dst-address-list=bad_ipv6
/ipv6 firewall filter add action=drop chain=forward comment="defconf: rfc4890 drop hop-limit=1" hop-limit=equal:1 protocol=icmpv6
/ipv6 firewall filter add action=accept chain=forward comment="defconf: accept ICMPv6" protocol=icmpv6
/ipv6 firewall filter add action=accept chain=forward comment="defconf: accept HIP" protocol=139
/ipv6 firewall filter add action=accept chain=forward comment="defconf: accept IKE" dst-port=500,4500 protocol=udp
/ipv6 firewall filter add action=accept chain=forward comment="defconf: accept ipsec AH" protocol=ipsec-ah
/ipv6 firewall filter add action=accept chain=forward comment="defconf: accept ipsec ESP" protocol=ipsec-esp
/ipv6 firewall filter add action=accept chain=forward comment="defconf: accept all that matches ipsec policy" ipsec-policy=in,ipsec
/ipv6 firewall filter add action=drop chain=forward comment="defconf: drop everything else not coming from LAN" in-interface-list=!LAN

This should be a good starting point for you :)
Thanks for this - I'll compare these to the existing rules and adjust them appropriately - fortunately (unfortunately) my ISP doesn't support IPV6 yet so I don't need those (yet).

Eish, I forgot how little I know about RouterOS...

Upgraded from RB2011 to RB3011 this weekend. Wanted to do the right thing and start from scratch so did a clean boot with just the factory default settings and then tried to set things up by copying relevant settings line by line (copy/pasta with appropriate tweaks from an export of the RB2011 config).....what a painful exercise and then reached a point where I couldn't figure out how to activate the NAT properly so ja...

Eventually capitulated and just did a backup from the RB2011 and restore to the RB3011 - everything working but I'm not really happy about it since I know there's cruft that I've now copied across to the new router :(
 
Thanks for this - I'll compare these to the existing rules and adjust them appropriately - fortunately (unfortunately) my ISP doesn't support IPV6 yet so I don't need those (yet).

Eish, I forgot how little I know about RouterOS...

Upgraded from RB2011 to RB3011 this weekend. Wanted to do the right thing and start from scratch so did a clean boot with just the factory default settings and then tried to set things up by copying relevant settings line by line (copy/pasta with appropriate tweaks from an export of the RB2011 config).....what a painful exercise and then reached a point where I couldn't figure out how to activate the NAT properly so ja...

Eventually capitulated and just did a backup from the RB2011 and restore to the RB3011 - everything working but I'm not really happy about it since I know there's cruft that I've now copied across to the new router :(
Not sure how you did this but if you use a compact export you have all your settings neatly laid out to edit and paste on to the new router. From terminal:

> export compact

Should be a very quick job as most of your stuff would be the same.
 
Thanks for this - I'll compare these to the existing rules and adjust them appropriately - fortunately (unfortunately) my ISP doesn't support IPV6 yet so I don't need those (yet).

Eish, I forgot how little I know about RouterOS...

Upgraded from RB2011 to RB3011 this weekend. Wanted to do the right thing and start from scratch so did a clean boot with just the factory default settings and then tried to set things up by copying relevant settings line by line (copy/pasta with appropriate tweaks from an export of the RB2011 config).....what a painful exercise and then reached a point where I couldn't figure out how to activate the NAT properly so ja...

Eventually capitulated and just did a backup from the RB2011 and restore to the RB3011 - everything working but I'm not really happy about it since I know there's cruft that I've now copied across to the new router :(
You can also export from the RB2011 with:

Code:
export terse file=export.rsc

...which places your config in a file that you can then download. The 'terse' argument writes each command fully so that instead of this:

Code:
/interface ethernet
set [ find default-name=ether1 ] comment=frogfoot l2mtu=2026
set [ find default-name=ether2 ] comment=pi
set [ find default-name=ether3 ] comment=nas
set [ find default-name=ether4 ] comment=meraki
set [ find default-name=ether5 ] comment=ap
set [ find default-name=sfp1 ] comment=disabled disabled=yes

You have this, which makes copy-pasting easier:

Code:
/interface ethernet set [ find default-name=ether1 ] comment=frogfoot l2mtu=2026
/interface ethernet set [ find default-name=ether2 ] comment=pi
/interface ethernet set [ find default-name=ether3 ] comment=nas
/interface ethernet set [ find default-name=ether4 ] comment=meraki
/interface ethernet set [ find default-name=ether5 ] comment=ap
/interface ethernet set [ find default-name=sfp1 ] comment=disabled disabled=yes
 
Thanks both of you above - I didn't use the 'terse/compact' parameter.

The 'issue' I have is that the RB3011 by default has interfaces labelled ether1 - ether10 with a default bridge. The RB2011 labels them as ether1-gateway then ether2-5 and then ether6-master/slave through 10 (I'll post a screenshot later).

When I tried to configure the default RB3011 I got stuck.

Now my 3011's ports are labelled like the 2011 (from the import) and I'm not sure if that should be so since I have a 'duplicate' ether1 and ether1-gateway....

PS I did overstate a bit the 'pain' of copy paste - it was actually quite easy since I dumped it into Atom editor which formats RouterOS script beautifully
 
Thanks both of you above - I didn't use the 'terse/compact' parameter.

The 'issue' I have is that the RB3011 by default has interfaces labelled ether1 - ether10 with a default bridge. The RB2011 labels them as ether1-gateway then ether2-5 and then ether6-master/slave through 10 (I'll post a screenshot later).

When I tried to configure the default RB3011 I got stuck.

Now my 3011's ports are labelled like the 2011 (from the import) and I'm not sure if that should be so since I have a 'duplicate' ether1 and ether1-gateway....

PS I did overstate a bit the 'pain' of copy paste - it was actually quite easy since I dumped it into Atom editor which formats RouterOS script beautifully
I think your easiest bet would be to export the default config on the RB3011 after a factory reset, and then you should have the baseline config that you can then merge with your existing RB2011 config by using Find/Replace in your favourite text editor. Then you can just copy and paste the imported config and change all the interface names to suit the new device?
 
RouterOS 7.1.5 installed without much fanfare. I do wish we could still unbundle the packages like in rOS 6.x, even if just to have a bit more disk space.

1648016697540.png
 
RouterOS 7.1.5 installed without much fanfare. I do wish we could still unbundle the packages like in rOS 6.x, even if just to have a bit more disk space.

View attachment 1275230

I use the Accounting function with Attix5 to get a real-time view of which devices are using bandwidth - very useful for me since I'm only on a 100 Meg line.

Accounting has been deprecated in RoS7 so I'm sticking with 6 for the time being.

You can see the same info in Winbox using Kid Control but I haven't been able to find out how to access that data outside of Winbox and show it in window/dashboard like I currently do.
 
Last edited:
I use the Accounting function with Attix5 to get real-time view of which devices are using bandwidth - very useful for me since I'm only on a 100 Meg line.

Accounting has been deprecated in RoS7 so I'm sticking with 6 for the time being.

You can see the same info in Winbox using Kid Control but I haven't been able to find out how to access that data outside of Winbox and show it in window/dashboard like I currently do.
Get a load of this guy...'only' a 100Mb line. My 30Mb line would like to have a word:ROFL:

I never used the Accounting feature, as I use my Unifi dashboard more to keep an eye on wireless devices - only my NAS and the work Meraki is wired, but it is something I could look into at some stage.
 
Get a load of this guy...'only' a 100Mb line. My 30Mb line would like to have a word:ROFL:

I never used the Accounting feature, as I use my Unifi dashboard more to keep an eye on wireless devices - only my NAS and the work Meraki is wired, but it is something I could look into at some stage.

I know right - you'd think that 100 Meg is plenty but then I have a son who games and streams and uploads YT vids and when he gets going (and Xbox updates are running) he can saturate that line pretty damn quickly (at which point I throttle him to 50 Meg via Unifi profile)
 
I know right - you'd think that 100 Meg is plenty but then I have a son who games and streams and uploads YT vids and when he gets going (and Xbox updates are running) he can saturate that line pretty damn quickly (at which point I throttle him to 50 Meg via Unifi profile)
I think you need some Mikrotik queues in your life:sneaky:
 
anyone know how to keep an ipv4 lan that can access ipv6 via mikrotik's internet-facing ipv6?
so all the lan devices do not need/get their own ipv6.
 
Afrihost has been rolling out ipv6 using dhcpv6 for Openserve fibre customers. Does anyone have a working setup on MikroTik? Tried following this https://pastebin.com/d28aZZe4 but didn't get it to work, unfortunately. I'm bit out of my depth here.

Looks like I do get an IP prefix, and status is bound:
1648198496390.png

My laptop also gets an ipv6 address that starts with the given prefix:
1648198719580.png

IPv6 firewall settings (not sure if these are correct):
1648198828088.png

Address list:
1648198920867.png

ND config:
1648198951257.png

But then ping6 fails:
1648198642274.png

If I try to ping the router I get the following "No route to host":
1648198983500.png
 
You may need "add default route" enabled
I unfortunately get the same results with "add default route" checked.

I'm not sure if this is an issue, but under addresses, the address is /64, not /60:
1648204188403.png

PPPoE settings:
1648204493546.png
 
Last edited:
I unfortunately get the same results with "add default route" checked.

I'm not sure if this is an issue, but under addresses, the address is /64, not /60:
View attachment 1277206

PPPoE settings:
Yeah you get allocated a /60 then your router will allocate a sub /64 for your network
They give you a /60 in case you have different networks, eg guests or tenants

What routerOS version are you on?

On 7.x I found that any queue (even ipv4) broke ipv6
Also sometimes after interface changes, I had to go to ipv6 settings, and disable then enable ipv6 as a whole, but I think they fixed this bug

Can you show what your ipv6 route table looks like
 
Yeah you get allocated a /60 then your router will allocate a sub /64 for your network
They give you a /60 in case you have different networks, eg guests or tenants

What routerOS version are you on?

On 7.x I found that any queue (even ipv4) broke ipv6
Also sometimes after interface changes, I had to go to ipv6 settings, and disable then enable ipv6 as a whole, but I think they fixed this bug

Can you show what your ipv6 route table looks like
I'm using RouterOS 7.1.5. I do have queues enabled.

Below are the routes:

1648216676361.png
 
A solution to my IPv6 issues above was posted at https://mybroadband.co.za/forum/threads/ipv6-roll-out.1127458/post-29095420

Code:
# mar/28/2022 09:25:34 by RouterOS 7.1.5
#
# model = 2011iL
#
# notes:
# - ipv6 dhcpv6 pd setup on afrihost (openserve)
# - pppoe interface (the actual connection, not ether1) is named 00-pppoe
# - making use of cloudflares ipv6 for dns, not default dns

/ipv6 dhcp-server
add address-pool=fibre disabled=yes interface=bridge name=server1
/ipv6 address
add address=::1 from-pool=fibre interface=bridge
/ipv6 dhcp-client
add interface=00-pppoe pool-name=fibre pool-prefix-length=60 request=prefix use-peer-dns=no
/ipv6 firewall address-list
add address=::/128 comment="defconf: unspecified address" list=bad_ipv6
add address=::1/128 comment="defconf: lo" list=bad_ipv6
add address=fec0::/10 comment="defconf: site-local" list=bad_ipv6
add address=::ffff:0.0.0.0/96 comment="defconf: ipv4-mapped" list=bad_ipv6
add address=::/96 comment="defconf: ipv4 compat" list=bad_ipv6
add address=100::/64 comment="defconf: discard only " list=bad_ipv6
add address=2001:db8::/32 comment="defconf: documentation" list=bad_ipv6
add address=2001:10::/28 comment="defconf: ORCHID" list=bad_ipv6
add address=3ffe::/16 comment="defconf: 6bone" list=bad_ipv6
/ipv6 firewall filter
add action=accept chain=input comment="defconf: accept ICMPv6" protocol=icmpv6
add action=accept chain=input comment="defconf: accept established,related,untracked" connection-state=\
    established,related,untracked
add action=accept chain=input comment="defconf: accept DHCPv6-Client prefix delegation." disabled=yes dst-port=546 protocol=\
    udp src-address=fe80::/10
add action=accept chain=input comment="defconf: accept DHCPv6-Client prefix delegation." dst-port=546 protocol=udp
add action=drop chain=input comment="defconf: drop invalid" connection-state=invalid
add action=accept chain=input comment="defconf: accept ICMPv6" protocol=icmpv6
add action=accept chain=input comment="defconf: accept UDP traceroute" port=33434-33534 protocol=udp
add action=accept chain=input comment="defconf: accept IKE" dst-port=500,4500 protocol=udp
add action=accept chain=input comment="defconf: accept ipsec AH" protocol=ipsec-ah
add action=accept chain=input comment="defconf: accept ipsec ESP" protocol=ipsec-esp
add action=accept chain=input comment="defconf: accept all that matches ipsec policy" ipsec-policy=in,ipsec
add action=drop chain=input comment="defconf: drop everything else not coming from LAN" in-interface-list=!LAN
add action=accept chain=forward comment="defconf: accept established,related,untracked" connection-state=\
    established,related,untracked
add action=drop chain=forward comment="defconf: drop invalid" connection-state=invalid
add action=drop chain=forward comment="defconf: drop packets with bad src ipv6" src-address-list=bad_ipv6
add action=drop chain=forward comment="defconf: drop packets with bad dst ipv6" dst-address-list=bad_ipv6
add action=drop chain=forward comment="defconf: rfc4890 drop hop-limit=1" hop-limit=equal:1 protocol=icmpv6
add action=accept chain=forward comment="defconf: accept ICMPv6" protocol=icmpv6
add action=accept chain=forward comment="defconf: accept HIP" protocol=139
add action=accept chain=forward comment="defconf: accept IKE" dst-port=500,4500 protocol=udp
add action=accept chain=forward comment="defconf: accept ipsec AH" protocol=ipsec-ah
add action=accept chain=forward comment="defconf: accept ipsec ESP" protocol=ipsec-esp
add action=accept chain=forward comment="defconf: accept all that matches ipsec policy" ipsec-policy=in,ipsec
add action=drop chain=forward comment="defconf: drop everything else not coming from LAN" in-interface-list=!LAN
/ipv6 firewall mangle
add action=change-mss chain=forward new-mss=clamp-to-pmtu passthrough=yes protocol=tcp tcp-flags=syn
/ipv6 nd
set [ find default=yes ] dns=2606:4700:4700::1111,2606:4700:4700::1001 hop-limit=64 interface=bridge \
    managed-address-configuration=yes
/ipv6 nd prefix default
set preferred-lifetime=1m30s valid-lifetime=1m30s
/ipv6 route
add disabled=no distance=1 dst-address=::/0 gateway=00-pppoe scope=30 target-scope=10
 
I decided to give fq codel a try.
[,..]
Never knew about this. Enabled a simple queue on pppoe and went from a D at +300ms upload to an A+ +2ms. If I disable the queue while doing a cloud backup I immediately see the ping spike, so it's doing its job well.

My queue tree has been defeated by an algorithm and I couldn't be happier.
 
Top
Sign up to the MyBroadband newsletter
X