使用 WARP 绕过 OpenAi 对 IP 的封锁

发生了什么

行为:chat.openai.com 无法正常访问,返回 1020

原因:openai 封了不少 ip,包括一些廉价的云服务提供商。通过这些 ip 访问 chatgpt 就会遭到拒绝,返回 1020

怎么办

使用 Cloudflare 提供的 WARP 服务 >1.1.1.1 with WARP replaces the connection between your device and the Internet with a modern, optimized, protocol >With the push of a button, users could connect their mobile device to the entire Internet using a WireGuard tunnel through a Cloudflare data center near to them. Traffic to sites behind Cloudflare became even faster and a user’s experience with the rest of the Internet became more secure and private.

简而言之,原先 host -> openai 的流量变成了 host ---wireguard tunnel---> cloudflare DC -> openai,此时 openai 看到的 ip 不再是 host 的 ip,而是某个 Cloudflare DC Gateway 的地址,跳出 openai 的 ip 黑名单。

ref:

https://1.1.1.1/

https://blog.cloudflare.com/warp-for-desktop/

怎么做

在 host 上安装 WARP

官网下载 WARP 安装包并安装

1
2
wget <download-link>
sudo dpkg -i <WARP-file.deb>

ref:

https://developers.cloudflare.com/warp-client/get-started/linux/

配置 WARP

注册客户端

1
warp-cli register

配置代理模式!!!直接 connect 会导致 ssh 断掉连不上

1
warp-cli set-mode proxy

连接 WARP

1
warp-cli connect

设置保持连接

1
warp-cli enable-always-on

现在 WARP 应该在默认的 40000 端口启动了 socks 代理,可以开始正常使用

查看当前 WARP 配置

1
warp-cli settings

查看当前 WARP 状态

1
warp-cli warp-stats

更多命令

1
warp-cli --help

ref:

https://www.4spaces.org/3750.html

配置 V2RAY

我们尽需要将访问 openai 的流量通过 WARP,因此需要调整 V2RAY 的出站流量配置。

/usr/local/etc/v2ray/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
    "outbounds":[
...
{
"tag": "warp",
"protocol": "socks",
"settings": {
"servers": [
{
"address": "127.0.0.1",
"port": 40000
}
]
}
}
],
"routing":{
"domainStrategy":"AsIs",
"rules":[
...
{
"type": "field",
"domain": [
"domain:openai.com",
"domain:ai.com",
"domain:challenges.cloudflare.com"
],
"outboundTag": "warp"
}
]
},
...

ref:

https://www.v2ray.com/en/configuration/routing.html#ruleobject

配置本地代理 Clash

让访问 openai 的流量单独走配置好的这台 host,这样就不用开全局代理了。在 parser 中进行配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
parsers: # array

- url:
yaml:
prepend-rules:
...
- DOMAIN-SUFFIX,openai.com,chatGPT
- DOMAIN-SUFFIX,ai.com,chatGPT
append-proxies:
- name: "chatGPT-Proxy"
type:
server:
port:
prepend-proxy-groups:
- name: chatGPT
type: select
proxies: ["chatGPT-Proxy", "DIRECT"]

配置浏览器

浏览器应关闭 QUIC 功能,防止未代理的 UDP 流量直达 openai

在 chrome 的地址栏中输入:chrome://flags/#enable-quic,然后关闭该功能

ref: https://github.com/wgetnz/chatgpt-openclash

大功告成

现在可以从浏览器中直接访问 chat.openai.com