Linux

Per-application firewall on Linux

Updated

Short answer

ufw and firewalld filter traffic by port and address, so they cannot block a single application by itself. Per-app control on Linux needs a tool that ties traffic to a process: iptables with an owner or cgroup match, an interactive firewall such as OpenSnitch, or a dashboard firewall such as PacketShield, which uses cgroup v2 and iptables to apply rules per app.

Why ufw and firewalld are not per-app

ufw “application profiles” are just named sets of ports (for example OpenSSH = port 22). They open or close ports for whatever process listens on them; they don’t know which program is making an outgoing connection.

Option 1: iptables owner match (per user or group)

sudo groupadd no-internet
sudo usermod -aG no-internet "$USER"   # log out and back in
sudo iptables -A OUTPUT -m owner --gid-owner no-internet -j REJECT

# Start the app with that group
sg no-internet -c "firefox"

iptables can match outgoing packets by the user or group of the process that sent them. Running an app under a dedicated group lets you block just that app:

Option 2: OpenSnitch (interactive)

OpenSnitch is an open-source application firewall for Linux that prompts you for each new connection and remembers your answers. It suits people who want to approve every connection as it happens.

Option 3: PacketShield (live dashboard, one click)

PacketShield runs as a systemd service and puts each app’s traffic in a cgroup v2, then applies iptables/ip6tables rules to it. The interface lists every app that is online with live speed and the domains it contacts, and blocks an app or a domain (including wildcards) in one click, without prompts.

Requirements: x86_64, systemd and kernel 5.8 or newer (Ubuntu 24.04, Debian 12, Fedora 40, Arch Linux). Packages: .deb, .rpm and AppImage.

Frequently asked questions

Can ufw block a specific application?

No. ufw rules match ports and addresses. Its application profiles are named port lists, so they can’t stop one program from connecting out.

What is the Linux equivalent of Little Snitch?

OpenSnitch is the closest in style (it prompts for each connection). PacketShield offers per-app and per-domain blocking from a live dashboard instead of prompts.

Does PacketShield replace ufw?

No, they work side by side. ufw keeps handling ports and inbound rules; PacketShield adds per-app and per-domain rules for outgoing traffic.