NetGuard™ — container network policy enforcement
NetGuard applies ingress and egress rules with nftables inside a container’s network namespace. A host administrator manages policies in /etc/netguard. For rootless Docker workloads, the guard runs as root on the host and applies the policy in the workload’s namespace.
For Debian 13, Ubuntu 26.04 LTS and AlmaLinux 10.3, download the package for your architecture from a successful package workflow run. The installation guide includes the APT and DNF commands.
Build from the source directory on Linux with a Rust toolchain that supports the 2024 edition. Live enforcement requires the nft command.
cargo build --release --locked --offline
sudo install -m 0755 target/release/netguard /usr/local/bin/netguard
netguard --versionsudo netguard init
sudo netguard generate network --name api --egress tcp 198.51.100.8 443
netguard list
netguard validate @apiReplace the example IP address with your service’s destination address. The generator writes /etc/netguard/api.policy. Preview the rules with netguard render @api before applying them in the target network namespace. Run netguard --help for the full command list.
- Policy syntax, kernel drop logs and tests
- systemd services · Docker Compose with systemd · Rootless Docker
- AppArmor with systemd · AppArmor with Docker Compose
- SELinux with Docker Compose
NetGuard is licensed under version 2 of the GNU General Public License (GPL-2.0-only). License text
Parts of this project were created with assistance from AI tools (e.g. large language models). All AI-assisted contributions were reviewed and adapted by maintainers before inclusion. If you need provenance for specific changes, please refer to the Git history and commit messages.