pf¶
Block every address on a list with pf, the firewall of OpenBSD and FreeBSD. The last two sections cover OPNsense and pfSense, which are built on pf but managed through their own web interface.
Written for OpenBSD 7.8 and 7.9, and FreeBSD 14 and 15, from their manuals. We haven't run these steps on those systems ourselves yet. If something doesn't work as written, tell us.
You need aip-sync installed and your key stored. It needs Python 3:
pkg_add python3 on OpenBSD, pkg install python3 on FreeBSD. OpenBSD has no curl by
default. Download the script with ftp -o /usr/local/bin/aip-sync <url> instead.
The examples use the persistent list, and keep files in /var/db/aip-sync, the usual place
on BSD systems.
Set up once¶
Add these two lines to /etc/pf.conf, before your other pass rules:
table <aip_persistent> persist file "/var/db/aip-sync/persistent.txt"
block in quick log from <aip_persistent>
quick stops pf at this rule for those addresses. log sends what it blocks to pflog0,
which you can watch with tcpdump -n -e -ttt -i pflog0. Remove log if you don't need it.
Fill the file once, then load the rules:
/usr/local/bin/python3 /usr/local/bin/aip-sync --list persistent \
--state-dir /var/db/aip-sync --out /var/db/aip-sync/persistent.txt --changes
pfctl -nf /etc/pf.conf && pfctl -f /etc/pf.conf
pfctl -nf checks the file without loading it.
FreeBSD: lists over 65,535 addresses¶
On FreeBSD, pf loads at most 65,535 addresses in one go by default. all-last-7-days is
bigger. If you use it, raise the limit now and at every boot:
sysctl net.pf.request_maxcount=200000
echo 'net.pf.request_maxcount=200000' >> /etc/sysctl.conf
pf also holds at most 200,000 addresses in all its tables together, on both systems. If you
load several lists, raise it in pf.conf with set limit table-entries 400000.
Update every day¶
Add this line to root's crontab (crontab -e), with a time after 03:30 UTC in your
server's time zone:
40 3 * * * /usr/local/bin/python3 /usr/local/bin/aip-sync --list persistent --state-dir /var/db/aip-sync --out /var/db/aip-sync/persistent.txt --changes --quiet && /sbin/pfctl -q -t aip_persistent -T replace -f /var/db/aip-sync/persistent.txt
The paths are written out because cron's search path doesn't include /usr/local/bin on
FreeBSD. pfctl -T replace swaps the table's contents in one step. If aip-sync fails, &&
skips it and the table keeps yesterday's addresses.
Check the table:
pfctl -t aip_persistent -T show | head
pfctl -t aip_persistent -T show | wc -l
After a reboot, pf reads the file again, so nothing else is needed.
IPv6 addresses can go in the same table. pf takes both.
OPNsense¶
OPNsense can download a list by itself, with your key. This needs OPNsense 25.1 or later.
- Go to Firewall > Aliases and add an alias.
- Set Type to
URL Table (IPs). - Set the URL to
https://api.intelligence.stratosphereips.org/v1/lists/persistent?format=csv. - Set the refresh frequency to 1 day.
- Under authorization, choose
Bearerand paste your API key. - Use the alias as the source in a block rule.
OPNsense reads the first column of each line, the address. This only blocks today's list. An address leaves the alias the day it leaves the list. Each refresh is a whole download, and costs its credits.
OPNsense reads the header row too, and looks up the word ip in DNS. That does no harm
unless your DNS knows a host called ip.
We wrote this from OPNsense's source code and haven't tried it on a live OPNsense yet.
pfSense¶
pfSense's URL Table (IPs) alias can't send an API key, so it can't download our lists
directly. Instead, run aip-sync on another machine, Linux for example. Publish its output
file on a web server inside your network, and point the alias at that address. Set the
alias to refresh every day.
This also keeps addresses for 7 or 14 days after they leave the list, which a direct download can't do. OPNsense users can do the same.