探索在Sing Box中使用Warp

探索在Sing Box中使用Warp

  1. 大全前端 🛫
  2. 2026-03-21 14:20
  3. 4 min read

安装sing-box脚本

参考安装sing-box脚本教程一键安装。

bash <(wget -qO- -o- https://github.com/233boy/sing-box/raw/main/install.sh)

安装一些测试协议

sb add reality
sb add hy
# ...

安装Warp

1.安装官方Cloudflare Warp客户端

# 1. 导入官方 GPG 密钥
curl -fsSL https://pkg.cloudflareclient.com/pubkey.gpg | sudo gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg
 
# 2. 添加官方软件源 (Ubuntu 22.04 对应代号是 jammy)
echo "deb [signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ jammy main" | sudo tee /etc/apt/sources.list.d/cloudflare-client.list
 
# 3. 更新并安装
sudo apt update && sudo apt install cloudflare-warp -y

2.配置Warp为Socks5代理模式

安装完成后,我们需要把它设置成“只在本地提供代理接口”,而不是接管整个服务器的流量(否则你的 SSH 会断开):

# 1. 注册设备
warp-cli registration new
 
# 1. 接受注册协议
# Accept Terms of Service and Privacy Policy? [y/N] y
# Success
 
# 2. 设置为代理模式 (默认就是 Socks5)
warp-cli mode proxy
 
# 3. 设置代理端口为 40000 (方便后面 Sing-box 分流)
warp-cli proxy port 40000
 
# 4. 开启 1.1.1.1 过滤模式(替代你刚才报错的那行)
# 这一步是为了确保 DNS 分流更干净
# 选择 off 性能最快,因为我们只需要 IP 出口,不需要它帮我们过滤内容
warp-cli dns families off
 
# 5. 连接并设置自动连接
warp-cli connect
 

3.最终确认三部曲

在修改 Sing-box 配置之前,请务必跑完这三步确认 WARP 环境已就绪:

查看状态:执行 warp-cli status,应显示 Status update: Connected

测试出口:执行 curl -x socks5h://127.0.0.1:40000 https://www.cloudflare.com/cdn-cgi/trace

成功标准:返回内容中包含 warp=on,说明 WARP 已经成功在 40000 端口守候了。

确认 IP 归属:执行 curl -x socks5h://127.0.0.1:40000 ifconfig.me

成功标准:返回的 IP 应该与你的 VPS 原生 IP (142.171.215.147) 不同。

4.修改Sing-box配置文件实现AI分流

现在,我们要告诉Sing-box:“遇到 ChatGPT 流量,请发给本地 40000 端口”。

1、打开配置文件:

nano /etc/sing-box/config.conf

2、找到 outbounds 部分(通常在文件的中间),添加 warp 节点: 注意:找到最后一个花括号,加个逗号再粘贴下面这段。

{
  "type": "socks",
  "tag": "warp-out",
  "server": "127.0.0.1",
  "server_port": 40000
}

3、找到 route 下的 rules 部分(通常在文件末尾),添加域名分流: 注意:要把这段放在 rules 数组的最前面,确保优先匹配。

{
  "domain": [
    "openai.com",
    "chatgpt.com",
    "oaistatic.com",
    "oaiusercontent.com",
    "anthropic.com",
    "claude.ai",
    "google.com",
    "googleapis.com",
    "gstatic.com",
    "gemini.google.com",
    "bing.com",
    "grok.com"
  ],
  "outbound": "warp-out"
}

4、重启并生效:

sb restart

5、测试修复后完整配置文件

{
  "log": {
    "output": "/var/log/sing-box/access.log",
    "level": "info",
    "timestamp": true
  },
  "dns": {
    "servers": [
      {
        "tag": "cloudflare-dns",
        "address": "https://1.1.1.1/dns-query"
      }
    ],
    "strategy": "prefer_ipv4"
  },
  "outbounds": [
    {
      "type": "direct",
      "tag": "direct"
    },
    {
      "type": "socks",
      "tag": "warp-out",
      "server": "127.0.0.1",
      "server_port": 40000
    }
  ],
  "route": {
    "rules": [
      {
        "port": [443], 
        "domain_suffix": [
          "openai.com",
          "chatgpt.com",
          "oaistatic.com",
          "oaiusercontent.com",
          "anthropic.com",
          "claude.ai",
          "gemini.google.com",
          "google.com",
          "googleapis.com",
          "gstatic.com",
          "bing.com",
          "grok.com"
        ],
        "outbound": "warp-out"
      },
      {
        "ip_cidr": [
          "104.16.0.0/12",
          "172.64.0.0/13",
          "162.158.0.0/16"
        ],
        "outbound": "warp-out"
      },
      {
        "outbound": "direct"
      }
    ]
  }
}

写在最后

为什么尝试这个方案?

官方保障:warp-cli 是 Cloudflare 维护的,比任何个人脚本都稳。

内存友好:在2GB小内存机子跑这个官方客户端绰绰有余。

联通优化:开启了BBR之后本地到VPS很快;而VPSAI网站通过WARP走Cloudflare的内部骨干网,速度极快。

此方案整理自AI教学优化VPS访问AI的响应。

Warp