Command reference
Every command, its options, what it changes, real output and exit codes. For a summary table see CLI and configuration.
General
Plain text
ipfence <command> [options]| Common option | Meaning |
|---|---|
--config PATH |
settings file (default /etc/ipfence/config.toml) |
--json |
machine-readable output |
--help |
options of that command |
Options may come before or after arguments. -- ends options. Output has no color
or escape codes.
Most commands need sudo: settings and state are readable by root only.
Which commands change what
| Command | Settings file | Database | Firewall |
|---|---|---|---|
help, version |
|||
test |
read | ||
status |
read | read | read |
init |
created if absent | read | read |
daemon |
read | write | write, if enabled |
enable, disable |
read | write | write |
ban, unban, allow |
read | write | write, if enabled |
help
Terminal session
$ ipfence help
Usage: ipfence <command> [options]
Local intrusion prevention for Linux. Nothing is sent off this machine.
Commands:
init discover services, report what can be protected, write a
minimal config if none exists. Changes no firewall state.
daemon run in the foreground (observes until enabled)
status show health, detectors, firewall, bans and allowlist
test <line> parse one log line; reads and writes nothing else
enable start blocking: create the ipfence nftables table
disable --yes stop blocking: remove the ipfence nftables table
ban <IP|CIDR> block now; requires --for <duration> or --permanent
unban <IP|CIDR> remove an active ban (does not allowlist it)
allow <IP|CIDR> never block this address; --remove undoes it
version show build information
help show this text
...ipfence with no command prints this to the error stream and exits 2.
version
Terminal session
$ ipfence version
ipfence 0.1.0 (commit unknown, built unknown, go1.27.4 linux/amd64)--json gives name, version, commit, built, go, target. Nothing is
checked against any server.
init
Plain text
ipfence init [--ssh-client ADDRESS] [--dry-run] [--json]| Option | Meaning |
|---|---|
--ssh-client |
allowlist this one address in the new file |
--dry-run |
report only; write nothing |
Does, in order: load existing settings (if invalid, stop without touching them); run discovery; inspect the firewall read-only; identify your SSH client; create the settings file only if none exists.
How the SSH client is chosen:
| Situation | Result |
|---|---|
--ssh-client given |
that address |
| a session address from the environment or parent processes, connected now | that address |
| one named but not connected | not allowlisted; told to use --ssh-client |
| none | told to allowlist yourself |
| a file already exists | nothing written; prints the allow command |
With --json: discovery, firewall, ssh_client (address, source,
action), config (path, found, created, content), warnings.
Full example output: The story of an attack.
daemon
Plain text
ipfence daemonRuns in the foreground until interrupted, logging to the error stream. Normally
started by systemd. It enforces only if enable was run. Stopping it leaves the
firewall as it is. Exit 4 if another writer is active.
Plain text
level=INFO msg="detector active" service=ssh source="journald through journalctl (20 recent sshd entries seen)"
level=INFO msg=ready version=0.1.0
level=INFO msg=decision event=ban address=203.0.113.50 service=ssh reason="5 SSH authentication failures within 10m (latest: failed-password)"status
Plain text
ipfence status [--json]Explained section by section in Reading the status report. Works with or without the daemon. JSON fields: Status JSON.
test
Plain text
ipfence test [--service ssh|nginx|caddy] [--format FORMAT] "<line>"
ipfence test - # read the first line from standard input| Option | Meaning |
|---|---|
--service |
try only this parser (default: journal JSON, Caddy, Nginx, then SSH) |
--format |
Nginx format for this run (default from settings) |
Accepts an sshd message, a syslog-style line (the prefix is removed), a journal JSON entry (sender checks applied), an Nginx line or a Caddy JSON line.
It reads the settings file and the list of local addresses. It does not open the
database or the firewall, so entries added with ipfence allow are not
considered.
Because it reads the settings file, which init creates readable by root only,
use sudo. Without it you get permission denied and exit 3.
Terminal session
$ sudo ipfence test "Failed password for root from 203.0.113.50 port 40022 ssh2"
dry run: the database and firewall were not touched
service: ssh
result: failure matched (failed-password)
address: 203.0.113.50 (global)
confidence: normal
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 entries
$ sudo ipfence test --json "Invalid user admin from 203.0.113.50 port 22"
{
"service": "ssh",
"parsed": true,
"matched": true,
"kind": "invalid-user",
"address": "203.0.113.50",
"scope": "global",
"high_confidence": true,
"would_count": true,
"why": "counts toward a ban at 5 within 10m"
}| Exit | Meaning |
|---|---|
| 0 | a failure was recognized (even if the address is exempt) |
| 10 | not a countable failure |
enable
Plain text
ipfence enable [--json]Checks the table is absent or ipfence's, closes dry-run entries, applies unexpired bans and the allowlist, and prints what was created and how to recover. If the firewall cannot be set up, enforcement stays off.
| Exit | Meaning |
|---|---|
| 0 | enabled |
| 5 | the table cannot be proven ipfence's |
| 1 | other failure |
disable
Plain text
ipfence disable --yes [--json]Without --yes it refuses (exit 6) and explains. Removes the table if provably
ipfence's; keeps all records.
Terminal session
$ sudo ipfence disable --yes
enforcement is off and the ipfence nftables table is gone; ban records are keptban
Plain text
ipfence ban <IP|CIDR> (--for DURATION | --permanent) [--reason TEXT] [--force]| Option | Meaning |
|---|---|
--for |
30s, 15m, 6h, 7d; at least 1 s |
--permanent |
no expiry |
--reason |
your note, up to 200 characters |
--force |
allow a range containing your own SSH client |
Exactly one of --for or --permanent.
Terminal session
$ sudo ipfence ban 198.51.100.0/24 --for 7d --reason "abusive network"
banned 198.51.100.0/24 until 2026-12-06T02:43:16Z
note: a network ban can block unrelated devices and users
$ sudo ipfence ban 203.0.113.77
ipfence: choose exactly one expiry: --for <duration> or --permanent (see "ipfence ban --help")
$ sudo ipfence ban example.com --for 1h
ipfence: "example.com" is not a literal IP address (see "ipfence ban --help")
$ sudo ipfence ban 10.0.0.5/8 --for 1h
ipfence: "10.0.0.5/8" has host bits set; did you mean 10.0.0.0/8? (see "ipfence ban --help")Safety refusals are listed in Everyday tasks.
| Exit | Meaning |
|---|---|
| 0 | banned and in the firewall |
| 1 | recorded but the firewall write failed (retried automatically) |
| 2 | bad arguments |
| 5 | recorded, but the table is not ipfence's |
| 6 | refused for safety, including while enforcement is off |
unban
Plain text
ipfence unban <IP|CIDR> [--reset-history]Removes the ban for exactly that address or range. --reset-history also forgets
the repeat count. With --reset-history and no active ban, the history is still
forgotten, although the command reports "not banned" (exit 7).
| Exit | Meaning |
|---|---|
| 0 | removed |
| 7 | no ban for exactly this; the message names covering or narrower bans |
| 1, 5 | recorded but the firewall was not updated |
allow
Plain text
ipfence allow <IP|CIDR> [--note TEXT]
ipfence allow --remove <IP|CIDR>| Exit | Meaning |
|---|---|
| 0 | done |
| 6 | /0, or removing a built-in, host or settings-file entry |
| 7 | --remove of something not added with allow |
Terminal session
$ sudo ipfence allow --remove 127.0.0.1
ipfence: refused: 127.0.0.1 is built in and cannot be removed hereExit codes
| Code | Name | Meaning |
|---|---|---|
| 0 | ok | success |
| 1 | error | any other failure, including "recorded but not applied" |
| 2 | usage | wrong arguments |
| 3 | permission | run with sudo |
| 4 | busy | another writer holds the lock or the daemon is not answering |
| 5 | unsafe firewall | ownership cannot be proven |
| 6 | refused | declined for safety |
| 7 | not found | no such ban or allow entry |
| 10 | no match | test only |
JSON for change commands
JSON
{
"ok": true,
"result": {
"recorded": true,
"message": "banned 203.0.113.9 until 2026-11-29T03:00:00Z",
"notes": [],
"removed": []
}
}(Empty lists are omitted.) On failure ok is false with code and error.
result.recorded can be true while ok is false: saved, but not yet applied.