sing-box + VLESS gRPC Reality + WARP 完整教程
sing-box + VLESS gRPC Reality + WARP 完整教程
前言
考虑到平时用机房IP使用AI工具如Chatgpt、Claude等,容易降智。解决方案最好的无疑是买一个住宅IP。但是考虑到价格相对昂贵,基于能省则省原则,本文考虑到第二种折中方案,即vps节点出口套用Warp。本文解决的一个经典场景即是,vps开了双栈,ipv4走warp出口,ipv6走直连。
目标效果:
| 入口 | 出口 |
|---|---|
| IPv4 节点 | 走 Cloudflare WARP |
| IPv6 节点 | 直连 VPS |
适用环境:
- VPS:DMIT / 其他海外 VPS
- 系统:Debian / Ubuntu
- sing-box:1.12.17
- 客户端:Shadowrocket / Clash / sing-box
- 协议:VLESS + gRPC + Reality
一、准备工作
你需要:
- 一台海外 VPS(支持 IPv4 + IPv6)
- 一个域名
- 两个子域名:
v4.example.com→ 只绑定 A 记录v6.example.com→ 只绑定 AAAA 记录
DNS 示例:
| 域名 | 记录 | 指向 |
|---|---|---|
| v4.example.com | A | VPS IPv4 |
| v6.example.com | AAAA | VPS IPv6 |
二、安装 sing-box
2.1 下载
1
2
apt update && apt upgrade -y
bash <(curl -fsSL https://sing-box.app/install.sh)
2.2 查看版本
1
sing-box version
三、安装 Cloudflare WARP(wgcf)
WARP 本质是一个 WireGuard 隧道,我们用 wgcf 生成配置。
3.1 下载 wgcf
1
2
3
wget https://github.com/ViRb3/wgcf/releases/download/wgcf_2.2.30_linux_amd64
chmod +x wgcf_2.2.30_linux_amd64
mv wgcf_2.2.30_linux_amd64 /usr/local/bin/wgcf
3.2 注册并生成配置
1
2
wgcf register
wgcf generate
生成文件:
1
wgcf-profile.conf
四、读取 WARP 参数
1
cat wgcf-profile.conf
你会看到类似:
1
2
3
4
5
6
7
8
9
[Interface]
PrivateKey = AAAABBBBCCCC
Address = 172.16.0.2/32, 2606:4700:110::/128
[Peer]
PublicKey = DDDDEEEEFFFF
Endpoint = 162.159.192.1:2408
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
记住这些:
| 项目 | 用途 |
|---|---|
| PrivateKey | WARP 私钥 |
| Address | 本机隧道 IP |
| PublicKey | Cloudflare 公钥 |
| Endpoint | WARP 服务器 |
| AllowedIPs | 全流量 |
| Keepalive | 保活 |
五、生成 Reality 密钥、UUID、ShortID
生成 Reality 密钥
1
sing-box generate reality-keypair
得到:
1
2
PrivateKey: XXXXX
PublicKey: YYYYY
生成UUID
1
sing-box generate uuid
生成ShortID
1
sing-box generate rand --hex 8
六、完整 sing-box 配置
编辑配置文件:
1
nano /etc/sing-box/config.json
粘贴以下内容:
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
{
"log": {
"level": "info",
"timestamp": true
},
"endpoints": [
{
"type": "wireguard",
"tag": "warp",
// 建议 system=false:让 sing-box 自己托管,不依赖 wg-quick
"system": false,
// wgcf 生成的 Address(可以同时填 v4/v6)
"address": [
"172.16.0.2/32",
"2606:4700:110:xxxx:xxxx:xxxx:xxxx:xxxx/128"
],
// wgcf 生成的 PrivateKey
"private_key": "YOUR_WARP_PRIVATE_KEY_BASE64",
// 可选:WARP 常见 MTU 1280
"mtu": 1280,
// Peer(Cloudflare)
"peers": [
{
// Endpoint:wgcf-profile.conf 里的 Endpoint
// 可以写域名
"address": "engage.cloudflareclient.com",
"port": 2408,
// wgcf-profile.conf 里的 PublicKey
"public_key": "YOUR_WARP_PEER_PUBLIC_KEY_BASE64",
// 通常 AllowedIPs 全局路由(让走 WARP 的流量全进隧道)
"allowed_ips": [
"0.0.0.0/0",
"::/0"
],
// 如果你拿到了 reserved(WARP 常用)
"reserved": [0, 0, 0],
"persistent_keepalive_interval": 25
}
]
}
],
"inbounds": [
{
"type": "vless",
"tag": "vless-in-4",
"listen": "0.0.0.0",
"listen_port": 443,
"users": [
{
"uuid": "YOUR_UUID",
"flow": ""
}
],
"transport": {
"type": "grpc",
"service_name": "grpc"
},
"tls": {
"enabled": true,
"server_name": "www.microsoft.com",
"reality": {
"enabled": true,
"handshake": {
"server": "www.microsoft.com",
"server_port": 443
},
"private_key": "YOUR_REALITY_PRIVATE_KEY",
"short_id": ["YOUR_SHORT_ID"]
}
}
},
{
"type": "vless",
"tag": "vless-in-6",
"listen": "::",
"listen_port": 8443,
"users": [
{
"uuid": "YOUR_UUID",
"flow": ""
}
],
"transport": {
"type": "grpc",
"service_name": "grpc"
},
"tls": {
"enabled": true,
"server_name": "www.microsoft.com",
"reality": {
"enabled": true,
"handshake": {
"server": "www.microsoft.com",
"server_port": 443
},
"private_key": "YOUR_REALITY_PRIVATE_KEY",
"short_id": ["YOUR_SHORT_ID"]
}
}
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct"
}
],
"route": {
// 默认不写也行;建议显式写 direct,避免误会
"final": "direct",
"rules": [
{
"inbound": ["vless-in-4"],
"action": "route",
"outbound": "warp"
},
{
"inbound": ["vless-in-6"],
"action": "route",
"outbound": "direct"
}
]
}
}
替换:
YOUR_WARP_PRIVATE_KEYYOUR_WARP_PEER_PUBLIC_KEYYOUR_REALITY_PRIVATE_KEYYOUR_UUID
七、启动 sing-box
1
2
3
systemctl enable sing-box
systemctl restart sing-box
journalctl -u sing-box -f
看到:
1
wireguard endpoint warp connected
说明成功。
八、客户端配置
打开 Shadowrocket → 右上角 + → Type: VLESS
填写以下内容:
| 项目 | 值 |
|---|---|
| Address | v4.example.com (IPv6节点填写 v6.example.com ) |
| Port | 443 (IPv6节点填写 8443) |
| UUID | 上面生成的 UUID |
| transport | grpc |
| Host | v4.example.com (IPv6节点填写 v6.example.com ) |
| Service Name | grpc |
| TLS | 开启 |
| SNI | www.microsoft.com |
| Public Key | Reality 的 PublicKey |
| Short ID | 你的 Short ID |
| Fingerprint | chrome 或默认(Shadowrocket 默认为 Safari) |
九、验证是否走 WARP
IPv4 连接后,访问:
1
https://www.cloudflare.com/cdn-cgi/trace
应显示 Cloudflare IP。而IPv6 连接后,应显示 DMIT 原生 IP。
十、最终结构图
1
2
IPv4 → VLESS → WARP → Cloudflare → Internet
IPv6 → VLESS → Direct → Internet
十一、总结
- sing-box 原生支持 WARP
- IPv4 + WARP 更稳定
- IPv6 直连更快
- 双入口分流是最优解
- 适合 ChatGPT / Google / Apple / OpenAI API
This post is licensed under CC BY 4.0 by the author.