cgtproxy is a transparent proxy RULE manager written in Go,
inspired by cgproxy.
It makes it easier to set per-app transparent proxy dynamically
by automatically updating your nft ruleset according to your configuration,
redirecting network traffic in each cgroup to a specific target.
You can create a bash function for convenient process management:
function cgtproxy-exec() {
local slice="cgtproxy-$1.slice"
shift 1
systemd-run --user --slice "$slice" -P "$@"
}
Use it like this:
# Run without proxy
cgtproxy-exec direct /some/command
# Run without network
cgtproxy-exec drop /some/command
# Run with proxy
cgtproxy-exec proxy /some/command
Check the example configuration for details about
cgtproxy-direct.slice, cgtproxy-drop.slice,
and cgtproxy-proxy.slice.
Systemd's XDG integration documentation suggests that
XDG applications should be launched in a systemd managed unit:
...
To ensure cross-desktop compatibility and encourage sharing of good practices,
desktop environments should adhere to the following conventions:
Application units should follow the scheme
app[-<launcher>]-<ApplicationID>[@<RANDOM>].service or
app[-<launcher>]-<ApplicationID>-<RANDOM>.scope^application-id e.g:
app-gnome-org.gnome.Evince@12345.service
app-flatpak-org.telegram.desktop@12345.service
app-KDE-org.kde.okular@12345.service
app-org.kde.amarok.service
app-org.gnome.Evince-12345.scope
...
For example, Telegram from Flatpak launched by desktop environment
will run in a cgroup like:
This means each application instance's cgroup path follows a pattern
that can be matched by regex.
cgtproxy monitors cgroupfs changes with inotify
and updates nftable rules when new cgroup hierarchies are created.
Why Use cgtproxy?
Common approaches to app-level proxy configuration on Linux have limitations: