前言
随着SagerNet作者持续“发烧”
升级展示多用户配置设置和sing-box全局配置代码示例,
及各项疑难解答,算是sing-box进阶教程,如果你是新手,请先看“Sing-box新手教程”
sing-box配置原理及多用户共有配置示例
sing-box配置通信流程
通信按照以下两步骤执行:
1.先获取TLS握手:
{浏览器} <–(socks/tun)–> {Sing-box 客户端 inbound <-> Sing-box 客户端 outbound} <–(shadowtls)–> {Sing-box 服务器 inbound <–(验证用户密码)–> Sing-box 服务器} <–(handshake)–> {www.bing.com}
2.获取握手后,识别流量走代理:
{浏览器} <–(socks/tun)–> {Sing-box 客户端 inbound <-> Sing-box 客户端 outbound} <–(shadowsocks)–> {Sing-box 服务器 inbound <–(验证ss密码)–> Sing-box 服务器} <–(Freedom)–> {目标网站}
1.先获取TLS握手:
{浏览器} <–(socks/tun)–> {Sing-box 客户端 inbound <-> Sing-box 客户端 outbound} <–(shadowtls)–> {Sing-box 服务器 inbound <–(验证用户密码)–> Sing-box 服务器} <–(handshake)–> {www.bing.com}
2.获取握手后,识别流量走代理:
{浏览器} <–(socks/tun)–> {Sing-box 客户端 inbound <-> Sing-box 客户端 outbound} <–(shadowsocks)–> {Sing-box 服务器 inbound <–(验证ss密码)–> Sing-box 服务器} <–(Freedom)–> {目标网站}
多用户共有配置示例
本文默认你有vps,并且已搭建升级好sing-box服务端,如果首次搭建sing-box服务端,请复制以下一键脚本安装。
1 |
wget -N --no-check-certificate https://raw.githubusercontent.com/lanhebe/singbox-shadowtls/main/mps_Sing-box.sh && chmod +x mps_Sing-box.sh && bash mps_Sing-box.sh |
以下用的是sing-box-1.2-beta10做的两人共用配置测试,如需增设用户数量,详见users突亮代码行依次增加。
如复制以下代码实验,请使用sing-box-1.2-beta10以上的高版本,否则启动会报错,无法运行。
用户sekai,hebe共用服务端配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
{ "inbounds": [ { "type": "shadowtls", "listen": "::", "listen_port": 443, "version": 3, "users": [ { "name": "sekai", "password": "ypGGDagcyFKCf5TYJyH0fw==" }, { "name": "hebe", "password": "1pGGDagcyFKCa8TYYyH0fw==" } ], "handshake": { "server": "www.ebay.com", "server_port": 443 }, "detour": "shadowsocks-in" }, { "type": "shadowsocks", "tag": "shadowsocks-in", "listen": "127.0.0.1", "network": "tcp", "method": "2022-blake3-aes-128-gcm", "password": "PAJdSIxI6tZdR0UqMtBaLQ==" } ] } |
sekai用户的http-sock客户端配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
{ "inbounds": [ { "type": "mixed", "listen_port": 1080, "sniff": true, "set_system_proxy": true } ], "outbounds": [ { "type": "shadowsocks", "method": "2022-blake3-aes-128-gcm", "password": "PAJdSIxI6tZdR0UqMtBaLQ==", "detour": "shadowtls-out", "multiplex": { "enabled": true, "max_connections": 4, "min_streams": 4 } }, { "type": "shadowtls", "tag": "shadowtls-out", "server": "更改成自己IP", "server_port": 443, "version": 3, "password": "ypGGDagcyFKCf5TYJyH0fw==", "tls": { "enabled": true, "server_name": "www.ebay.com" } }, { "type": "direct", "tag": "direct" }, { "type": "block", "tag": "block" } ], "route": { "rules": [ { "geosite": "cn", "geoip": "cn", "outbound": "direct" }, { "geosite": "category-ads-all", "outbound": "block" } ] } } |
sekai用户的http-sock客户端全局配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
{ "inbounds": [ { "type": "mixed", "listen_port": 1080, "sniff": true, "set_system_proxy": true } ], "outbounds": [ { "type": "shadowsocks", "method": "2022-blake3-aes-128-gcm", "password": "PAJdSIxI6tZdR0UqMtBaLQ==", "detour": "shadowtls-out", "multiplex": { "enabled": true, "max_connections": 4, "min_streams": 4 } }, { "type": "shadowtls", "tag": "shadowtls-out", "server": "更改成自己IP", "server_port": 443, "version": 3, "password": "ypGGDagcyFKCf5TYJyH0fw==", "tls": { "enabled": true, "server_name": "www.ebay.com" } }, { "type": "direct", "tag": "direct" }, { "type": "block", "tag": "block" } ], "route": { "rules": [ { "geosite": "category-ads-all", "outbound": "block" } ] } } |
sekai用户的Tun客户端配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
{ "dns": { "servers": [ { "tag": "google", "address": "tls://8.8.8.8" }, { "tag": "local", "address": "223.5.5.5", "detour": "direct" } ], "rules": [ { "geosite": "cn", "server": "local" } ], "strategy": "ipv4_only" }, "inbounds": [ { "type": "tun", "inet4_address": "172.19.0.1/30", "auto_route": true, "sniff": true } ], "outbounds": [ { "type": "shadowsocks", "method": "2022-blake3-aes-128-gcm", "password": "PAJdSIxI6tZdR0UqMtBaLQ==", "detour": "shadowtls-out", "multiplex": { "enabled": true, "max_connections": 4, "min_streams": 4 } }, { "type": "shadowtls", "tag": "shadowtls-out", "server": "更改成自己IP", "server_port": 443, "password": "ypGGDagcyFKCf5TYJyH0fw==", "version": 3, "tls": { "enabled": true, "server_name": "www.ebay.com" } }, { "type": "direct", "tag": "direct" }, { "type": "block", "tag": "block" }, { "type": "dns", "tag": "dns-out" } ], "route": { "rules": [ { "protocol": "dns", "outbound": "dns-out" }, { "geosite": "cn", "geoip": "cn", "outbound": "direct" }, { "geosite": "category-ads-all", "outbound": "block" } ], "auto_detect_interface": true } } |
hebe用户的http-sock客户端配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
{ "inbounds": [ { "type": "mixed", "listen_port": 1080, "sniff": true, "set_system_proxy": true } ], "outbounds": [ { "type": "shadowsocks", "method": "2022-blake3-aes-128-gcm", "password": "PAJdSIxI6tZdR0UqMtBaLQ==", "detour": "shadowtls-out", "multiplex": { "enabled": true, "max_connections": 4, "min_streams": 4 } }, { "type": "shadowtls", "tag": "shadowtls-out", "server": "更改成自己IP", "server_port": 443, "version": 3, "password": "1pGGDagcyFKCa8TYYyH0fw==", "tls": { "enabled": true, "server_name": "www.ebay.com" } }, { "type": "direct", "tag": "direct" }, { "type": "block", "tag": "block" } ], "route": { "rules": [ { "geosite": "cn", "geoip": "cn", "outbound": "direct" }, { "geosite": "category-ads-all", "outbound": "block" } ] } } |
hebe用户的Tun客户端配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
{ "dns": { "servers": [ { "tag": "google", "address": "tls://8.8.8.8" }, { "tag": "local", "address": "223.5.5.5", "detour": "direct" } ], "rules": [ { "geosite": "cn", "server": "local" } ], "strategy": "ipv4_only" }, "inbounds": [ { "type": "tun", "inet4_address": "172.19.0.1/30", "auto_route": true, "sniff": true } ], "outbounds": [ { "type": "shadowsocks", "method": "2022-blake3-aes-128-gcm", "password": "PAJdSIxI6tZdR0UqMtBaLQ==", "detour": "shadowtls-out", "multiplex": { "enabled": true, "max_connections": 4, "min_streams": 4 } }, { "type": "shadowtls", "tag": "shadowtls-out", "server": "更改成自己IP", "server_port": 443, "password": "1pGGDagcyFKCa8TYYyH0fw==", "version": 3, "tls": { "enabled": true, "server_name": "www.ebay.com" } }, { "type": "direct", "tag": "direct" }, { "type": "block", "tag": "block" }, { "type": "dns", "tag": "dns-out" } ], "route": { "rules": [ { "protocol": "dns", "outbound": "dns-out" }, { "geosite": "cn", "geoip": "cn", "outbound": "direct" }, { "geosite": "category-ads-all", "outbound": "block" } ], "auto_detect_interface": true } } |
hebe用户的Tun客户端全局配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
{ "dns": { "servers": [ { "tag": "google", "address": "tls://8.8.8.8" }, { "tag": "local", "address": "223.5.5.5", "detour": "direct" } ], "rules": [ { "geosite": "cn", "server": "local" } ], "strategy": "ipv4_only" }, "inbounds": [ { "type": "tun", "inet4_address": "172.19.0.1/30", "auto_route": true, "sniff": true } ], "outbounds": [ { "type": "shadowsocks", "method": "2022-blake3-aes-128-gcm", "password": "PAJdSIxI6tZdR0UqMtBaLQ==", "detour": "shadowtls-out", "multiplex": { "enabled": true, "max_connections": 4, "min_streams": 4 } }, { "type": "shadowtls", "tag": "shadowtls-out", "server": "更改成自己IP", "server_port": 443, "password": "1pGGDagcyFKCa8TYYyH0fw==", "version": 3, "tls": { "enabled": true, "server_name": "www.ebay.com" } }, { "type": "direct", "tag": "direct" }, { "type": "block", "tag": "block" }, { "type": "dns", "tag": "dns-out" } ], "route": { "rules": [ { "protocol": "dns", "outbound": "dns-out" }, { "geosite": "category-ads-all", "outbound": "block" } ], "auto_detect_interface": true } } |
Sing-box图形客户端使用:
Sing-box图形客户端使用教程详见此处,此处略。
常见错误解决办法:
-
1bad timestamp: received
原因:客户端系统时间不正确;解决办法:纠正客户端系统时间为正确北京时间即可。 -
1client hello verify failed: hmac mismatch
原因:password错误或没有设置;解决办法:检查两端密码是否设置一致,或一方增加密码设置。 - 客户端启动sing-box,自动退出。
原因:json配置与程序版本冲突;/json配置有误;解决办法:两端更新到最新版本再执行。
原因:设置的TLS握手服务器拒绝请求或设置域名不存在。解决办法:更改两端tls 有效server_name- CS两端增加version:3配置参数,无法成功启动。
原因:程序版本与配置不兼容。解决办法: v2.v3必须使用大于等于1.2-beta10版本以上Sing-box程序
如果你对sing-box搭建视频感兴趣,欢迎点击链接跳转观看!
如果本文对你非常有用!不妨点赞并转发,感谢支持!
最新评论
这个怎么开启啊,好像开启的命令不对
请问博主,代理列表中线路前的国旗图标是如何实现的呢?
AQWorlds
感谢分享,如果厌倦搭建的繁琐步骤,不妨来 devpn.store 看看,也许正是您需要的。
谢谢分享,devpn.store 有提供trojan和vpn服务,7天免费试用。
这个价格是大家共用,不是独用!所以正常。。。。
提供高速稳定科学上网节点,月付16,年付150,可试用 联系方式 telegram: @hellowordnew QQ: 3604500082
ios 有 sing-box testflight app