ipfence
Local intrusion prevention for Linux: watch your own logs, block the address that is attacking, and see exactly what was done and why.
Status: version 0.1, an early release. "ipfence" (project codename Ward) is a provisional name that has not been cleared for package registries, trademarks or domains.
In plain English
Any server on the internet is constantly poked by automated programs. They guess SSH passwords thousands of times, and ask web servers for files that should never be public. ipfence notices this in the server's own logs and tells the Linux firewall to ignore that visitor for a while.
Diagram source
flowchart LR
A["Attacker guesses<br/>passwords"] --> B["Your server writes<br/>log lines"]
B --> C["ipfence reads them<br/>and counts"]
C --> D["Five in ten minutes:<br/>adds the address to<br/>the firewall"]
D --> E["The Linux kernel<br/>drops its packets"]
E -.-> A- It only watches at first, and tells you who it would block. Blocking starts
when you run
ipfence enable. - Bans wear off: 15 minutes, then 6 hours, then 7 days.
- It tries hard not to lock you out (no guarantee: see below).
- Nothing leaves your machine.
Understand it properly
| If you want to... | Read |
|---|---|
| know what it does, with no jargon | What ipfence does |
| learn the words (firewall, port, log...) | Concepts from zero |
| watch a real attack get blocked, step by step | The story of an attack |
| install it carefully | Getting started |
| understand the code | Code tour |
| see every page | Documentation index |
Privacy contract
ipfence's built-in components never send anything off your machine. No telemetry, crash reports, update checks, accounts, API keys, shared threat feeds, downloaded databases or remote parsers. Rules, history and logs stay local.
- The program makes no DNS lookups and contacts no server. Its only HTTP client talks to the local Docker Unix socket.
- The systemd unit prevents the daemon, and anything it starts, from creating an IPv4 or IPv6 socket at all. A trace of the running daemon showed Unix and netlink sockets only.
- One thing you can add does send data wherever you choose: the optional hook, a program of yours that runs after a ban. It is off unless you configure it, and the unit's network block applies to it until you remove that block.
Building from source downloads Go modules. That is the only network use.
What it does, precisely
| Detects | OpenSSH authentication failures from the systemd journal. High-confidence exploit probes (/.env, /.git/config, path traversal to /etc/passwd, JNDI payloads and a few more) in Nginx and Caddy access logs, once you enable them. |
| Blocks | Source addresses, in one nftables table of its own, inet ipfence, using rules that only ever drop. |
| Remembers | Bans, history and repeat offenses in a local SQLite file. Bans last 15 minutes, then 6 hours, then 7 days. |
| Shows | What was detected, which log is read, which firewall hook sees the traffic, every ban and its reason, and what is not covered. |
It starts in observe mode: it records what it would ban and changes no
firewall rule until you run ipfence enable.
What it does not do
- It is not a web application firewall and does not protect against volumetric denial of service.
- It cannot block a visitor who reaches you through a reverse proxy or CDN: this host only ever sees the proxy's address.
- It does not treat a bare 401 or 403 as a failed login, and has no generic "suspicious URL" rules.
- It does not read container logs or detect services running inside containers.
- It cannot promise you will never be locked out. It exempts what it can verify and gives you ways back in; see IPv6 and lockout.
Supported systems
Requires Linux with nftables, root privileges for firewall changes, and
journalctl for SSH detection. Binaries are static, CGO-free, for amd64 and
arm64.
| Tested (amd64 virtual machines) | Kernel | systemd | OpenSSH | Nginx | Caddy |
|---|---|---|---|---|---|
| Debian 13 | 6.12 | 257 | 10.0p2 | 1.26 | 2.6 |
| Debian 12 | 6.1 | 252 | 9.2p1 | 1.22 | 2.6 |
| Rocky Linux 9.9, SELinux enforcing | 5.14 | 252 | 9.9p1 | 1.20 | 2.6 |
Each of those ran the unit and integration tests, the end-to-end script (real sshd, Nginx, Caddy and systemd, attacked from a network namespace) and a reboot check. arm64 ran the same three on Debian 13 under emulation only.
Ubuntu, Fedora, RHEL itself, Alpine, Arch and physical hardware (amd64 or arm64) have not been tested. Without systemd there is no SSH detection. Windows, macOS, BSD, Kubernetes and multi-host setups are not supported.
Firewall neighbours (details in Firewall and Docker):
| Alongside | Result |
|---|---|
| ufw 0.36 | Tested: bans apply; ufw rules unchanged |
| firewalld 2.3 (nftables backend) | Tested: bans apply, survive reload; rules unchanged |
| Docker 26.1, iptables-nft and iptables-legacy | Tested: host services protected; published ports only with docker.mode = "forward" |
| Docker 29.10, native nftables backend (experimental in Docker) | Tested, same as above |
| Rootless Docker, Swarm, macvlan/ipvlan, Podman | Not tested; do not assume coverage |
| Tailscale, WireGuard | Not tested |
Build and install
Needs Go 1.27.4 or newer.
Shell commands
scripts/build.sh
sudo install -m 0755 dist/ipfence-linux-amd64 /usr/local/bin/ipfence
sudo install -m 0644 systemd/ipfence.service /etc/systemd/system/ipfence.service
sudo systemctl daemon-reloadFirst run
Shell commands
sudo ipfence init # report what can be protected; writes a short config
sudo systemctl enable --now ipfence # start observing
sudo ipfence status # review what it detects and would ban
sudo ipfence test "Failed password for invalid user admin from 203.0.113.70 port 40022 ssh2"
sudo ipfence enable # start blockinginit never changes the firewall. If you run it from an SSH session it
allowlists that session's exact client address and says so.
Sample init report (a Debian 13 test machine, shortened):
Plain text
ipfence init: local discovery report (nothing in the firewall was changed)
SERVICE DETECTED SOURCE PARSER PACKET PATH WILL ACTIVATE
ssh yes yes yes yes yes
nginx yes yes yes unknown no
caddy yes no unknown unknown no
ssh
detected: ssh.service is active; 3 sshd process(es) on the host; listening on 0.0.0.0:22, [::]:22
source: journald through journalctl (20 recent sshd entries seen)
parser: OpenSSH password, keyboard-interactive, invalid user and AllowUsers/DenyUsers failures
packet path: host service: the ipfence input hook sees its packets
nginx
...
to activate: opt-in: set [nginx] enabled = true and clients
Allowlist
Allowlisting 10.0.2.2 (that exact address only, from the open SSH session running this command)A detector runs only when all four links hold: the service is detected, its
log source is readable, the parser supports its format, and a ban would
affect its packet path. (A web log with no lines yet is followed and shown as
unverified; only lines that parse completely are ever used.)
Sample dry run:
Plain text
dry run: the database and firewall were not touched
service: ssh
result: failure matched (failed-password)
address: 203.0.113.70 (global)
confidence: high
would count: yes: counts toward a ban at 5 within 10m
not checked here: allowlist entries added with "ipfence allow"; journal sender checks apply only to JSON entriesSample status (shortened):
Plain text
ipfence status at 2026-11-28 01:08:29 UTC (all times UTC)
Daemon running (pid 17821, version 0.1.0, since 2026-11-28 01:08:00 UTC)
Enforcement ENABLED
Config /etc/ipfence/config.toml
Firewall (nftables table inet ipfence)
ownership: owned
chain input: hook input, priority -10, policy accept
sets (entries in the kernel): ban4 2, ban4net 1, ban6 0, ban6net 0, allow4 7, allow6 6
kernel-live drop counters (reset when the table is rebuilt and at reboot):
CHAIN SET PACKETS BYTES
input ban4 12 716
...
Active bans (3)
ADDRESS ORIGIN SERVICE OFFENSE EXPIRES IN IN FIREWALL REASON
203.0.113.50 auto ssh 1 14m 55s yes 5 SSH authentication failures within 10m (latest: failed-password)
198.51.100.0/24 manual - - 6d 23h yes manual: abusive network
203.0.113.80 auto nginx 1 14m 56s yes 3 Nginx exploit probes within 10m (latest: probe:wp-config-backup)
Local counters (persisted in the database since it was created)
bans.auto 2
...Daily use
Shell commands
sudo ipfence ban 198.51.100.7 --for 6h # or --permanent
sudo ipfence unban 198.51.100.7 # removes the ban; does not trust the address
sudo ipfence allow 203.0.113.5 --note laptop # never block it
sudo ipfence allow --remove 203.0.113.5
sudo ipfence status --json
sudo ipfence disable --yes # remove all ipfence firewall rulesIf you are locked out
From a console, or from an address that still works:
Shell commands
sudo ipfence unban <your address> # works even if the daemon is stopped
sudo ipfence allow <your address>
sudo ipfence disable --yes # remove every ipfence rule
sudo nft delete table inet ipfence # the same without ipfenceStop the daemon first if you use nft delete, or it will restore the table
within about 15 seconds. Stopping or restarting the daemon does not remove
rules.
Threat model in brief
ipfence reduces noise and slows password guessing and scanning from individual addresses. It trusts the kernel, root, journald's trusted fields, and the logs of the web server you enable. It does not stop an attacker with many addresses, one who already has local root, one who has compromised the web server writing its logs, or an exploit that succeeds on the first request. The full list is in Privacy and threat model.
Documentation
Everything is listed in the documentation index.
Learn
| What ipfence does | plain English, no background needed |
| Concepts | the ideas it is built on, from zero |
| The story of an attack | a real attack, with real output |
| FAQ and Glossary | quick answers and definitions |
Use
| Getting started | careful first installation |
| Reading the status report | every line explained |
| Everyday tasks | ban, allow, recover, configure, uninstall |
| Troubleshooting | symptoms and recovery |
| Installation and removal | install, upgrade, uninstall, systemd sandbox |
| SSH and journald | which messages count, trust checks, cursors |
| Nginx, Caddy and proxies | formats, probes, trusted proxies |
| Firewall and Docker | packet path, priorities, test matrix |
| IPv6 and lockout | address policy and exemptions |
| Privacy and threat model | what is stored, who is trusted |
Look up
| Commands | every command, option and exit code |
| Settings | every configuration key |
| Messages and errors | what each message means |
| Status JSON, Counters, Files and limits | details |
Develop
| Code tour | where everything is, then ten deeper pages |
| Architecture | data flow, state, ownership, reconciliation |
| Design decisions | why, bugs found, rough edges |
| Development and tests | build, test, virtual machine scripts |
| Release procedure | what to do before publishing |
| Contributing, Security, Changelog | project files |
License
MIT. The repository had no license, so this release uses MIT: it is short, permissive, widely understood, and compatible with the dependencies' MIT, BSD and Apache-2.0 licenses.