A desktop client from a subscribe file
This recipe turns etemenanki-app into a proxy client for your own machine. A provider gives you a subscribe file that lists their nodes, a DNS setup and route groups, such as “Streaming” or “Ads”. Your own file adds two local proxies, a SOCKS5 port and an HTTP port, and says which node each route group uses. A small HTTP API on loopback lets a script or a tray application switch those picks while the proxy runs.
Use it when a provider hands out an etemenanki subscribe file and you want to keep your picks when the provider updates it. For the file format itself, see Subscribe files; for the API, REST API.
flowchart LR APP["Browser, other apps"] -->|"SOCKS5 :1080, HTTP :8080"| C["etemenanki-app"] C -->|"route group: Streaming, Proxy, …"| N["Provider's nodes"] C -->|"Local, Ads"| D["direct / blackhole"] S["curl, a tray app"] -->|"API :9090"| C
Before you start
Section titled “Before you start”- etemenanki-app on your machine, as described in Install. This page uses Linux paths; any directory works if you change the paths in the file.
- The provider’s subscribe file, saved as
/etc/etemenanki/subscribe.toml. geoip.datandgeosite.datfrom v2fly, when the provider’s route groups usegeoiporgeositematchers. Split routing shows where to get them.curl, for the API steps.
The two files
Section titled “The two files”# A desktop client: SOCKS5 and HTTP proxies on this machine, nodes and route# groups from a provider's subscribe file, and a local API to switch which# node a route group uses.## Put the provider's file at the path in [subscribe]. Saving either file# reloads; so does every route switch through the API.
[[inbound]]tag = "socks-in"protocol = "socks"listen = "127.0.0.1"port = 1080
[[inbound]]tag = "http-in"protocol = "http"listen = "127.0.0.1"port = 8080
# Routing comes from the subscribe file's route groups. [route] names the# geodata files those groups use.[route]geoip = "/etc/etemenanki/geoip.dat"geosite = "/etc/etemenanki/geosite.dat"
[subscribe]path = "/etc/etemenanki/subscribe.toml"
# The API rewrites these picks. A group without a pick uses what it# inherits in the subscribe file.[subscribe.routes]default = "vless-ws"
# Loopback only and no secret: every program on this machine may switch# routes, nothing else can reach it.[api]listen = "127.0.0.1:9090"# A subscribe file, as a provider hands it out. It lists the nodes# ([[proxy_server]]), a DNS setup ([dns]) and route groups ([[route_group]]).# Every host, address, key and password here is a placeholder.
# ---------------------------------------------------------------------------# Nodes. Each becomes an outbound tagged with its name.# ---------------------------------------------------------------------------[[proxy_server]]name = "vless-ws"server = "proxy1.example.com"port = 443protocol = "vless"id = "11111111-2222-3333-4444-555555555555"# WebSocket with TLS; the TLS name defaults to the server.stream = { network = "ws", path = "/ws", tls = {} }
[[proxy_server]]name = "trojan-tls"server = "proxy2.example.com"port = 443protocol = "trojan"password = "replace-with-a-long-random-password"# TLS over plain TCP.stream = { network = "tcp", tls = {} }
[[proxy_server]]name = "ss-2022"server = "192.0.2.10"port = 8388protocol = "shadowsocks"method = "2022-blake3-aes-128-gcm"password = "AAAAAAAAAAAAAAAAAAAAAA=="
[[proxy_server]]name = "hy2"server = "proxy3.example.com"port = 443protocol = "hysteria2"password = "replace-with-a-long-random-password"obfs = { type = "salamander", password = "replace-with-a-long-random-obfs-key" }# Port hopping across the ports the server forwards, and the client's rates.ports = "443,20000-30000"hop_interval = 30up = "50 mbps"down = "200 mbps"
[[proxy_server]]name = "wg"server = "2001:db8::10"port = 51820protocol = "wireguard"private_key = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="peer_public_key = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="address = ["10.0.0.2", "2001:db8:a::2"]
# ---------------------------------------------------------------------------# DNS. When present, every key is required.# ---------------------------------------------------------------------------[dns]# Asked directly: the nodes' host names, and the name of dns.example.com below.pre_proxy = ["udp://192.0.2.53:53"]# Asked through the route table: everything else.through_proxy = ["https://dns.example.com/dns-query"]use_hosts = true# Reach a node over IPv4 when its name has both A and AAAA records.connect_ipv6 = "tolerated"resolve_ipv6 = true
# ---------------------------------------------------------------------------# Route groups, matched from top to bottom. A group sends what it matches to# the node the user picks for it, or else to what it inherits.# ---------------------------------------------------------------------------[[route_group]]name = "Ads"inherit = "blackhole"matches = [{ geosite = ["category-ads-all"] }]
[[route_group]]name = "Streaming"inherit = { group = "Proxy" }matches = [{ geosite = ["netflix"] }]
[[route_group]]name = "Local"inherit = "direct"matches = [{ geoip = ["private"] }, { domain_suffix = ["lan"] }]
[[route_group]]name = "Proxy"matches = [{ domain_suffix = ["example.org"] }, { network = ["udp"] }]The split is deliberate. The provider’s file holds everything that changes when the provider changes: the nodes, the DNS setup and the route groups. Your file holds what is yours: the local ports, the geodata paths, the picks and the API. When the provider sends a new file, you replace theirs and keep yours.
How the two combine:
- Every node becomes an outbound tagged with the node’s name:
vless-ws,trojan-tls,ss-2022,hy2andwghere. - Route groups are the routing table. A flow goes to the first group whose
matchesmatch it. Your own[[route.rule]]entries, if you write any, are ignored while[subscribe]is set. - A group uses your pick, if
[subscribe.routes]has one for it, and otherwise what the group inherits: another group ({ group = "Proxy" }),direct,blackhole, ordefault. defaultis the pick for everything no group matches. Here it isvless-ws, and theProxygroup inherits it.
Run it
Section titled “Run it”-
Put both files in place and check them.
--testreads the subscribe file too:Terminal window etemenanki-app --test -c /etc/etemenanki/config.tomlConfiguration OK. -
Start the proxy. In the foreground, or with the unit from Running in production:
Terminal window etemenanki-app -c /etc/etemenanki/config.tomlINFO etemenanki_supervisor::system::listener: inbound socks-in listening on 127.0.0.1:1080INFO etemenanki_supervisor::system::listener: inbound http-in listening on 127.0.0.1:8080INFO etemenanki_app::instance: config loaded: built [dns, outbound vless-ws@v1, outbound trojan-tls@v1, outbound ss-2022@v1, outbound hy2@v1, outbound wg@v1, outbound direct@v1, outbound blackhole@v1, route, inbound socks-in, inbound http-in]INFO etemenanki_app: API listening on 127.0.0.1:9090directandblackholeappear as outbounds because the route groups name them; etemenanki-app creates them when no outbound of yours has those tags. -
Point your applications at it. Use
socks5h://127.0.0.1:1080where an application takes a SOCKS5 proxy, so that it sends names rather than addresses and the domain matchers see them, orhttp://127.0.0.1:8080where it takes an HTTP proxy. From a shell:Terminal window curl --socks5-hostname 127.0.0.1:1080 https://example.com
See where each group goes
Section titled “See where each group goes”GET /v1/routes shows every group, its pick, what it inherits, and where its traffic goes now:
curl -s http://127.0.0.1:9090/v1/routes{ "default": { "pick": "vless-ws", "target": "vless-ws" }, "groups": [ { "name": "Ads", "pick": null, "inherit": "blackhole", "target": "blackhole" }, { "name": "Streaming", "pick": null, "inherit": { "group": "Proxy" }, "target": "vless-ws" }, { "name": "Local", "pick": null, "inherit": "direct", "target": "direct" }, { "name": "Proxy", "pick": null, "inherit": "default", "target": "vless-ws" } ], "targets": [ { "name": "vless-ws", "kind": "node" }, { "name": "trojan-tls", "kind": "node" }, { "name": "ss-2022", "kind": "node" }, { "name": "hy2", "kind": "node" }, { "name": "wg", "kind": "node" }, { "name": "direct", "kind": "direct" }, { "name": "blackhole", "kind": "blackhole" } ]}Streaming has no pick, so it follows Proxy, which follows default: its traffic goes to vless-ws. targets lists every name a pick may use.
Switch a group
Section titled “Switch a group”Send streaming traffic through the Hysteria 2 node instead:
curl -s -X PUT -H 'Content-Type: application/json' \ -d '{"target": "hy2"}' http://127.0.0.1:9090/v1/routes/Streaming{"status":"applied","built":["route"],"swapped":[],"drained":[],"rebound":[],"restarted":[],"removed":[],"reused":["dns","outbound vless-ws@v1","outbound trojan-tls@v1","outbound ss-2022@v1","outbound hy2@v1","outbound wg@v1","outbound direct@v1","outbound blackhole@v1","inbound socks-in","inbound http-in"]}The API wrote the pick into your config, as one new line under [subscribe.routes], and reloaded:
[subscribe.routes]default = "vless-ws"Streaming = "hy2"The answer is the reload report. Only the routing table was built again; every node and both listeners were reused, so no connection was dropped. Connections that were already open stay on the node they started on, and new streaming connections go to hy2. To close the open ones the switch moved, so their apps reconnect through hy2, add "close": true to the body; see Switching a route. Because the pick lives in the file, it survives a restart, and you can also change it by editing the file.
To go back to what the group inherits, remove its line from [subscribe.routes] and save the file. Percent-encode a group name with spaces in the path, for example /v1/routes/Video%20Streaming.
Watch the traffic
Section titled “Watch the traffic”GET /v1/traffic is an event stream with one event a second: the bytes sent and received since the start, the rates over the last second and the number of live flows, in total and per inbound and outbound tag:
curl -sN http://127.0.0.1:9090/v1/trafficevent: trafficdata: {"tick":2,"interval_ms":1001,"up":0,"down":0,"up_rate":0,"down_rate":0,"flows":0,"inbounds":{},"outbounds":{}}GET /v1/connections lists the live connections, and DELETE /v1/connections/{flow} closes one; see Endpoints.
When the provider updates the file
Section titled “When the provider updates the file”Save the new subscribe file over the old one in one step, by writing it next to the old one and renaming it, so that the proxy never reads half a file. etemenanki-app watches the subscribe file’s directory and reloads. When the DNS setup is unchanged, nodes whose settings did not change keep running; changed ones are built anew, and new connections use them.
A pick must keep naming something. If the new file renames or removes a node you picked, or a group you have a pick for, the whole reload is refused and the proxy keeps running as it was:
ERROR etemenanki_app::instance: reload: subscribe: [subscribe.routes] "Streaming" = "hy2": no node, outbound or balancer has that name; keeping the running configFix the pick in your file, or remove it, and the next save loads both files.
Common errors
Section titled “Common errors”Each of these appears after configuration invalid: under --test, after failed to start: at startup, and in a reload: …; keeping the running config line on a reload. The API answers a switch it cannot make with the same message in {"error": …}.
| Message | Cause | Fix |
|---|---|---|
subscribe file /etc/etemenanki/subscribe.toml: No such file or directory (os error 2) |
The subscribe file is not where [subscribe] path says |
Save it there, or fix the path |
subscribe: [subscribe.routes] names "Video", which is not a route group in … |
A pick for a group the file does not have, often after the provider renamed it | Rename or remove the pick |
subscribe: [subscribe.routes] "Streaming" = "hy3": no node, outbound or balancer has that name |
A pick names a node that does not exist | Pick a name from targets |
[api] listen 0.0.0.0:9090: an API reachable from other hosts needs a secret; listen on a loopback address or a unix socket, or set one |
The API listens beyond loopback without a secret | Keep it on 127.0.0.1, or set secret |
failed to start: API on 127.0.0.1:9090: Address already in use (os error 98) |
Another program holds the API port | Pick another port in [api] listen |
building route failed: No such file or directory (os error 2) |
A geodata file the route groups need is missing | Download it to the path in [route] |
WARN … [subscribe] is set, so the config's 1 [[route.rule]] entries are ignored; … |
Your file still has [[route.rule]] entries |
Remove them; the route groups do the routing |
The API’s own answers:
| Answer | Cause |
|---|---|
404 {"error":"no route group named \"Video\""} |
The group in the path does not exist |
422 {"error":"no node, outbound or balancer is named \"hy3\"; the route view lists them"} |
The target is not one of targets |
409 |
The file changed since the ETag you sent in If-Match |
Subscribe files lists the errors of the file format itself.