Resurrecting and old thread but couldn't easily find this info anywhere else and wanted to add for others help in the future, this works as of v7.7 in 2023;
Using a RAW rule after adding to blocked list.
Similar issue, want to block brute force. Instead of blocking a single port, if an IP is a bad actor, we want to block the IP completely.
The add to src-address-list rules need to be on forward chain and using the TO port in the NAT rule. So if ext port 999 NAT TO internal 192.168.1.1 port 80, you want port 80 in the rule;
add chain=forward protocol=tcp dst-port=80 connection-state=new action=add-src-to-address-list \
address-list=block_stage1 address-list-timeout=1m comment="" disabled=no
This will add and advance the IP.
Now for blocking, the block rule works on FORWARD chain src-address-list=blocked_addresses.
add chain=forward src-address-list=blocked_addresses action=drop \
comment="drop blocked" disabled=no
But, that IP can still scan/brute ports on the router (port 8291, 22 if open, etc.) So you can add another block rule with chain=input.
We found that adding a RAW rule is much better, it stops any further processing or packets from blocked IPs.
/ip/firewall/raw
add chain=prerouting action=drop in-interface=ether1 src-address-list=blocked_addresses
Does anyone see a problem with doing it that way? Seems most efficient and safe way to block traffic.
Now, you can't specify a connection-state=new in raw rules so you can't build the block rules in raw table (otherwise it would hit on every packet to that port), so ideally you need 2 sets of rules to add FORWARD and INPUT to blocked_addresses;
add chain=input protocol=tcp dst-port=80 connection-state=new action=add-src-to-address-list \
address-list=block_stage1 address-list-timeout=1m comment="" disabled=no
Another idea would be to add multiple ports to capture "bad" scanners, such as ports 21,22,80,etc INPUT and add to blocked_addresses escalation lists.
Any problems with assumptions and rules above? Any more efficient way to do this?
Thanks and hope this helps someone.