cPFence is a powerful security software with advanced features you won't find in traditional firewalls. One of these is the ability to integrate custom IP blocklists or public RBL databases that update automatically. Whether you're blocking spammers or abusive IPs, here's how to set it up in just a few steps.
Step 1 (Optional): Prepare Your Custom List
If you're using your own blocklist or whitelist, prepare the file before integrating it. You can use either a public URL or a local file.
To add the list on your website:
su - username
cd public_html
nano blocklist.txt
Then run:
dos2unix blocklist.txt
This ensures the file uses proper Linux line endings.
Step 2: Add a Daily Cronjob
To keep your firewall synced with the latest version of your blocklist, set up a daily cronjob:
- Open the crontab editor:
crontab -e
- Add this line to run the sync once per day (e.g., at 3:30 AM):
30 3 * * * /opt/cpfence/app/setup/cpfmain --bulk-blacklist-ip https://yourcompany.com/blocklist.txt >/dev/null 2>&1
Save and exit.
This will fetch and apply your blocklist daily.
Step 3 (Optional): Reduce False Positives with a Whitelist
Custom blocklists and RBLs are powerful, but can sometimes cause false positives. To prevent this, maintain a whitelist file and import it as well:
35 3 * * * /opt/cpfence/app/setup/cpfmain --bulk-whitelist-ip https://yourcompany.com/whitelist.txt >/dev/null 2>&1
Whitelist entries are always applied before blocklist rules, ensuring safe IPs aren't accidentally blocked.
Got an interesting RBL source or automation tip to share? Drop it in the replies.