PF table to block IP not working in real-time

Hi

I am implementing a program to detect bad IPs and block them in real-time via PF. I have a blocklist table persisted. The table starts with empty. Then my program will add bad IPs into this table.

My expectation is that PF will start blocking the connections from those IPs once they are added into the table. But I can still see the existing udp connections not destroyed/blocked by PF and there is traffic going between them.

/etc/rc.conf
Code:
table <blocklist> persist file '/usr/local/etc/pf_blocklist'
set skip on lo0
block all
pass out keep state
block on epair100b from <blocklist> to any
block on epair100b from any to <blocklist>

I am using this to add bad IPs to PF table
Code:
pfctl -t blocklist -Tadd 123.123.321.321

I verify the IPs are in the PF table. But their existing udp connections are still up. Those connections are established before I add them into the PF table.

Any thoughts? Thanks.
 
Add the offending IP to your table and then kill it with:

Code:
-k host | network | label | id | gateway

See the pfctl() man page.

Additionally, depending what goal you are trying to achieve, you may find that allowing pfctl to dynamically block hosts may perhaps be more efficient.

Be sure to see chapter 33 in the handbook regarding Firewalls and the section named "33.3.2.5. Using Overload Tables to Protect SSH". The concept applies to other ports not just SSH.
 
I moved from tables to blacklistd.


I love this info-graphic:

Very bottom of page setup instructions:
 
Back
Top