Ok, so there is a default firewall config that works fine and all, but I’m trying to understand what it actually does. It seems that all tutorials explain that it does PRECISELY, like in the exact way the rule is written, which doesn’t really explain anything.
/ip firewall filter
1 - add action=accept chain=input comment="defconf: accept established,related,untracked" connection-state=established,related,untracked
2 - add action=drop chain=input comment="defconf: drop invalid" connection-state=invalid
3 - add action=accept chain=input comment="defconf: accept ICMP" protocol=icmp
4 - add action=drop chain=input comment="defconf: drop all not coming from LAN" in-interface-list=!LAN5 - add action=accept chain=forward comment="defconf: accept established,related, untracked" connection-state=established,related,untracked
6 - add action=drop chain=forward comment="defconf: drop invalid" connection-state=invalid
7 - add action=drop chain=forward comment="defconf: drop all from WAN not DSTNATed" connection-nat-state=!dstnat connection-state=new in-interface-list=WAN
(I have removed CAPsMAN and ipsec rules as I don’t use these features, and I have numbered the rules)
At the same time, I’m looking at The ultimate Mikrotik iptables flowchart as reference.
Question 1) Not related to defconf yet, but looking at the flowchart - if I send an UDP packet from a completely different network into my network and if I have a dstnat with the UDP port, does the packet go through steps 1, 2, 3, 4, 5, 10, 11, 12, 13 (because IP was overriden to 192.168.x.x IP that is not the router itself, so step 12 results in N (assuming “dst addr=self” is the public WAN IP???)), etc. completely bypassing INPUT chain? How can a completely unrelated external incoming packet bypass a chain named “INPUT”?
Question 2) Not related to defconf yet, but what is “localhost” in step 5 in the flowchart? Is it only the router itself? “self” is used two times in the flowchart, but it doesn’t seem that they mean the same thing (local router IP vs WAN IP)
Question 3) What is an “untracked” connection state? Connection tracking - RouterOS - MikroTik Documentation mentions it, but doesn’t explain it. Or is the name confused “notrack” in that page?
Question 4) Why would we need an ICMP accept rule 3, but not a TCP/UDP accept rule? If we remove the ICMP rule, does that mean that pings won’t work from outside? Why would then TCP/UDP work?
Question 5) Looking at packet count of rule 4 and looking at logs with log=yes, it seems that this rule rejects internet noise (probes, etc.), but the description of the rule is a bit confusing. Does this rule work this way only because non-DSTNATed traffic goes through INPUT and “all not coming from LAN” is actually just “all coming from WAN”?
Question 6) I have internet detection feature enabled, which sends DNS queries for cloud.mikrotik.com every second. Enabling logs for rule 4, I see logs for UDP [dns server]:53→[WAN IP]:5678, which I assume is the DNS answer. This actually makes sense because DNS answers are coming from WAN, and are routed through INPUT chain. If the rule is to drop, how can internet detection feature work?
Question 7) Do we need an additional rule 6 (compared to rule 2) because DSTNATed traffic doesn’t touch INPUT chain? Any other reasons?
Question 8) I have been running my router for a some time. Rule 7 has never been triggered (packet count is 0). Why is this rule needed? If an incoming connecting is DSTNATed, then the rule doesn’t apply (actually I don’t see how anything would reach FORWARD chain if traffic isn’t DSTNATed). If incoming connection is not DSTNATed, then only INPUT chain applies and it’s dropped by rule 4. It is theoretically possible to send traffic to the router with dst ip of 1.2.3.4, so maybe then it would reach the FORWARD chain and wouldn’t be DSTNATed?
Thanks. I would actually prefer a firewall that DROPs by default, so if anyone has a copypaste config I could learn from, that would be great.
I know that the design of the firewall is very much influenced by linux iptables, but holy hell it’s confusing.
