Files
proxy-suite-flake/docs/usage/per-app.md
T
2026-10-10 16:19:54 +05:00

183 lines
6.2 KiB
Markdown

# Route a single app
Run one program through the proxy, or through zapret, and leave the rest of the system
alone.
## Config
```nix
services.proxy-suite = {
enable = true;
proxy = {
enable = true;
outbounds = [ { tag = "my-vps"; urlFile = "/run/secrets/my-vps-url"; } ];
};
perAppRouting = {
enable = true;
createDefaultProfiles = true; # a profile named after each method below
proxychains.enable = true;
tun.enable = true;
};
};
```
## Run an app
```sh
proxy-ctl apps # list profiles
proxy-ctl apps run tun -- firefox
proxy-ctl apps run proxychains -- curl https://example.com
```
Run it as yourself, not with sudo.
## Which method
| Method | Covers | Notes |
|---|---|---|
| `proxychains` | TCP | Preloads a library into the app. Needs no privileges, but does not work with statically linked programs or most Go programs. |
| `tun` | TCP and UDP | Puts the app in its own cgroup and routes it into a separate TUN. Works with any program. |
| `tproxy` | TCP and UDP | Like `tun`, but intercepts with nftables. |
| `zapret` | What zapret handles | No proxy: runs a separate zapret for the app, to get past DPI. Needs `zapret.enable`; see [Unblock sites without a server](./zapret.md). |
`tun` works with any program. `proxychains` is handy for a quick command.
## Your own profiles
Name profiles after what they are for, to keep commands short:
```nix
services.proxy-suite = {
enable = true;
proxy = {
enable = true;
outbounds = [ { tag = "my-vps"; urlFile = "/run/secrets/my-vps-url"; } ];
};
perAppRouting = {
enable = true;
tun.enable = true;
profiles = [ { name = "browser"; route = "tun"; } ];
};
};
```
Then run `proxy-ctl apps run browser -- chromium`.
## Through one outbound
Send an app through one outbound you pick, past the [routing rules](./routing.md):
```sh
proxy-ctl apps run --via nl -- firefox
proxy-ctl apps run --via nl --route tproxy -- curl https://example.com
```
Or name it in a profile:
```nix
services.proxy-suite = {
enable = true;
proxy = {
enable = true;
outbounds = [ { tag = "nl"; urlFile = "/run/secrets/nl-url"; } ];
};
perAppRouting = {
enable = true;
tun.enable = true;
profiles = [ { name = "game"; route = "tun"; outbound = "nl"; } ];
};
};
```
- An "interface" AmneziaWG outbound, or a global AmneziaWG profile (`--via home`), takes the
app straight into its interface, with no proxy in between, and sends the app's DNS to the
profile's DNS server. See [Use an AmneziaWG config](./amneziawg.md).
- Any other outbound goes through per-app TUN or TProxy (`--route`; TUN when both are
enabled) and needs the sing-box or hybrid backend. Each outbound in use takes one of
`perAppRouting.via.pinSlots`.
- When the outbound is down, the app's connections fail; they never leave another way.
- Add profiles without a rebuild: `proxy-ctl apps add game --via nl`, then
`proxy-ctl apps rm game`. In `proxy-tui` and the desktop app, the Apps tab adds and removes
them, and runs a command via an outbound.
## Keep a route running
`tun`, `tproxy` and `zapret` start their backend with the first app and stop it after the last,
so each first app waits for it to come up. `keepRunning` keeps one running from boot instead:
```nix
services.proxy-suite = {
enable = true;
proxy = {
enable = true;
outbounds = [ { tag = "my-vps"; urlFile = "/run/secrets/my-vps-url"; } ];
};
perAppRouting = {
enable = true;
createDefaultProfiles = true;
tun = {
enable = true;
keepRunning = true;
};
};
};
```
The per-app TProxy and zapret step aside under a global TUN or TProxy (zapret under a global
AmneziaWG profile too), as below, and come back once it stops.
A profile through one outbound can be kept running too, with its own `keepRunning`:
```nix
services.proxy-suite = {
enable = true;
proxy = {
enable = true;
outbounds = [ { tag = "nl"; urlFile = "/run/secrets/nl-url"; } ];
};
amneziaWg = {
enable = true;
profiles.home.configFile = "/run/secrets/home.conf";
};
perAppRouting = {
enable = true;
tun.enable = true;
profiles = [
{ name = "game"; route = "tun"; outbound = "nl"; keepRunning = true; }
{ name = "home"; outbound = "awg:home"; keepRunning = true; }
];
};
};
```
- An "interface" AmneziaWG outbound keeps its rules and DNS forwarder for apps up.
- A global AmneziaWG profile is kept up for apps alone (as `--via` brings it up), unless the
profile is up globally, which carries the apps already.
- Any other outbound keeps its pin slot: it counts against `perAppRouting.via.pinSlots`
for good, and with it the route's backend stays up.
Only declared profiles: one `proxy-ctl apps add` adds still starts with its first app.
## Good to know
- `tun`, `tproxy` and `zapret` profiles start a system service, so they ask for an admin
password unless `userControl` grants the `perApp` scope (see
[Control it day to day](./control.md)).
- While a global TUN or TProxy is running, these three run the app without their route:
the global mode already carries its traffic. `proxy-ctl` prints a note when it does. So
does `--via`, except that an "interface" AmneziaWG outbound still takes the app under a
global TProxy or AmneziaWG profile.
- With `tun` and `tproxy`, the app's DNS queries go through its route wherever its resolver
is, a local one (such as systemd-resolved on 127.0.0.53) or the LAN router. Lookups glibc
hands to nscd (NixOS's default) do not: nscd resolves them itself, outside the route.
`proxy-ctl` warns when nscd runs. Apps that resolve names themselves are not affected:
programs built with Go, and browsers using their own resolver or DNS-over-HTTPS.
- The app follows your [routing rules](./routing.md) like any other proxied traffic.
## See also
- [Wrap programs with the proxy](./wrap-apps.md): a package that always starts through a profile
- [`perAppRouting.profiles`](../options/perAppRouting.md#services-proxy-suite-perapprouting-profiles)
- [`perAppRouting.createDefaultProfiles`](../options/perAppRouting.md#services-proxy-suite-perapprouting-createdefaultprofiles)
- [`perAppRouting.via`](../options/perAppRouting.md#services-proxy-suite-perapprouting-via-pinslots)