订阅文件
订阅文件是代理服务商交给客户端的东西:它提供的服务器(节点)、一套 DNS 设置,以及说明哪些流量应该走哪个节点的路由组。它是一个独立的 TOML 文件,与配置文件分开。配置中的 [subscribe] 一节指定这个文件,并为每个路由组选择节点;etemenanki-app 在每次加载时把两者合并。
etemenanki-app 从不下载订阅文件。由你或管理客户端的程序把它放到磁盘上;保存它会像保存配置文件一样触发代理重载。
从服务商获取服务器的客户端才需要订阅文件。你自己配置的服务器不需要它:把出站和规则直接写在配置文件里即可。
| 文件 | 由谁编写 | 内容 |
|---|---|---|
| 订阅文件 | 服务商 | [[proxy_server]] 节点、可选的 [dns],以及 [[route_group]] 路由组 |
| 配置文件 | 你 | 入站、[route] 中的 geodata 路径、带有你的选择的 [subscribe],以及可选的自有出站、负载均衡器和 [api] |
一个最小的客户端
Section titled “一个最小的客户端”配置文件保存属于你的部分:两个本地入站、geodata 文件、订阅文件的路径和你的选择。订阅文件带来五个节点、一套 DNS 设置和四个路由组。其中的每个值都是占位符。
# A local client that takes its nodes, route groups and DNS setup from a# subscribe file. This file keeps what is yours: the inbounds, the geodata# paths, and which node each route group uses.## Put the provider's file at the path below. Saving either file reloads.
[[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] still names# the geodata files those groups use.[route]geoip = "/etc/etemenanki/geoip.dat"geosite = "/etc/etemenanki/geosite.dat"
[subscribe]path = "/etc/etemenanki/subscribe.toml"
# Your picks: a route group's name, or `default` for traffic no group# matches, and the node (or outbound, balancer, "direct" or "blackhole")# that carries it. A group without a pick uses what it inherits.[subscribe.routes]default = "vless-ws"Streaming = "trojan-tls"# 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"] }]使用这两个文件时,流量的去向如下:
| 流量 | 路由组 | 去向 | 原因 |
|---|---|---|---|
| 广告域名 | Ads |
blackhole |
没有选择;该组继承 blackhole |
| Netflix | Streaming |
trojan-tls |
在 [subscribe.routes] 中选择了它 |
私有地址和 .lan 域名 |
Local |
direct |
没有选择;该组继承 direct |
example.org 和所有 UDP |
Proxy |
vless-ws |
没有选择;该组继承 default,而 default 选择的是 vless-ws |
| 其余所有流量 | 无 | vless-ws |
default 的选择 |
路由组按从上到下的顺序尝试,所以发往私有地址的 UDP 流量归 Local,而不是 Proxy。
-
把服务商的文件保存到
[subscribe] path指定的路径。 -
同时检查两个文件:
etemenanki-app --test -c /etc/etemenanki/config.toml会像启动时一样读取订阅文件。 -
启动代理;如果代理已在运行,保存配置文件即可。
[subscribe] 一节
Section titled “[subscribe] 一节”| 键 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
path | path | 是 | — | 订阅文件。相对路径按进程的工作目录解析,与配置中的其他路径一样。不写时配置会被拒绝,报 [subscribe] needs a path naming the subscribe file。每次加载都会读取这个文件,修改它会触发重载。 |
routes | table | 否 | — | 你的选择,写作 [subscribe.routes]:每个键是一个路由组的名字,或者是 default(表示没有任何路由组匹配的流量),每个值是承载这部分流量的 tag。值可以是某个节点、配置自身的出站或负载均衡器,也可以是 direct 或 blackhole。键不是路由组(报 [subscribe.routes] names "…", which is not a route group in <file>),或者值找不到对应的对象(报 [subscribe.routes] "…" = "…": no node, outbound or balancer has that name),配置都会失败。没有选择的路由组使用它继承的目标。default 会覆盖 [route] default。 |
带有 [subscribe] 的配置不需要自己的 [[outbound]]:节点就是出站。
两个文件如何合并
Section titled “两个文件如何合并”flowchart LR SUB["订阅文件"] --> NODES["节点"] SUB --> GROUPS["路由组"] SUB --> SDNS["[dns]"] CFG["配置文件"] --> IN["[[inbound]]"] CFG --> OWN["自有出站和负载均衡器"] CFG --> PICKS["[subscribe.routes]"] NODES --> OUT["出站"] OWN --> OUT GROUPS --> RULES["路由规则"] PICKS --> RULES SDNS --> DNS["解析器"]
- 节点变成出站,每个出站以节点的
name为 tag,排在配置自身的出站之后。路由规则、选择和负载均衡器都可以像引用出站一样引用节点。 - 路由组变成路由规则,按文件中的顺序排列,第一条匹配的规则生效。配置自身的
[[route.rule]]会被忽略,并输出一条警告:[subscribe] is set, so the config's <n> [[route.rule]] entries are ignored; routing comes from the route groups in <file>。[route]中的geoip和geosite仍然指定路由组使用的 geodata 文件。 - 默认路由是
[subscribe.routes]中的default选择;没有时用[route] default;再没有时用第一个出站:配置自身的第一个出站,配置没有出站时则是第一个节点。 - 订阅文件的
[dns]取代配置的[dns]。配置的[dns]设置了任何键时,会输出一条警告说它被忽略:<file> has a [dns] section, so the config's [dns] is ignored。订阅文件没有[dns]时,照常使用配置的[dns]。 - 路由引用
direct和blackhole时它们就会存在。 继承direct的路由组、选择blackhole的条目,都不需要同名的出站:etemenanki-app 会自动添加一个freedom或blackhole出站。使用订阅文件时,被路由当作direct或blackhole的 tag 必须名副其实:配置中使用这个 tag 的其他协议出站或负载均衡器会被拒绝,这样本应直连的流量不会从一个恰好叫direct的代理流出。 - 其余部分仍然来自配置:所有入站,以及配置自身的出站和负载均衡器。
节点:[[proxy_server]]
Section titled “节点:[[proxy_server]]”每个节点是一个 [[proxy_server]] 表。name、server、port 和 protocol 是所有节点共有的键;protocol 决定节点还能使用下面哪些键。键名沿用应用的 [outbound.settings],所以节点读起来就像它生成的出站,检查方式也相同:节点中的错误会以出站的形式指出节点名,例如 outbound wg: invalid wireguard private_key。
| 键 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
name | string | 是 | — | 节点的名字,即它所生成的出站的 tag,也是选择时使用的名字。它不能与其他节点重名,也不能与配置自身的出站或负载均衡器的 tag 相同(否则报 subscribe: node "…" is defined twice, or shares its name with a config outbound)。 |
server | string | 是 | — | 服务器的主机名或 IP 地址,不带端口。IPv6 地址直接写(2001:db8::10)。域名用文件中 [dns] 的 pre_proxy 服务器解析(文件没有 [dns] 时用配置的 [dns])。 |
port | u16 | 是 | — | 服务器端口:hysteria2 和 wireguard 为 UDP 端口,其他协议为 TCP 端口。 |
protocol | string (enum) | 是 | — | vless、vmess、trojan、shadowsocks、socks、http、hysteria2、wireguard、anytls 或 sss 之一,必须完全一致。这里不接受 hy2 这类应用内的别名。它决定节点可以使用下面哪些键;写了其他协议的键会导致解析失败,读取方不认识的协议也一样(unknown variant)。 |
stream | table | 否 | — | vless、vmess、trojan、shadowsocks、socks、http 和 sss:传输层,写成内联表,例如 { network = "ws", path = "/ws", tls = {} }。见下方的 stream 表。不写即为普通 TCP。anytls 没有 stream:它总是运行在 TLS 之上,TLS 键直接写在节点里。 |
id | string | 视情况 | — | vless、vmess 和 sss 必填:用户的 UUID。 |
flow | string (enum) | 否 | — | vless:XTLS flow,xtls-rprx-vision 或不写。它需要 reality stream(否则报 vless vision (xtls-rprx-vision) rides only over reality);其他取值报 unknown vless flow。 |
security | string (enum) | 否 | "auto" | vmess:正文加密算法,auto(即 AES-128-GCM)、aes-128-gcm 或 chacha20-poly1305,必须完全一致。 |
method | string (enum) | 视情况 | — | shadowsocks 必填:aes-128-gcm、aes-256-gcm、chacha20-poly1305(或 chacha20-ietf-poly1305)、xchacha20-poly1305(或 xchacha20-ietf-poly1305)、2022-blake3-aes-128-gcm、2022-blake3-aes-256-gcm 或 2022-blake3-chacha20-poly1305。 |
password | string | 视情况 | — | trojan、shadowsocks、hysteria2 和 anytls 必填。Shadowsocks 2022 方法下是 base64 密钥,连接多用户服务端时写成 iPSK:uPSK。Hysteria 2 服务端使用按用户区分的账户时,写成 user:pass。 |
user | string | 否 | — | socks 和 http:账户的用户名。 |
pass | string | 否 | — | socks 和 http:账户的密码。 |
server_name | string | 否 | — | hysteria2 和 anytls:TLS 服务器名,作为 SNI 发送并用于校验证书。默认取节点的 server。 |
allow_insecure | bool | 否 | false | hysteria2 和 anytls:接受任何证书。只用于测试。 |
obfs | table | 否 | — | hysteria2:Salamander 混淆,写作 { type = "salamander", password = "…" }。密码至少 4 字节,并且必须与服务端相同。 |
ports | string | 否 | — | hysteria2:端口跳跃,服务端应答的所有端口,例如 "443,20000-30000"。节点仍然需要 port。跳跃间隔默认 30 秒。 |
hop_interval | u64 | 否 | — | hysteria2:在一个端口上停留多少秒后跳跃,至少 5。需要同时设置 ports。 |
up | string | 否 | — | hysteria2:客户端发送的最高速率,写成数字加单位,例如 "50 mbps"。它成为出站的 bandwidth.up。 |
down | string | 否 | — | hysteria2:客户端接收的最高速率,会告诉服务端。它成为出站的 bandwidth.down。 |
private_key | string | 视情况 | — | wireguard 必填:你的私钥,与 wg-quick 文件中的相同。 |
peer_public_key | string | 视情况 | — | wireguard 必填:对端的公钥。 |
preshared_key | string | 否 | — | wireguard:预共享密钥,对端为你设置了时才填写。 |
address | array of IPs | 视情况 | — | wireguard 必填:你的隧道内地址,写成纯 IP,例如 ["10.0.0.2", "2001:db8:a::2"]。对端就是节点的 server 和 port。 |
mtu | integer | 否 | 1420 | wireguard:隧道的 MTU。 |
keepalive | u16 | 否 | — | wireguard:持续保活间隔,单位秒。 |
reserved | array of integers | 否 | — | wireguard:恰好三个字节,写入包头的保留字段,只在服务方要求时填写。 |
transform | table | 否 | — | sss:伺服端的變換鏈,從客戶端的視角寫成 { up = […], down = […] }:每個方向都是表示式陣列,記法與出站的同名鍵相同,依書寫順序執行。單一表示式也要寫成只有一項的陣列。不寫時兩條鏈都是恆等變換。變換鏈在節點轉換為出站時檢查。 |
udp_max_datagram | u16 | 否 | 65535 | sss:一条 UDP 记录承载的最大数据报,与服务端的设置相同。 |
有三类节点的写法与众不同:
- AnyTLS 只运行在 TCP 上的 TLS 之上,所以它的节点没有
stream。它的 TLS 键server_name和allow_insecure与 Hysteria 2 一样直接写在节点里,节点会变成一个network = "tls"的anytls出站。见 AnyTLS。 - 基于 REALITY 的 VLESS 是
stream为network = "reality"的vless节点,见 stream 表。这样的节点还可以设置flow = "xtls-rprx-vision"。这个 flow 只能运行在 REALITY 之上:用在其他 stream 上时节点会失败,报outbound <name>@v0: vless vision (xtls-rprx-vision) rides only over reality;在其他协议上使用 REALITY stream 则报outbound <name>@v0: reality is for vless only。 - sss 使用用户的
id、它的transform变换链和udp_max_datagram,可以使用 REALITY 以外的任何 stream。它的键见 sss。
[[proxy_server]]name = "tw-anytls"server = "proxy.example.com"port = 443protocol = "anytls"password = "replace-with-a-long-random-password"server_name = "proxy.example.com" # optional: defaults to server
[[proxy_server]]name = "fra-reality"server = "203.0.113.10"port = 443protocol = "vless"id = "11111111-2222-3333-4444-555555555555"flow = "xtls-rprx-vision"stream = { network = "reality", public_key = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", server_name = "www.example.com", short_id = "0123456789abcdef" }这里的每个值都是占位值。REALITY 的 public_key 是服务端的 X25519 公钥,用不带填充的 base64url 写成,共 43 个字符;server_name 是服务端所伪装的站点,而不是节点自己的 server。
节点不能包含取决于客户端本机或个人偏好的键:
| 节点里没有的键 | 节点改用 |
|---|---|
ca_file |
系统根证书;或设置 allow_insecure,不做校验 |
address_family |
文件有 [dns] 时由 [dns] connect_ipv6 推导,否则为 auto |
Hysteria 2 的 max_concurrent_streams |
默认值 102,400 |
Hysteria 2 的 congestion、quic、min_hop_interval、max_hop_interval 和 bandwidth.disable_loss_compensation |
默认值:Cubic、上游的 QUIC 默认值、固定的跳跃间隔、开启丢包补偿。节点的 up、down、ports 和 hop_interval 分别成为出站的 bandwidth.up、bandwidth.down、ports 和 hop_interval |
WireGuard 的 endpoint |
节点的 server 和 port,拼成 server:port;IPv6 的 server 可以直接写,也可以加方括号 |
AnyTLS 的 client、idle_session_check_interval、idle_session_timeout 和 min_idle_session |
默认值:client 为空,每 30 秒检查一次空闲会话,空闲超时 30 秒,不保留空闲会话 |
sss 的 flush_delay |
"0ms" |
stream 表
Section titled “stream 表”| 键 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
network | string (enum) | 是 | — | tcp、ws、grpc 或 reality。这里没有 tls 这种 network:只要写了 tls 表,就启用 TLS。reality 表示基于普通 TCP 上 REALITY 的 VLESS;它使用 public_key、server_name 和 short_id,不使用 tls 表。 |
path | string | 否 | "/" | ws:WebSocket 路径。 |
host | string | 否 | — | ws:Host 请求头。默认依次取 tls.server_name 和节点的 server。 |
service_name | string | 视情况 | — | grpc 必填:gRPC 服务名。 |
authority | string | 否 | — | grpc:HTTP/2 的 :authority。默认依次取 tls.server_name 和节点的 server。 |
tls | table | 否 | — | tcp、ws 和 grpc:启用 TLS,写成空表 tls = {} 也算。它的键是 server_name 和 allow_insecure。 |
public_key | string | 视情况 | — | reality 必填:服务端的 X25519 公钥,32 字节,用不带填充的 base64url 写成(43 个字符)。 |
server_name | string | 视情况 | — | reality 必填:客户端发送的 SNI,即服务端所伪装的站点名,而不是节点自己的 server。 |
short_id | string | 否 | — | reality:客户端出示的 shortId,最多 16 个十六进制数字。服务端接受空 shortId 时可以不写。 |
| 键 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
server_name | string | 否 | — | 作为 SNI 发送、并用来校验证书的名称。默认取节点的 server。 |
allow_insecure | bool | 否 | false | 接受任何证书。节点没有 ca_file:不写这个键时,证书按系统根证书校验。 |
stream 会变成出站的 [outbound.stream]:
节点的 stream |
出站的 stream |
|---|---|
不写,或 { network = "tcp" } |
普通 TCP |
{ network = "tcp", tls = {} } |
network = "tls" |
{ network = "ws", tls = {} } |
network = "ws"、security = "tls" |
{ network = "grpc", service_name = "…", tls = {} } |
network = "grpc"、security = "tls" |
{ network = "reality", public_key = "…", server_name = "…", short_id = "…" } |
security = "reality",并在 [outbound.stream.reality] 中写入 public_key、server_names = [server_name] 和 short_ids = [short_id] |
reality stream 不使用 tls 表:REALITY 自带握手。它的 short_id 可选,服务端接受空 shortId 时可以省略。各种 stream 在线路上的表现见传输层,REALITY 见 REALITY。
订阅文件格式有版本,即读取它的 etemenanki-subscribe crate 的版本,并随着新协议的加入而增长:
| 节点 | 需要的版本 |
|---|---|
AnyTLS、reality stream、VLESS 的 flow |
0.3 或更高 |
| sss | 1.1 或更高 |
etemenanki-app 3.0 讀取 1.1 版。檔案裡沒有版本標記,讀取方遇到它不認識的 protocol 或 network 時會拒絕整個檔案:subscribe: TOML parse error at line <n>, column <m>,附帶 unknown variant 和它認識的取值。下載訂閱檔案的客戶端會在 User-Agent 中以 etemenanki-subscribe/<version> 宣告自己讀取的版本,這樣提供方就可以略去該客戶端讀不了的節點。etemenanki-app 自己從不下載訂閱檔案,因此不送出 User-Agent。
格式能够描述、但 etemenanki-app 无法转换为出站的节点,是一个指出节点名的配置错误。只有当 etemenanki-app 用比它发布时更新的 etemenanki-subscribe 构建时,才会出现这种情况:subscribe: node "<name>": its protocol is not supported by this version,或把 its protocol 换成 its stream、its vmess security、its shadowsocks method。
DNS:[dns]
Section titled “DNS:[dns]”不建议任何 DNS 设置的服务商不写 [dns]。一旦写了 [dns] 表,五个键都必须设置。
| 键 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
pre_proxy | array of strings | 是 | — | 直接查询的服务器,在任何代理可用之前使用。它们负责解析节点的主机名,以及 through_proxy 服务器的主机名。每一项都要写成地址:这里写域名会在构建解析器时被拒绝。可以为空。 |
through_proxy | array of strings | 是 | — | 通过路由表查询的服务器:负责其余所有解析,包括 direct 的目标地址和应用程序自己发出的 DNS 查询。这里不接受 system。域名由 pre_proxy 解析。可以为空,此时由 pre_proxy 回答所有查询。 |
use_hosts | bool | 是 | — | 在询问任何服务器之前,先用系统 hosts 文件回答。 |
connect_ipv6 | string (enum) | 是 | — | 当节点的域名同时有 A 和 AAAA 记录时如何连接:required(只用 IPv6)、preferred(优先 IPv6)、tolerated(优先 IPv4)或 forbidden(只用 IPv4)。它会成为每个节点的 address_family(WireGuard 节点则是 endpoint_address_family)。 |
resolve_ipv6 | bool | 是 | — | 客户端后面的应用程序发出 DNS 查询时,是否返回 AAAA 结果。 |
pre_proxy 和 through_proxy 中的每个服务器都是一个字符串:
| 写法 | 服务器 | 默认端口 |
|---|---|---|
"system" |
主机的系统解析器。只能用在 pre_proxy 中。 |
— |
"udp://192.0.2.53:53" |
普通 DNS | 53 |
"tls://203.0.113.53:853#dns.example.com" |
DNS over TLS。# 后面的部分是校验证书时使用的名称;没有时使用主机部分。 |
853 |
"https://dns.example.com/dns-query" |
DNS over HTTPS。没有路径的 URL 使用 /dns-query。 |
443 |
这里的 IPv6 主机要加方括号,例如 udp://[2001:db8::53]:53。
订阅文件的 [dns] 把域名解析分成两部分:
| 解析器 | 服务器 | 负责解析 |
|---|---|---|
| 直连解析器 | pre_proxy,从本机直接查询 |
节点的服务器域名(包括 WireGuard 端点)、负载均衡器的探测,以及 through_proxy 服务器的域名 |
| 代理解析器 | through_proxy,经路由表访问 |
direct 和 WireGuard 隧道要连接的目标地址,以及应用程序的 DNS 查询。through_proxy 为空时,这些也由直连解析器负责。 |
发往 through_proxy 服务器的查询,是一条连到该服务器地址和端口的 TCP 连接,和其他连接一样由路由组决定去向:带有相应 cidr、geoip、port 或 network 条目的路由组会承载它。域名匹配条件永远匹配不到它,因为它的目标是一个地址。
设置 use_hosts = true 时,两个解析器在询问服务器之前都会先用系统 hosts 文件回答。
应用程序的 DNS
Section titled “应用程序的 DNS”订阅文件带有 [dns] 时,etemenanki-app 会亲自回答它后面那些应用程序的 DNS 查询。任何入站上、发往 53 端口的每个连接,无论 TCP 还是 UDP,也无论应用程序询问的是哪个 DNS 服务器,都由代理解析器回答,而不会被路由。只有设置 resolve_ipv6 = true 时才返回 AAAA 结果。
订阅文件没有 [dns] 时没有这项服务:发往 53 端口的查询会像其他连接一样被路由。
路由组:[[route_group]]
Section titled “路由组:[[route_group]]”| 键 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
name | string | 是 | — | 客户端显示的名字,也是 [subscribe.routes] 选择时使用的键。在文件内必须唯一(否则报 subscribe: route group "…" is defined twice),并且不能叫 default,这个名字留给 [subscribe.routes] 表示默认路由。 |
inherit | string or table | 否 | "default" | 路由组没有选择时,其流量的去向:"default"(与未匹配流量相同)、"direct"、"blackhole",或 { group = "<名字>" } 跟随另一个路由组。 |
matches | array of tables | 否 | [] | 路由组匹配的内容,写成只有一个键的表,例如 { geosite = ["netflix"] }。只要其中任意一项匹配,路由组就匹配这个流;一项中任意一个值匹配,这一项就匹配。空列表什么都不匹配,但其他路由组仍然可以继承它。 |
matches 的每一项都是只含下列某一个键的表。取值写法与应用自身的路由规则相同:
| 键 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
domain_full | array of strings | 否 | — | 完全相同的域名。 |
domain_suffix | array of strings | 否 | — | 该域名及其所有子域名。 |
domain_keyword | array of strings | 否 | — | 域名中包含的子串。 |
domain_regex | array of strings | 否 | — | 对转为小写的域名求值的正则表达式,不自动锚定。 |
cidr | array of strings | 否 | — | 目标 IP 网段,例如 "192.0.2.0/24"。目标地址是域名时永远不匹配。 |
port | array of strings | 否 | — | 目标端口 "443" 或端口范围 "8000-9000"。 |
network | array of strings | 否 | — | "tcp"、"udp" 或两者。 |
geosite | array of strings | 否 | — | geosite 列表,写 "code" 或 "code@attr",来自配置中 [route] geosite 指定的文件。 |
geoip | array of strings | 否 | — | GeoIP 列表,写 "code" 或 "!code",来自配置中 [route] geoip 指定的文件。 |
路由组没有 inbound_tag 和 source_cidr 匹配条件:它们取决于客户端自身的设置,服务商无从知晓。
inherit 决定你还没有为路由组选择节点时,它的流量去向:
inherit |
流量去向 |
|---|---|
不写,或 "default" |
默认路由 |
"direct" |
direct,不经代理 |
"blackhole" |
blackhole:连接被丢弃 |
{ group = "Proxy" } |
路由组 Proxy 的去向:它的选择,没有选择时再看它继承的目标 |
你的选择保存在配置文件的 [subscribe.routes] 中。订阅文件从不被修改,所以服务商替换它时不会丢掉你的选择。
- 手动切换:编辑
[subscribe.routes]并保存,重载会应用它。 - 由程序切换:使用 REST API。
PUT /v1/routes/<group>改写同一个键并重载,同时保留文件中的注释和格式。
值可以是某个节点、配置自身的某个出站或负载均衡器、direct 或 blackhole。default 为没有任何路由组匹配的流量选择路由。
如果一次切换只是让某个路由组改用另一个已经存在的出站,就只会重建路由表:已经打开的连接继续使用打开时的出站,这个路由组的新连接使用新的选择。透過 REST API 切換時加上 "close": true,還會關閉這次切換移走的開啟中連線,讓它們改由新的選擇重新連線。
更新订阅文件
Section titled “更新订阅文件”etemenanki-app 除了监视配置文件所在的目录,还会监视订阅文件所在的目录。任意一个文件发生变化,都会触发重载:
- 一次性替换文件:先把新文件写在旧文件旁边,再把它重命名覆盖旧文件,这样重载永远不会读到写了一半的文件。
- 重载只应用变化的部分。如果一个节点的设置没有变,而且文件的 DNS 设置也没有变,这个节点会保持运行原样。设置有变化的节点会重新构建,新连接使用新设置。
- 选择必须始终指向存在的对象。新文件改名或删除了
[subscribe.routes]所选的节点时,整次加载都会被拒绝,报[subscribe.routes] "<group>" = "<node>": no node, outbound or balancer has that name。请先更新选择再换文件,或者在下一次重载之前把两者都改好。 - 被拒绝的文件不会影响正在运行的配置,日志会说明原因。见热重载。
合并过程自身的错误都以 subscribe: 开头。在 --test 下它们出现在 configuration invalid: 之后,启动时出现在 failed to start: 之后,重载时出现在 reload: …; keeping the running config 这一行中。
| 错误 | 原因 |
|---|---|
[subscribe] needs a path naming the subscribe file |
[subscribe] 没有 path。 |
subscribe: TOML parse error at line <n>, column <m> |
订阅文件无法解析:语法错误、未知或缺少的键、节点中写了其他协议的键,或者 [dns] 没有写全五个键。 |
subscribe: node "<name>" is defined twice, or shares its name with a config outbound |
两个节点重名,或者某个节点使用了你的某个出站或负载均衡器的 tag。 |
subscribe: a route group may not be named "default": [subscribe.routes] uses that key for the default node |
某个路由组叫 default。 |
subscribe: route group "<name>" is defined twice |
两个路由组重名。 |
subscribe: [subscribe.routes] names "<key>", which is not a route group in <file> |
某个选择指定了文件中不存在的路由组,通常是服务商改了组名。 |
subscribe: [subscribe.routes] "<key>" = "<tag>": no node, outbound or balancer has that name |
某个选择指向的对象不存在:被改名或删除的节点,或者拼写错误。 |
subscribe: no node or outbound to send unmatched traffic to |
没有 default 选择、没有 [route] default,也没有任何出站和节点。 |
subscribe: "direct" is routed to, but the outbound tagged "direct" is "socks", not "freedom" |
路由用到了 direct,而你的某个其他协议的出站使用了这个 tag。blackhole 也做同样的检查;使用这两个 tag 之一的负载均衡器同样会被拒绝。 |
outbound <name>: … |
节点中的某个值有误,例如格式错误的 UUID 或密钥。这里的名字就是节点名。 |
subscribe: node "<name>": its protocol is not supported by this version |
该节点属于这个 etemenanki-app 无法转换的类型;见格式版本。 |
dns: server "<server>": … |
pre_proxy 或 through_proxy 中的某个字符串无法解析。 |
building dns failed: dns: the system resolver cannot be reached through a proxy |
through_proxy 中写了 "system"。 |
building dns failed: dns: server "<name>" is a name, and nothing resolves it; write its address |
pre_proxy 中的某个服务器写成了域名。 |