ipfence home page local-first intrusion prevention for Linux

Manual pages

CLI and configuration

A summary of the commands, then every setting in detail. Full command behaviour and output: Command reference.

Commands

Command What it does Changes
init [--ssh-client ADDR] [--dry-run] discovery report; creates the config if absent the config file only, never overwritten
daemon runs in the foreground state; firewall only if enabled
status health, detectors, firewall, bans, allowlist, history, counters nothing
test [--service ssh|nginx|caddy] [--format F] <line | -> parses one line nothing
enable turns blocking on creates the table
disable --yes turns blocking off removes the table, keeps records
ban <addr|cidr> (--for D | --permanent) [--reason T] [--force] manual ban state, firewall
unban <addr|cidr> [--reset-history] removes a ban; does not allowlist state, firewall
allow <addr|cidr> [--note T] never block; removes matching bans state, firewall
allow --remove <addr|cidr> removes an entry added by allow state, firewall
version, help

Every command accepts --config PATH and --json; options may come before or after arguments. ipfence <command> --help lists options. Output has no color or terminal escape codes.

Addresses are literal IPv4 or IPv6, or CIDRs with no host bits set. Names are never resolved.

Manual ban rules

ban is refused when enforcement is off (it would block nothing), and for: loopback, unspecified, multicast or broadcast ranges; an address of this host; a range wider than /8 (IPv4) or /32 (IPv6); anything an allowlist entry fully covers; and a range containing your own SSH client, unless you add --force. Banning an address again replaces its expiry. A private address may be banned deliberately.

Disabling keeps ban records. Enabling again restores the unexpired ones.

Exit codes

Code Meaning
0 success
1 error, including "recorded but not applied to the firewall"
2 usage
3 permission denied (use sudo)
4 another writer is busy
5 firewall ownership cannot be proven; nothing changed in the firewall
6 refused for safety
7 no such ban or allowlist entry
10 test: the line is not a failure ipfence counts

JSON formats: status and change commands.


The settings file

/etc/ipfence/config.toml, in TOML: [section] headings followed by key = value.

Rule
write only what differs from the defaults the file may be empty or absent
unknown settings are errors a typo cannot silently drop an allowlist
invalid values are errors the daemon will not start
unsafe files are refused symlink, not owned by root, writable by others, over 64 KiB
changes need a restart sudo systemctl restart ipfence; bans stay

Durations are written as 90s, 15m, 6h or 7d. Lists use square brackets: ["a", "b"].

A complete, valid example showing many settings:

Settings file (TOML)

[allow]
addresses = ["203.0.113.5", "2001:db8:abcd::/64"]

[ssh]
threshold = 4
window = "15m"

[nginx]
enabled = true
clients = "direct"
format = "main"
access_logs = ["/var/log/nginx/access.log"]

[policy]
durations = ["30m", "12h", "14d"]
forget_after = "60d"

[docker]
mode = "forward"

[log]
level = "info"

[allow]: never block these

Key Type Default
addresses list of addresses or CIDRs []

Never banned automatically, never dropped even inside a network ban, and manual bans fully covered by them are refused. Adding one ends existing bans inside it at the next maintenance. /0 is rejected; ranges wider than /8 or /32 produce a warning. Loopback and this host's own addresses are always allowed without being listed.

Settings file (TOML)

[allow]
addresses = ["203.0.113.5"]

[proxy]: reverse proxies you trust

Key Type Default
trusted list of addresses or CIDRs []

Addresses of proxies as this server sees them. They are never banned. Probes arriving from them are reported (with the visitor the proxy claimed, when logged) instead of banned. Listing an address here does not make its forwarded headers choose any ban target.

[ssh]

