-
As @jaclaz wrote, you can remove #17 and keep #18.
-
Current rule #16 should be moved below the "established,related,untracked" original rule #18 (and also after the "drop invalid" rule, see below).
For the bulk of the traffic (the very large majority of the packets), the connection state would be
established. When you download a 150KB JPG image for example, then usually only one packet has statenew, while the other 100+ ones will have stateestablished. You would want the packets in theestablishedto be handled as soon as possible, skipping the other rules below immediately. Of course, fasttrack already helps in this case, but for the cases where fasttrack is not working or not enabled, you don't want to have rules that only act on packets with connection statenewto be placed higher than the rule that acceptsestablishedin the chain. -
The
chain=forward action=drop connection-state=invalidrule should be placed right after that original #18 rule. -
Once you've got the "accept established,related,untracked" and "drop invalid" rules at the correct positions (high in the chain, only behind fasttrack and the two special ipsec related rules), then all the other
acceptordroprules below them no longer needconnection-state=newand that condition can be removed from those rules.The possible values for
connection-statearenew,established,related,untracked,invalid, which means once you already have the 3 rules (including the fasttrack rule) that catch and handleestablished,related,untracked,invalid, the only possible connection state for the packets caught by other rules below them isnew. It is thus totally redundant and unnecessary when you also specifyconnection-state=newon them. Any packets they can see already only have that connection state. -
The original rule #20 is fully redundant (already handled by original #18) and should be removed too.
-
When you have the catch all rule (original #25) then you normally don't need the original rule #22 anymore, because no other rule between them explicitly accepts things coming from WAN.
But you can still leave it there if you want, in case you might insert some
acceptrules in between and forget to handle incoming connections from WAN with those. With normal traffic (not under attack) only a small ratio of the packets hasconnection-state=new, so having a few unnecessary rules below the rules that handleestablished,related,untracked,invaliddoesn't affect the performance too much. -
If in the future for some reason you are not able to use fasttrack anymore (for example you want to use simple queues, or all traffics need mangle) then when you disable the fasttrack rule you should also move the two
ipsecrules below the "accept established, related, untracked" rule to prioritize it as much as possible. Without fasttrack, the difference between having to only process 1 rule instead of 3 for most of the packets is very much noticeable.With fasttrack enabled and active, then you need those two rules above the fasttrack rule, because from your config, it looks like IPsec is in use.