[SOLVED] Kind request for feedback about firewall configuration

Hello Mikrotik Users!

NOTE: I’ve read: http://forum.mikrotik.com/t/forum-rules/173010/1

I’ve been using my RB915G-2HnD for years now and I’m really happy. I’d describe myself as more of a casual network admin :wink: i.e.: when I need or want to change something I dive in and usually the thing works, but I’m not gonna call myself an expert.

This is about to become painfully obvious, because I’d like to ask for feedback about my firewall rules.

My sources:

  1. https://blog.ligos.net/2017-08-16/Mikrotik-And-LTE-via-Android.html
  2. https://www.shellhacks.com/mikrotik-firewall-default-config-basics-for-dummies/
  3. https://mum.mikrotik.com/presentations/VN17/presentation_4332_1493289082.pdf
  4. https://help.mikrotik.com/docs/display/ROS/RouterOS (I’m not sure how much applies to ROS6 that I have, this seems to be ROS7-centric at times…)

In the MUM presentation they reiterate the two ways of designing a firewall:

Firewall
Two approaches
● Drop not trusted and allow trusted
● Allow trusted and drop untrusted

I may have ended up with a kludge, that misses the mark somewhere.

Notes:

  1. I’m not using LTE/PPP anymore, but I kept those lines just in case I have to.
  2. Interface pppoe-out1 is dead, because I’m in-between ISPs right now, but this is what I’ll be using soon.
  3. I’m on ROS 6.49.14

Firewall configuration:

user@mikrotik > /ip firewall filter print 
Flags: X - disabled, I - invalid, D - dynamic 
 0    ;;; defconf: accept established,related,untracked
      chain=input action=accept connection-state=established,related,untracked 

 1    ;;; defconf: drop invalid
      chain=input action=drop connection-state=invalid 

 2    ;;; defconf: accept ICMP
      chain=input action=accept protocol=icmp 

 3    ;;; defconf: accept to local loopback (for CAPsMAN)
      chain=input action=accept dst-address=127.0.0.1 

 4 I  ;;; https://blog.ligos.net/2017-08-16/Mikrotik-And-LTE-via-Android.html
      ;;; lte1 not ready
      chain=input action=drop in-interface=*B log=no log-prefix="" 

 5    ;;; defconf: drop all not coming from LAN
      chain=input action=drop in-interface-list=!LAN 

 6    ;;; defconf: accept in ipsec policy
      chain=forward action=accept ipsec-policy=in,ipsec 

 7    ;;; defconf: accept out ipsec policy
      chain=forward action=accept ipsec-policy=out,ipsec 

 8 X  ;;; defconf: fasttrack
      chain=forward action=fasttrack-connection connection-state=established,related log=no log-prefix="" 

 9    ;;; defconf: accept established,related, untracked
      chain=forward action=accept connection-state=established,related,untracked 

10    ;;; defconf: drop invalid
      chain=forward action=drop connection-state=invalid 

11    ;;; defconf: drop all from WAN not DSTNATed
      chain=forward action=drop connection-state=new connection-nat-state=!dstnat in-interface-list=WAN 

12 I  ;;; defconf: drop all from ppp-out1 not DSTNATed
      ;;; ppp-out1 not ready
      chain=forward action=drop connection-state=new connection-nat-state=!dstnat in-interface=ppp-out1 log=no log-prefix="" 

13 I  ;;; defconf: drop all from huawei-modem not DSTNATed
      ;;; huawei-modem not ready
      chain=forward action=drop connection-state=new connection-nat-state=!dstnat in-interface=huawei-modem log=no log-prefix="" 

14 I  ;;; defconf: drop all from lte1 not DSTNATed
      ;;; lte1 not ready
      chain=forward action=drop connection-state=new connection-nat-state=!dstnat in-interface=*B log=no log-prefix=""

My questions:

  1. I’m aware this config is not pretty, but is it safe?
  2. I’d like to know how rule 5 and 4, 12-14 work together, since the packets can come from different interfaces (lte, pppoe-out1, huawei-modem). Is this an issue that I have a drop on input as rule 5 while rules 12-14 have no corresponding drop at the end?
  3. What does *B mean? Deleted? I couldn’t find this in the docs, but I guess it’s for deleted items, since I removed lte-1 a while ago.

Thank you!

Regarding note 1, you could disable the unused rules. Now on to your questions:

  1. Yes, there are no visible nonsensical rules.
  2. Rule 4 is redundant because rule 5 has a greater coverage - no access to the router from an interface that is not part of the LAN interface list. As for the role of rules 12-14, they drop all forwarded traffic that is not allowed from the upper rules except if it’s dstnat-ed. If you add the interfaces from those rules to the WAN interface list, you could get rid of them.
  3. Your assumption is correct.