Key Type Default Range
enabled true or false automatic
units list of unit names ["ssh.service", "sshd.service"] 1 to 16
threshold number 5 1 to 1000
window duration 10m 10 s to 24 h
  • enabled unset: on when OpenSSH is found and the journal is readable. false: off. true: still requires detection, source, parser and path.
  • units: whose journal entries are accepted when the program path is unknown; per-connection instances such as sshd@...service are included.
  • threshold failures within window cause a ban.

[nginx]

Key Type Default Range
enabled true or false false
clients "direct" or "proxied" none required if enabled
access_logs list of paths ["/var/log/nginx/access.log"] up to 32, absolute
format text "combined" see formats
threshold number 3 1 to 1000
window duration 10m 10 s to 24 h

clients = "direct": visitors connect to this machine. "proxied": they come through proxies listed in proxy.trusted (required). Declaring direct behind a CDN bans CDN addresses.

A custom format is your log_format text:

Settings file (TOML)

[nginx]
enabled = true
clients = "direct"
format = '$remote_addr [$time_iso8601] "$request" $status'

[caddy]

Key Type Default Range
enabled true or false false
clients "direct" or "proxied" none required if enabled
access_logs list of paths [] up to 32
journal_unit unit name none
threshold number 3 1 to 1000
window duration 10m 10 s to 24 h

Exactly one of access_logs or journal_unit.

Settings file (TOML)

[caddy]
enabled = true
clients = "direct"
journal_unit = "caddy.service"

[policy]: how long, and who

Key Type Default Range
durations list of durations ["15m", "6h", "7d"] 1 to 10 entries, 1 m to 365 d, not decreasing
forget_after duration 30d at least 1 h
permanent_after number 0 0, or 3 to 100
auto_ban_private true or false false
  • durations: the first entry for the first offense, and so on; the last repeats.
  • forget_after: quiet time after which an address's offense count restarts.
  • permanent_after: 0 means never. Otherwise from that offense on, permanent when all evidence was high confidence.
  • auto_ban_private: also ban private, unique-local and link-local sources. Check your allowlist first; this is how people lock out their own LAN.

[ipv6]: prefix escalation (off)

Key Type Default Range
prefix_escalation true or false false
prefix number none 48 to 127, required if on
threshold number none 2 to 1000, required if on
window duration 24h 1 m to 30 d

See IPv6 and lockout.

Settings file (TOML)

[ipv6]
prefix_escalation = true
prefix = 64
threshold = 5

[docker]

Key Type Default Values
mode text "off" "off", "forward"

forward adds a forward-hook chain so banned sources are also dropped on traffic passing through this machine, including published container ports. See Firewall and Docker.

[firewall]

Key Type Default Range
priority number -10 -190 to 300

The hook priority of ipfence's chains. Rarely needs changing.

[paths]

Key Default
state_dir /var/lib/ipfence
run_dir /run/ipfence
journalctl /usr/bin/journalctl

Absolute paths. The supplied service unit only permits writing the default directories; changing them needs matching unit changes.

[log]

Key Default Values
level "info" debug, info, warn, error

Logs go to the error stream (the journal under systemd). Decisions and state changes are logged; raw log lines and ordinary requests are not.

[hook]: run your program after a decision

Off unless command is set. The program receives ban data and may send it anywhere.

Key Type Default Range
command list: program then arguments [] absolute path, up to 32 items
timeout duration 5s 100 ms to 30 s
fields list ["event", "address", "service", "reason", "expires"] those plus origin, offense

It runs after a ban (event = ban), a dry-run decision (observe) or a manual unban (unban), only while the daemon is running, one at a time, with only PATH in its environment. The selected fields arrive as one JSON object on standard input; output is discarded. Up to 16 notifications wait; more are dropped and counted in status. No shell is involved; the program must be a file only root can change. The service sandbox applies to it (see Everyday tasks).

Settings file (TOML)

[hook]
command = ["/usr/local/bin/ipfence-notify"]
timeout = "10s"
fields = ["event", "address", "reason"]

Not included in this release: geolocation lookup from a local .mmdb file.