wj-firewall
A macOS PF (Packet Filter) firewall configuration tool with both an interactive terminal UI and a command-line interface.
wj-firewall is not a firewall itself — it configures macOS's built-in PF packet filter. It makes it easy to block incoming traffic on specific network interfaces while keeping others open. The typical use case is blocking incoming connections on Wi-Fi while keeping Tailscale or other trusted networks open, so services listening on 0.0.0.0 are only reachable from trusted networks.
Features
- Interactive TUI — curses-based terminal UI for visual interface management
- CLI — scriptable command-line interface for automation and quick changes
- Per-interface blocking — block incoming traffic on selected interfaces
- Port exceptions — allow specific ports through on blocked interfaces (TCP + UDP)
- ICMP control — optionally block ICMP (ping, traceroute) on blocked interfaces
- PF anchors — rules stored in
/etc/pf.anchors/wj-firewall, surviving OS updates - Zero dependencies — Python 3.12+ stdlib only
Requirements
- Python 3.12+
- macOS (uses PF and pfctl)
- Administrator privileges (sudo) for applying firewall rules
Installation
pip install wj-firewall
Or run directly with uv:
uvx wj-firewall
Quick Start
Interactive TUI
wj-firewall
You will be prompted for your password (sudo). The TUI shows all network interfaces and lets you:
- Space — toggle "block incoming" on the selected interface
- p — open port editing mode (add/remove port exceptions)
- i — toggle ICMP blocking on a blocked interface
- a — apply changes (writes anchor file and reloads PF)
- r — revert to last applied state
- q — quit (confirms if unsaved changes)
Command-Line Interface
# Show current firewall status
wj-firewall status
# Block incoming traffic on Wi-Fi
wj-firewall block en0
# Allow SSH and HTTP through on a blocked interface
wj-firewall allow en0 22 80
# Block ICMP (ping) on an interface
wj-firewall icmp en0 block
# Remove a port exception
wj-firewall deny en0 80
# Unblock an interface
wj-firewall unblock en0
How It Works
wj-firewall uses macOS PF anchors to manage firewall rules without touching the rest of your pf.conf. Rules are stored in /etc/pf.anchors/wj-firewall and referenced from pf.conf via anchor declarations. The tool automatically adds the anchor references if they are missing.
For each blocked interface, the following PF rules are generated:
- Pass outgoing — all outbound traffic and return traffic is allowed
- Pass DHCP — DHCP discovery is always allowed (so you can get an IP address)
- Pass ICMP — ping, traceroute, and PMTU discovery are allowed (unless ICMP is blocked)
- Pass ports — any port exceptions are allowed through (both TCP and UDP)
- Block everything else — all other incoming traffic is silently dropped
Rules use quick for first-match-wins evaluation and block drop (silent discard) to avoid triggering macOS Private Relay issues.
Development
# Set up development environment
make dev
# Run linting and type checking
make check
# Auto-format code
make format
# Build wheel and docs
make build
Licence
Released under the Unlicense — public domain.
Metadata
Release files for wj-firewall 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wj_firewall-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for wj_firewall-1.1.1-py3-none-any.whl |
Release files / wj_firewall-1.1.1-py3-none-any.whl
| Download URL | wj_firewall-1.1.1-py3-none-any.whl |
|---|---|
| Size | 41.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a0b6de2fe3ec4893332d925aafaff9673cc95cbcb0b4fe88ad3db3a4ee5d2d02
|
|
BLAKE2b-256 checksum How to use checksums |
62040833d9bed7f476963144cf5382e1a114eed3bca313151725de48d82321f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Security for wj-firewall 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.