6.2 KiB
Route a single app
Run one program through the proxy, or through zapret, and leave the rest of the system alone.
Config
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
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. |
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:
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:
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:
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. - 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 ofperAppRouting.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, thenproxy-ctl apps rm game. Inproxy-tuiand 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:
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:
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
--viabrings 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.pinSlotsfor 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,tproxyandzapretprofiles start a system service, so they ask for an admin password unlessuserControlgrants theperAppscope (see Control it day to day).- While a global TUN or TProxy is running, these three run the app without their route:
the global mode already carries its traffic.
proxy-ctlprints 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
tunandtproxy, 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-ctlwarns 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 like any other proxied traffic.
See also
- Wrap programs with the proxy: a package that always starts through a profile
perAppRouting.profilesperAppRouting.createDefaultProfilesperAppRouting.via