Large blocklists on the server
The ph24 firewall filters in front of the server. Its IP lists are meant for known parties and take up to 1,000 entries. Large or constantly changing blocklists work better inside the server itself: with an nftables set loaded from a file, with CrowdSec or with fail2ban.
What IP lists are for
An IP list groups addresses that several rules or firewalls need. Typical contents:
- fixed addresses of the office and the VPN, for example for SSH or the database
- monitoring and uptime services, partners and payment services
- published networks, for example those of a CDN
- small blocklists with a few known attackers
Large threat feeds, blocking whole countries and automatic bans after failed logins are not offered by the ph24 firewall. Tools that run inside the server do this.
1,000 entries per list and per server
- Per IP list: up to 1,000 entries, one address or network (CIDR) each. A network like 203.0.113.0/24 is one entry, even though it covers 256 addresses.
- Per server: up to 1,000 entries in total from all IP lists named by the rules of its firewalls. A list named by several rules or firewalls of a server counts once; the same address in two lists counts twice.
- Not counted: addresses written directly into a rule (up to 10 per rule) and the server's own addresses.
Each entry is written to the host one by one when the firewall is applied. A list of 1,000 entries takes a few minutes to apply the first time; longer lists would delay every change accordingly. A change that would take a server above 1,000 entries is refused, and the message names the servers concerned. Lists and servers that had more entries before keep them and can only get shorter.
A blocklist with nftables from a file
nftables is the Linux kernel's packet filter and is part of current Debian and Ubuntu systems. An nftables set holds hundreds of thousands of addresses and is searched quickly for every packet. The script below reads a file with one address or network per line, creates a table of its own with a set and drops incoming packets from these addresses. Lines that don't start with a digit (comments, empty lines) are skipped.
#!/bin/sh
# Reloads the blocklist: one IPv4 address or network (CIDR) per line.
set -eu
list=/etc/blocklist/ipv4.txt
{
cat <<'END'
table inet blocklist
delete table inet blocklist
table inet blocklist {
set v4 { type ipv4_addr; flags interval; auto-merge; }
chain input {
type filter hook input priority -10; policy accept;
ip saddr @v4 drop
}
}
END
grep -E '^[0-9]' "$list" | sed 's/.*/add element inet blocklist v4 { & }/'
} | nft -f -chmod +x /usr/local/sbin/blocklist-load
/usr/local/sbin/blocklist-load
nft list set inet blocklist v4 | head@reboot root /usr/local/sbin/blocklist-load
0 * * * * root /usr/local/sbin/blocklist-loadnftables takes the file in one step: the old list applies until the new one does, with no gap in between. Other rules on the server, for example from ufw, stay as they are. For IPv6, add a second set with type ipv6_addr and the rule ip6 saddr. Traffic to containers with published ports (Docker) passes the forward chain instead of input; they need a second chain with hook forward and the same rule.
CrowdSec: detect attacks and block them together
CrowdSec reads the server's logs, for example from SSH or the web server, detects attack patterns and blocks the senders. On top comes a shared blocklist built from the reports of many installations. A so-called bouncer enforces the blocks; the firewall bouncer for nftables works with sets like the example above.
The installation is described in the documentation at docs.crowdsec.net; for Debian and Ubuntu the vendor runs a package repository. Afterwards, two commands show what is blocked and why:
cscli decisions list
cscli alerts listfail2ban: bans after failed attempts
fail2ban blocks an address for a set time when too many logins from it fail, for example for SSH, mail or a web login. It is a package in Debian and Ubuntu. With the following settings it blocks with nftables and protects SSH:
[DEFAULT]
banaction = nftables-multiport
bantime = 1h
findtime = 10m
maxretry = 5
[sshd]
enabled = trueapt install fail2ban
systemctl restart fail2ban
fail2ban-client status sshdOn Debian 12 without the file /var/log/auth.log, fail2ban reads the logins from the journal: add backend = systemd to the [sshd] section.
Which one fits?
- A fixed or regularly loaded list (threat feed, networks of whole countries): an nftables set from a file.
- Detect attacks and learn from other installations: CrowdSec.
- Repeated failed logins: fail2ban.
- Known parties such as the office, VPN and monitoring: IP lists in the ph24 firewall.
Frequently asked questions
More questions? Contact
What happens to IP lists that already have more than 1,000 entries?
They stay as they are and are still applied. Changes are possible as long as the list doesn't get longer, until it has 1,000 entries or fewer.
Does an address in two lists count twice?
Yes. Each list counts with all its entries. A list named by several rules or firewalls of the same server, however, counts only once.
Do addresses written directly into a rule count?
No. Up to 10 addresses directly in a rule don't count towards a server's 1,000 entries.