Maybe @anav would suggest more rules or give a second opinion but overall there is no need for worries

I dont comment unless I see the full config as items are related.

To export and paste your configuration (and I’m assuming you are using WebFig or Winbox), open a terminal window, and type (without the quotes) “/export hide-sensitive file=any-filename-you-wish”. Then open the files section and right click on the filename you created and select download in order to download the file to your computer. It will be a text file with whatever name you saved to with an extension of .rsc. Suggest you then open the .rsc file in your favorite text editor and redact any sensitive information. Then in your message here, click the code display icon in the toolbar above the text entry (the code display icon is the 7th one from the left and looks like a square with a blob in the middle). Then paste the text from the file in between the two code words in brackets.

Hello,

apologies for the late reply.


Thank you TheCat12 for your help!

I didn’t want to post the whole config initially, because of this tip mentioned in the first post of the rules thread:

Posting large setups “for evaluation” might not get you any answers, so start with the core issue and ask a specific question.

Here’s my redacted config:

# jul/06/2024 15:24:06 by RouterOS 6.49.15
# software id = [*******]
#
# model = 951G-2HnD
# serial number = [*******]
/interface bridge
add admin-mac=[*******] auto-mac=no comment=defconf name=bridge
/interface ethernet
set [ find default-name=ether3 ] comment=raspberrypi
/interface vlan
add interface=ether1 name=[*******] vlan-id=[*******]
/interface pppoe-client
add add-default-route=yes disabled=no interface=[*******] name=\
    pppoe-out1 user=[*******]
/interface list
add comment=defconf name=WAN
add comment=defconf name=LAN
/interface lte apn
add apn=internet name=non-dns-default
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
add authentication-types=wpa2-psk eap-methods="" management-protection=\
    allowed mode=dynamic-keys name=hardened supplicant-identity=""
/interface wireless
set [ find default-name=wlan1 ] antenna-gain=0 band=2ghz-b/g/n channel-width=\
    20/40mhz-XX country=no_country_set disabled=no distance=indoors \
    frequency=auto frequency-mode=manual-txpower installation=indoor mode=\
    ap-bridge security-profile=hardened ssid=*** station-roaming=enabled \
    wireless-protocol=802.11
/ip pool
add name=dhcp ranges=192.168.88.10-192.168.88.254
/ip dhcp-server
add address-pool=dhcp disabled=no interface=bridge name=defconf
/port
set 0 baud-rate=9600 data-bits=8 flow-control=none name=usb1 parity=none \
    stop-bits=1
set 1 baud-rate=9600 data-bits=8 flow-control=none name=usb2 parity=none \
    stop-bits=1
/interface ppp-client
add data-channel=1 dial-on-demand=no name=huawei-modem phone=*99# port=usb1
add apn=internet dial-on-demand=no name=ppp-out1 phone=*99# pin=**** port=\
    usb2
/system logging action
set 1 disk-lines-per-file=4096
/user group
set full policy="local,telnet,ssh,ftp,reboot,read,write,policy,test,winbox,pas\
    sword,web,sniff,sensitive,api,romon,dude,tikapp"
/interface bridge port
add bridge=bridge comment=defconf interface=ether2
add bridge=bridge comment=defconf interface=ether3
add bridge=bridge comment=defconf interface=ether4
add bridge=bridge comment=defconf interface=ether5
add bridge=bridge comment=defconf interface=wlan1
add bridge=bridge comment=defconf interface=*2
/ip neighbor discovery-settings
set discover-interface-list=none
/interface list member
add comment=defconf interface=bridge list=LAN
add comment=defconf interface=ether1 list=WAN
/ip accounting
set account-local-traffic=yes enabled=yes
/ip address
add address=192.168.88.1/24 comment=defconf interface=ether2 network=\
    192.168.88.0
/ip dhcp-client
add comment=defconf interface=ether1 use-peer-dns=no
add disabled=no use-peer-dns=no
/ip dhcp-server lease
add address=192.168.88.104 mac-address=[*****] server=defconf
add address=192.168.88.106 client-id=[*****] mac-address=\
    [*****] server=defconf
add address=192.168.88.105 client-id=[*****] mac-address=\
    [*****] server=defconf
/ip dhcp-server network
add address=192.168.88.0/24 comment=defconf gateway=192.168.88.1
/ip dns
set allow-remote-requests=yes cache-size=8192KiB servers=\
    104.16.248.249,104.16.249.249 use-doh-server=\
    https://cloudflare-dns.com/dns-query verify-doh-cert=yes
