北屋教程网

专注编程知识分享,从入门到精通的编程学习平台

什么是 sing-box?带你避坑sing-box

  • 一个“一机多协议”的代理服务端/客户端工具,支持 Shadowsocks、VLESS、Trojan、SOCKS、HTTP 等多种协议既能当服务端,也能当客户端,还能做转发、分流、端口跳跃、kcp、mux 等高级玩法。
  • 2. 安装 sing-box

    (1)官方脚本一键

    bash <(curl -sL https://cdn.jsdelivr.net/gh/SagerNet/sing-box@master/install.sh)

    安装后可在 /usr/local/bin/sing-box 找到二进制文件。

    (2)手动下载

    1. 去 GitHub Releases 拉取对应平台的 sing-box-linux-amd64.tar.gz
    2. 解压并移动到 /usr/local/bin/

    tar xzf sing-box-*-linux-amd64.tar.gz

    mv sing-box /usr/local/bin/

    chmod +x /usr/local/bin/sing-box

    3. 最小可用配置示例

    服务端 server.json

    {

    "inbounds": [

    {

    "type": "trojan", // Trojan 协议

    "tag": "trojan-in",

    "listen": "0.0.0.0",

    "port": 443,

    "sniff": { "enable": true },

    "users": [

    { "name": "user1", "password": "强密码123" }

    ],

    "tls": { "enabled": true, "certificate": "/path/fullchain.pem", "key": "/path/privkey.pem" }

    }

    ],

    "outbounds": [

    { "type": "direct", "tag": "direct" }

    ]

    }

    客户端 client.json

    {

    "inbounds": [

    {

    "type": "socks", // 本地启动 SOCKS5 代理

    "tag": "local-socks",

    "listen": "127.0.0.1",

    "port": 1080

    }

    ],

    "outbounds": [

    {

    "type": "trojan", // 对应服务器的 Trojan 出口

    "tag": "trojan-out",

    "servers": [

    {

    "address": "your.server.com",

    "port": 443,

    "password": "强密码123",

    "tls": { "enabled": true, "servername": "your.server.com" }

    }

    ]

    },

    { "type": "direct", "tag": "direct" }

    ],

    "routing": {

    "rules": [

    { "type": "field", "inbound": ["local-socks"], "outbound": "trojan-out" }

    ]

    }

    }

    4. 启动与验证

    1.启动服务端:

    sing-box run -c /etc/sing-box/server.json

    2.启动客户端:

    sing-box run -c ~/client.json

    3.验证代理:

    curl --socks5 127.0.0.1:1080 https://api.ip.sb/ip

    能正常返回你服务器的 IP 就成功了。

    以上就是“从 0 到 1” 玩转 sing-box 的核心要点。你可以先照例子跑起来,再根据需要把配置拆分、合并、开更多协议、加路由、加端口跳跃……不断试就熟了。

    要更深入的某块(如 WS+TLS 配置、分流规则写法、mux 性能调优)再细聊!

    控制面板
    您好,欢迎到访网站!
      查看权限
    网站分类
    最新留言