ipfence home page local-first intrusion prevention for Linux

Manual pages

Firewall and Docker

The packet path

A ban only helps if the packet passes a chain that drops it.

Traffic Hook Covered
to a service on this host (sshd, Nginx) input always, when enabled
to a published container port on a bridge network forward, after destination NAT only with docker.mode = "forward"
to a published port through docker-proxy (for example IPv6 to an IPv4-only container) input yes
routed through this host (VPN gateway, virtual machines) forward only with docker.mode = "forward"
macvlan/ipvlan containers bypasses the host's filter no

Rules in the input chain do not protect published container ports. Docker's documentation makes the same point about ufw.

Container mode

Settings file (TOML)

[docker]
mode = "forward"

This adds a forward chain with the same drop rules to ipfence's own table. It does not touch Docker's tables, use DOCKER-USER, or disable Docker's firewall management. Because a drop is final, it works whichever backend Docker uses.

Know the scope: banned sources are dropped on every forwarded path, and replies from a banned address to your containers are dropped too.

Detection is unchanged. ipfence does not read container logs or find services inside containers; what it blocks on the forward path are addresses detected from host services or banned by hand.

Docker detection uses the local socket (/run/docker.sock). DOCKER_HOST is ignored, so no remote engine is contacted. Status shows the version, default logging driver, firewall backend and number of containers publishing ports.

Docker logging drivers

ipfence reads no container logs in this release, whatever the driver. It never opens Docker's json-file log files.

Logging driver Container events detected
json-file, local no
journald no: only host sshd entries and a configured Caddy unit are read from the journal
syslog and remote drivers no

Only the engine's default driver is reported; per-container overrides are not inspected.

Tested matrix

Virtual machines, amd64, using test/e2e/matrix.sh. Docker and neighbour results come from Debian 13 only.

Setup Checks Result
Docker 26.1.5, iptables-nft host blocked; published port open in off, blocked in forward (IPv4 and IPv6); others unaffected; container outbound; Docker restart; no other rule changed; disable restores 23/23
Docker 26.1.5, iptables-legacy same 23/23
Docker 29.10.1, native nftables backend same 23/23
ufw 0.36.2 bans apply; reload and restart; ufw rules unchanged 14/14
firewalld 2.3.1, nftables backend bans apply; reload and restart; rules unchanged 13/13

Docker describes its native nftables backend (added in 29.0.0) as experimental; its behaviour may change.

Not tested: Docker on other distributions, firewalld's iptables backend, rootless Docker, Swarm and its ingress network, macvlan/ipvlan, Podman, Kubernetes, Tailscale and WireGuard, and several of these tools combined. Leave docker.mode = "off" in any setup you have not verified yourself, and verify with a real connection from a banned address.

Living with other firewall tools

  • ipfence changes only inet ipfence.
  • An accept in another tool's chain does not override ipfence's drop, and ipfence has no accept rules that could override theirs.
  • nft flush ruleset, which some nftables.service configurations run on reload, deletes every table including ipfence's. The daemon restores it within about 15 seconds. status and init warn when that service is in use.
  • Flowtable offload bypasses forward hooks for offloaded flows; not tested.

Tailscale and WireGuard

This host's own VPN addresses are exempt like any local address. Peers are not: Tailscale uses 100.64.0.0/10, shared with carrier-grade NAT, so ipfence does not allow the whole range. Add your own client:

Shell commands

sudo ipfence allow 100.101.102.103 --note "my laptop"

WireGuard peers usually have private addresses, which are not banned automatically unless you set auto_ban_private.

Looking and diagnosing

Shell commands

sudo ipfence status                      # ownership, chains, sets, counters
sudo nft list table inet ipfence
sudo nft list ruleset                    # everything on the packet path

See Troubleshooting for foreign, drifted and other-install.