/ip dns static
add address=192.168.88.1 comment=defconf disabled=yes name=router.lan
add address=104.16.248.249 name=cloudflare-dns.com
add address=104.16.249.249 name=cloudflare-dns.com
/ip firewall filter
add action=accept chain=input comment=\
    "defconf: accept established,related,untracked" connection-state=\
    established,related,untracked
add action=drop chain=input comment="defconf: drop invalid" connection-state=\
    invalid
add action=accept chain=input comment="defconf: accept ICMP" protocol=icmp
add action=accept chain=input comment=\
    "defconf: accept to local loopback (for CAPsMAN)" dst-address=127.0.0.1
# no interface
add action=drop chain=input comment=\
    https://blog.ligos.net/2017-08-16/Mikrotik-And-LTE-via-Android.html \
    in-interface=*B
add action=drop chain=input comment="defconf: drop all not coming from LAN" \
    in-interface-list=!LAN
add action=accept chain=forward comment="defconf: accept in ipsec policy" \
    ipsec-policy=in,ipsec
add action=accept chain=forward comment="defconf: accept out ipsec policy" \
    ipsec-policy=out,ipsec
add action=fasttrack-connection chain=forward comment="defconf: fasttrack" \
    connection-state=established,related disabled=yes
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 all from WAN not DSTNATed" connection-nat-state=!dstnat \
    connection-state=new in-interface-list=WAN
# no interface
add action=drop chain=forward comment=\
    "defconf: drop all from ppp-out1 not DSTNATed" connection-nat-state=\
    !dstnat connection-state=new in-interface=ppp-out1
# no interface
add action=drop chain=forward comment=\
    "defconf: drop all from huawei-modem not DSTNATed" connection-nat-state=\
    !dstnat connection-state=new in-interface=huawei-modem
# no interface
add action=drop chain=forward comment=\
    "defconf: drop all from lte1 not DSTNATed" connection-nat-state=!dstnat \
    connection-state=new in-interface=*B
/ip firewall nat
add action=masquerade chain=srcnat comment="defconf: masquerade" \
    ipsec-policy=out,none
# no interface
add action=masquerade chain=srcnat out-interface=huawei-modem
# no interface
add action=masquerade chain=srcnat comment=lte1 out-interface=*B
/ip service
set telnet disabled=yes
set ftp disabled=yes
set www disabled=yes
set api disabled=yes
set api-ssl disabled=yes
/system clock
set time-zone-name=[*****]
/system logging
add action=disk topics=critical
add action=disk topics=error
add action=disk topics=info
add action=disk topics=warning
add topics=dns
add topics=lte
add topics=gsm
/tool bandwidth-server
set enabled=no
/tool graphing interface
add allow-address=192.168.88.0/24 interface=huawei-modem
add allow-address=192.168.88.0/24 interface=ether3
add allow-address=192.168.88.0/24
/tool graphing resource
add allow-address=192.168.88.0/24
/tool mac-server
set allowed-interface-list=none
/tool mac-server mac-winbox
set allowed-interface-list=LAN

I hope this answers some questions.

As for the firewall: I want to work on it, but I’m working on multiple other projects now. When I finally find the time to do the cleanup, where should I ask? In this thread? Will that be seen as necroposting or keeping things together? :sunglasses:

I tend to think at this as “keeping things together”.

Before and besides anything else you have some issues in your configuration, the:
# no interface
is Ros trying to tell you that a rule doesn’t make sense as it applies to something that doesn’t exist.

Additionally, you have in a few lines interface:

*B

or

*2

generally speaking this means that there was a reference to an existing item that (for whatever reason) was removed or however that Ros cannot find it anymore and so uses instead a (hex) number preceded by an asterisk as a “placeholder”, these should be fixed or removed.

Not really important, but comments starting with “defconf:” are usually the built-in ones in standard configuration, if you modify one of them, it is a good idea to change also the beginning of the comment to something like “myconf:” so that they are easier to distinguish.

… reference to what jaclaz, spit it out man. To the missing config already requested :stuck_out_tongue_winking_eye:
( one doesnt blindly delete config lines with errors one investigates why they exist )

Then kindly ask the text for help… drats…can texts talk, no.
A living human being, answered your request for assistance, so dont quote an inert, clearly not totally useful text, back…
To be fair, it seems legit but MT documentation is not really context specific and is general advice mostly for professionals, not us regular folks. :slight_smile:

The advice is sheite for most people, except for IT trained, experienced network pers who can communicate an issue precisely such that it can be answered the first go around. There are few people here that can actually do that, Sindy for one, but not many others.

I’ll keep that in mind, thanks!

It’s rather obvious at this point that my config needs a bit of a clean-up (dead devices, redundant firewall rules). I need to set aside a day to do this. As far as I’m concerned my original topic is solved.