跳转到内容

入门指南

Sail 是面向客户端、服务端和中继的可复用 Rust 代理核心。本指南会构建命令行程序,启动一个本地 SOCKS5 监听,并通过直连出站发送流量。

flowchart LR
    A["应用<br/><small>浏览器或客户端</small>"] --> B["SOCKS5<br/><small>127.0.0.1:1080</small>"]
    B --> C["Sail 路由器"]
    C --> D["direct 出站"]

    classDef client fill:#eaf2ff,stroke:#075cff,color:#082b68,stroke-width:2px
    classDef proxy fill:#13223c,stroke:#4f8cff,color:#ffffff,stroke-width:2px
    classDef core fill:#075cff,stroke:#85aeff,color:#ffffff,stroke-width:3px
    classDef direct fill:#fff2ee,stroke:#ff6759,color:#5a1a14,stroke-width:2px
    class A client
    class B proxy
    class C core
    class D direct
    linkStyle 0,1 stroke:#075cff,stroke-width:3px
    linkStyle 2 stroke:#ff6759,stroke-width:3px

你需要 Rust、Cargo、CMake、C/C++ 编译器和 libclang。BoringSSL 会随项目从源码构建。目前还没有预编译的发布版。平台相关说明见安装。

终端窗口
cargo build -p sail-cli --release
./target/release/sail -V

生成的可执行文件位于 target/release/sail。

将以下内容保存为 config.json:

{
"log": { "level": "info", "format": "compact" },
"inbounds": [
{
"type": "socks",
"tag": "local-socks",
"listen": "127.0.0.1",
"listen_port": 1080
}
],
"outbounds": [{ "type": "direct", "tag": "direct" }],
"route": { "final": "direct" }
}

入站接收 SOCKS5 TCP 和 UDP 流量;未命中规则的连接都会交给 direct 出站。

这是 Sail 的原生格式 sing-box JSON。Sail 也能直接读取 Clash/Mihomo YAML(.yaml、.yml)或 Surge 配置(.conf),格式由扩展名决定。config.json 也是默认路径,因此 -c config.json 可以省略。

终端窗口
./target/release/sail -c config.json -T

文件能解析,且所有入站、出站、DNS 服务器和规则都能构建时,Sail 输出 ok 后退出。未知字段、缺失的出站标签和无效规则会在启动前被发现。

终端窗口
./target/release/sail -c config.json

在另一个终端中测试:

终端窗口
curl --socks5-hostname 127.0.0.1:1080 https://example.com

--socks5-hostname 会把域名交给 Sail 解析,使域名路由规则拥有完整信息。配置调试时可加 --auto-reload 自动重载。

  • 配置模型:顶层结构、默认值和兼容范围。
  • 路由规则:域名、IP、端口、入站和进程匹配。
  • 协议与兼容性:入站、出站、传输层及主流配置生态。
  • MPTP:搭建客户端/服务端多路径隧道。
  • CLI 参考:验证、连通性测试与运行时配置。