ipfence home page local-first intrusion prevention for Linux

Manual pages

Getting started

A careful first installation, about twenty minutes. Each step says what you should see and what to do if you do not.

This is an early release that changes your firewall. Try it on a machine you can still reach another way (a provider's web console, physical access) before relying on it.

Before you begin

You need Check with
Linux with systemd systemctl --version
root access sudo -v
OpenSSH server ssh -V
Go 1.27.4 or newer, on the machine that builds go version
a second way into the server your provider's console

Tested systems are listed in the README.

Optional but useful for looking at the firewall: sudo apt install nftables or sudo dnf install nftables.

Step 1: build

On any machine with Go (Linux, macOS or Windows with a POSIX shell):

Shell commands

git clone https://github.com/nothikemu/ipfence.git
cd ipfence
scripts/build.sh

You should see:

Plain text

built dist/ipfence-linux-amd64
built dist/ipfence-linux-arm64
wrote dist/THIRD_PARTY_LICENSES.txt

followed by two checksums. Use amd64 for ordinary Intel and AMD servers and arm64 for ARM servers (uname -m prints x86_64 or aarch64).

The first build downloads the Go libraries ipfence depends on.

Step 2: copy it to the server

Shell commands

scp dist/ipfence-linux-amd64 systemd/ipfence.service you@server:/tmp/

On the server:

Shell commands

sudo install -m 0755 /tmp/ipfence-linux-amd64 /usr/local/bin/ipfence
sudo install -m 0644 /tmp/ipfence.service /etc/systemd/system/ipfence.service
sudo systemctl daemon-reload
ipfence version

Plain text

ipfence 0.1.0-dev (commit unknown, built unknown, go1.27.4 linux/amd64)

(The version and commit depend on how you built it.)

Step 3: ask what it can protect

Run this from your normal SSH session:

Shell commands

sudo ipfence init

Read the table at the top:

Column Question If the answer is not "yes"
DETECTED Is the service here? nothing to protect, or it runs in an unusual way
SOURCE Can its events be read? check the log path or journal
PARSER Is the format understood? set the log format
PACKET PATH Would a ban actually block it? declare how clients connect, or it runs in a container
WILL ACTIVATE All four the lines underneath say what is missing

Then look for the Allowlist line. It should say it is allowlisting your address:

Plain text

Allowlisting 10.0.2.2 (that exact address only, from the open SSH session running this command)

Check that this really is your address (echo $SSH_CONNECTION shows it first, before sudo clears it). If it says it could not identify a client:

Shell commands

sudo ipfence allow <your address>          # after step 4, or
sudo ipfence init --ssh-client <address>   # only if no config file exists yet

If you connect from changing addresses (home broadband, mobile), an allow entry helps only until your address changes. Keep your console access working.

Step 4: start watching

Shell commands

sudo systemctl enable --now ipfence
sudo ipfence status

You want:

Plain text

Daemon       running (pid ..., version ..., since ...)
Enforcement  disabled: observing only, nothing is blocked

and in the Detectors table, ssh ... active.

If the daemon is not running: sudo journalctl -u ipfence -n 20 says why. See Troubleshooting.

Step 5: let it observe

Leave it for a day or two. Then:

Shell commands

sudo ipfence status

Look at Would have banned, observed only. For each entry ask: is that an address I want blocked? On an internet-facing server you will usually see strangers within hours.

If you see an address of yours, or a monitoring service you use:

Shell commands

sudo ipfence allow 198.51.100.40 --note "uptime monitor"

Step 6: switch on blocking

Shell commands

sudo ipfence enable

Then, without closing your current session, open a second SSH session to confirm you can still get in.

Observed entries are closed rather than turned into bans. New activity creates real ones.

Step 7: verify

Shell commands

sudo ipfence status                # "Enforcement  ENABLED", ownership: owned
sudo nft list table inet ipfence   # if nft is installed

Optionally, prove it works with a machine you can afford to block, from a different address than yours: fail the password five times, confirm it can no longer connect, then sudo ipfence unban <that address>.

Step 8 (optional): protect your web server

Only if visitors connect directly to this machine (no Cloudflare, no load balancer in front):

Shell commands

sudo nano /etc/ipfence/config.toml

Settings file (TOML)

[nginx]
enabled = true
clients = "direct"
# format = "main"       # needed on Rocky, Alma, RHEL, Fedora and nginx.org packages

Shell commands

sudo systemctl restart ipfence
sudo ipfence status

nginx ... active or unverified (no request logged yet) is good. If it says disabled, the detail lines explain why. For Caddy and for sites behind a proxy, read Nginx, Caddy and proxies first.

Step 9 (optional): containers

If you run Docker and want banned addresses kept away from published container ports too:

Settings file (TOML)

[docker]
mode = "forward"

Read Firewall and Docker for what this does and what has been tested.

Done

Day-to-day commands are in Everyday tasks. To make sense of everything status prints, read Reading the status report.

To back out completely at any point:

Shell commands

sudo ipfence disable --yes
sudo systemctl disable --now ipfence