What ipfence does, in plain English
This page assumes no knowledge of firewalls or Linux internals. If a word is unfamiliar, it is explained in Concepts or the Glossary.
The one-sentence version
ipfence watches your server's own logs for someone attacking it, and tells the server's firewall to stop listening to that someone for a while.
The problem
Any server reachable from the internet is probed constantly. Automated programs
("bots") try thousands of username and password combinations against SSH, the
service used to log in remotely. Others ask your web server for files that should
never be public, such as /.env (which often holds database passwords), hoping
one was left behind by mistake.
Each single attempt is harmless. The danger is volume: given unlimited tries, a weak password eventually falls, and a forgotten secret file eventually gets found.
The fix is simple to describe: after a few suspicious attempts, stop letting that visitor try. Doing it safely is the hard part.
The analogy
Think of your server as a building.
| In the building | On your server |
|---|---|
| The doors | services such as SSH and your web server |
| The doorman's incident book | log files and the system journal |
| A list of people not to let in | the firewall's ban list |
| The doorman | ipfence |
ipfence is a doorman with strict habits:
- He reads the incident book. He does not stand in the doorway inspecting everyone. He reads what the doors already write down.
- He only believes entries written by the real staff. Anyone could scribble "that man tried to break in" in the margin, to get an innocent person banned. ipfence checks who wrote each entry.
- He counts before acting. One wrong password is a typo. Five in ten minutes is not.
- He never turns away the owner. Your own addresses, and ones you list, are exempt.
- First he only takes notes. Until you say "start enforcing", he writes down who he would have turned away.
- Bans wear off. Fifteen minutes the first time, six hours the second, a week after that.
- He keeps his list on one sheet of his own. He never edits anyone else's.
- He can show his work. Who is banned, why, for how long, and what he cannot protect.
- He phones nobody. Nothing about your server is sent anywhere.
What actually happens
Diagram source
flowchart TD
A["Someone fails to log in, or asks for a secret file"] --> B["Your SSH or web server writes a log line"]
B --> C["ipfence reads that line"]
C --> D{"Written by the real service?"}
D -- no --> X["Ignored and counted"]
D -- yes --> E{"Is this address exempt?"}
E -- yes --> X
E -- no --> F["Add one point for this address"]
F --> G{"Enough points inside the time window?"}
G -- no --> W["Wait for more"]
G -- yes --> H{"Enforcement enabled?"}
H -- no --> I["Record: would have banned"]
H -- yes --> J["Save the ban, then add the address to the firewall"]
J --> K["The kernel silently drops its packets until the ban expires"]The last step matters. ipfence does not sit between the attacker and your server. It puts an address into a list that the Linux kernel consults for every incoming packet. The kernel does the blocking, very quickly, even if ipfence itself is stopped.
A thirty-second example
This is from a real run in a test machine. An attacker at 203.0.113.50 tried
the wrong password for root. The SSH server wrote:
Plain text
sshd-session[1110]: Failed password for root from 203.0.113.50 port 53585 ssh2After the fifth such line within ten minutes, ipfence logged:
Plain text
level=INFO msg=decision event=ban address=203.0.113.50 service=ssh reason="5 SSH authentication failures within 10m (latest: failed-password)"The firewall now held:
Plain text
elements = { 203.0.113.50 timeout 14m59s992ms expires 14m57s268ms }and the attacker's next connection attempt got nothing back:
Plain text
ssh: connect to host 203.0.113.1 port 22: Connection timed outMeanwhile another address, 203.0.113.60, reached the server normally. The
full story follows this attack step by step.
What it watches
| Service | What counts as suspicious | On by default? |
|---|---|---|
| SSH (OpenSSH) | failed passwords, logins for accounts that do not exist, accounts your SSH settings forbid | yes, when ipfence can verify everything it needs |
| Nginx web server | requests only an attacker makes: secret files, tricks to read system files, known exploit strings | no, you turn it on |
| Caddy web server | the same | no, you turn it on |
Why are the web ones off? Because ipfence must know one thing only you know: do visitors connect to your server directly, or through a middleman such as a CDN? If there is a middleman, every visitor appears to come from the middleman's address, and banning it would shut out everybody.
What it deliberately does not do
| It will not... | Because |
|---|---|
| ban someone for one mistake | typos happen |
| count a "403 Forbidden" or "401 Unauthorized" web answer as an attack | ordinary visitors get those all the time |
| ban your own server, your home network by default, or listed addresses | locking yourself out is worse than missing an attacker |
| believe a visitor's claim about their address | anyone can type any address into a web request |
| change firewall rules it did not create | another tool, or you, put them there |
| remove protection when it stops | restarting the doorman must not unlock the door |
| send your data anywhere | that is the point of the project |
| protect against huge floods of traffic | by the time packets reach your server, a flood has already filled the pipe |
| act as a web application firewall | it reacts to logs; it does not inspect or filter requests |
What can go wrong
Being honest about this is part of the design.
- An attacker with many addresses can try a few times from each and stay under the limit.
- Someone sharing your address (an office, a café, a mobile carrier) can get that address banned, including for you.
- Your address may change. An exemption for yesterday's address does not help today.
- The first successful attack wins. ipfence slows guessing; it cannot undo a correct guess. Use SSH keys and keep software updated.
If you are ever locked out, the ways back are in Everyday tasks.
How is this different from fail2ban?
fail2ban does this job, is far more mature and covers many more services. ipfence is deliberately smaller, and puts its effort into showing its work:
- a report, before anything is blocked, of what can and cannot be protected;
- an observe mode that is the default;
- its own firewall table, checked for ownership before every change;
- one static program with nothing sent off the machine.
If you need breadth today, use fail2ban. ipfence is an early release.
Where to go next
| To... | Read |
|---|---|
| learn the vocabulary | Concepts |
| watch an attack unfold in detail | The story of an attack |
| run it yourself | Getting started |
| understand the code you now own | Code tour |