No description
  • Python 98.1%
  • Makefile 1.9%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-27 20:13:31 +08:00
tests added 2026-10-27 20:13:31 +08:00
ipwall.py added 2026-10-27 20:13:31 +08:00
Makefile added 2026-10-27 20:13:31 +08:00
README.md added 2026-10-27 20:13:31 +08:00

ipwall

A terminal UI for managing iptables / ip6tables — browse chains, add and reorder rules, flip policies, watch counters, and undo mistakes, without memorising netfilter syntax.

Single file, pure Python standard library. No build step, no dependencies.

┌─ Chains (4) ───────────┬─ INPUT · policy DROP · 6 rules ───────────────────────┐
│ INPUT             DROP │   #   PKTS    BYTES RULE                              │
│ FORWARD           DROP │   1   1.2K    345K  -i lo -j ACCEPT                   │
│ OUTPUT          ACCEPT │   2   890K    1.1G  -m conntrack --ctstate RELATED,…  │
│ SSH-GUARD           ·2 │   3    412     28K  -p tcp -m tcp --dport 22 -j SSH-… │
│                        │   4      0       0  -p tcp -m multiport --dports 80,… │
└────────────────────────┴───────────────────────────────────────────────────────┘

Requirements

Python 3.9+ and the iptables binaries. Root, or a sudo that can reach them.

Install

sudo make install            # -> /usr/local/bin/ipwall
sudo make install PREFIX=~/.local
make uninstall

make on its own lists every target. make check runs the smoke tests, which use the in-memory demo ruleset and never open the live firewall. make demo launches the UI against that same fake ruleset.

Or skip make entirely — it's one file with no dependencies:

chmod +x ipwall.py && sudo install -m 755 ipwall.py /usr/local/bin/ipwall

Usage

ipwall --demo          # explore the UI against a fake ruleset — safe, no privileges
sudo ipwall            # manage the live IPv4 ruleset
sudo ipwall -6 -t nat  # start on the IPv6 nat table
sudo ipwall --watch 2  # refresh counters every 2 seconds
sudo ipwall --dry-run  # change nothing; log what would have run (press L to see it)

Start with --demo. It is the real interface driven by an in-memory ruleset, so every key does exactly what it will do for real.

Keys

↑ ↓ k j · PgUp/PgDn · g G move · page · first/last
Tab · ← → · Enter switch pane · chains ⇄ rules
t T · 1…5 · 6 next/prev table · jump to table · IPv4 ⇄ IPv6
/ · Esc · < > filter rules · clear filter · scroll rule text
a · A · i add rule (guided form) · add raw spec · insert above cursor
e · d · J K edit rule · delete rule · move rule down/up
y · p · z yank rule · paste below · zero counters
c · x hide counters · exact ⇄ human-readable counters
P · n · X · R · F policy · new chain · delete chain · rename · flush
u · Ctrl-R · r undo · redo · reload from kernel
w · S · O · L write ruleset to disk · save snapshot · restore snapshot · command log
? · q help · quit

How it works

Rules are read with iptables -S, which prints them in the exact syntax you'd type, so what the UI shows is what the kernel holds. Counters come from iptables -L -n -v -x and are matched to rules by position.

Every mutating action snapshots the full ruleset (iptables-save) first, so u restores the previous state exactly — including reorders, flushes, and whole-ruleset restores. The snapshot stack holds the last 50 changes.

Adding a rule through the form (a) shows the exact command it will run as you type it. If a field combination is invalid — ports without a protocol, a missing target — it says so before anything is executed.

Safety notes

  • Changes take effect immediately, as with iptables itself. They live in the kernel only; press w to write them where your distro reloads them at boot (/etc/iptables/rules.v4, /etc/sysconfig/iptables, …).
  • Setting the INPUT or FORWARD policy to DROP can lock you out of a remote session. The confirmation dialog warns you; u undoes it.
  • --dry-run executes nothing and records every command it would have run.