问题

  • 机房 RackNerd 洛杉矶 dc02
  • 之前一直用网页版的 ChatGPT,今天用了下移动端发现不可用
  • 看来是整个 IP 段都被 OpenAI 拉黑了

思路

找一台能解锁 ChatGPT 的 VPS,利用 Xray 的出站规则和路由规则进行前置代理和分流

方案

Cloudflare 的 WARP 可以免费用,参考官方教程

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
Cloudflare WARP packages
Cloudflare's client-side software can be installed on Linux with package managers APT or YUM by following these instructions. However, keep in mind that not all packages may support all operating systems or architectures and that you can check a specific package's page (linked from the homepage) to see what's available. We generally support modern versions of the following distributions:

Ubuntu
The supported releases are:
Jammy (22.04)
Focal (20.04)
Bionic (18.04)
Xenial (16.04)
# Add cloudflare gpg key
curl -fsSL https://pkg.cloudflareclient.com/pubkey.gpg | sudo gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg


# Add this repo to your apt repositories
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflare-client.list


# Install
sudo apt-get update && sudo apt-get install cloudflare-warp

Debian
The supported releases are:
Bookworm (12)
Bullseye (11)
Buster (10)
Stretch (9)
# Add cloudflare gpg key
curl -fsSL https://pkg.cloudflareclient.com/pubkey.gpg | sudo gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg


# Add this repo to your apt repositories
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflare-client.list


# Install
sudo apt-get update && sudo apt-get install cloudflare-warp

Red Hat Enterprise Linux & CentOS
Install the repository with yum (replace <VERSION> with the release version number):
The supported versions are:
8
# Add cloudflare-warp.repo to /etc/yum.repos.d/
curl -fsSl https://pkg.cloudflareclient.com/cloudflare-warp-ascii.repo | sudo tee /etc/yum.repos.d/cloudflare-warp.repo

# Update repo
sudo yum update

# Install
sudo yum install cloudflare-warp

WARP 的 IP 会与落地机处于同一地区

操练

安装 WARP

本文以 Debian11 系统为例

  1. 安装存储库的 GPG 密钥
    1
    curl https://pkg.cloudflareclient.com/pubkey.gpg | sudo gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg
  2. 将存储库添加到计算机的 apt 源
    1
    echo "deb [arch=amd64 signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflare-client.list
  3. 更新 apt
    1
    sudo apt update
  4. 安装 WARP
    1
    apt install cloudflare-warp
  5. 注册 WARP
    1
    warp-cli register
  6. 设置为代理模式(一定要先设置)
    1
    warp-cli set-mode proxy
  7. 连接 WARP
    1
    warp-cli connect

可能出现的错误

  1. 部分用到的命令系统可能没有安装,使用 apt-get install [packagename] 安装后再试
  2. 安装 WARP 时报错:
    1
    2
    3
    4
    E: Malformed entry 1 in list file /etc/apt/sources.list.d/cloudflare-client.list (Component)
    E: The list of sources could not be read.
    E: Malformed entry 1 in list file /etc/apt/sources.list.d/cloudflare-client.list (Component)
    E: The list of sources could not be read.
    这是由于之前有代码没有执行成功,比如缺少命令。执行如下命令后再试:
    1
    rm /etc/apt/sources.list.d/cloudflare-client.list
  3. 报错:bash: lsb_release: command not found
    安装 lsb_release 即可:apt-get install lsb-release
  4. 执行 warp-cli register 失败:
    1
    Error: "Unable to connect to CloudflareWARP daemon. Maybe the daemon is not running?"
    可能是缺少 systemctl 命令,安装后执行:systemctl start warp-svc

服务端设置

x-ui

安装 x-ui
1
bash <(curl -Ls https://raw.githubusercontent.com/FranzKafkaYu/x-ui/master/install.sh)
修改配置文件

面板设置 -> xray 相关设置,替换成下面这段,然后保存配置 -> 重启面板

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
{
"api": {
"services": [
"HandlerService",
"LoggerService",
"StatsService"
],
"tag": "api"
},
"inbounds": [
{
"listen": "127.0.0.1",
"port": 62789,
"protocol": "dokodemo-door",
"settings": {
"address": "127.0.0.1"
},
"tag": "api"
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
},
{
"tag": "socks5-warp",
"protocol": "socks",
"settings": {
"servers": [
{
"address": "127.0.0.1",
"port": 40000
}
]
}
},
{
"protocol": "blackhole",
"settings": {},
"tag": "blocked"
}
],
"policy": {
"levels": {
"0": {
"handshake": 10,
"connIdle": 100,
"uplinkOnly": 2,
"downlinkOnly": 3,
"statsUserUplink": true,
"statsUserDownlink": true,
"bufferSize": 10240
}
},
"system": {
"statsInboundDownlink": true,
"statsInboundUplink": true
}
},
"routing": {
"rules": [
{
"type": "field",
"outboundTag": "socks5-warp",
"domain": [
"geosite:openai"
]
},
{
"inboundTag": [
"api"
],
"outboundTag": "api",
"type": "field"
},
{
"ip": [
"geoip:private"
],
"outboundTag": "blocked",
"type": "field"
},
{
"outboundTag": "blocked",
"protocol": [
"bittorrent"
],
"type": "field"
}
]
},
"stats": {}
}

XrayR

安装 XrayR
1
wget -N https://raw.githubusercontent.com/XrayR-project/XrayR-release/master/install.sh && bash install.sh
修改配置文件

路径:/etc/XrayR

  1. 修改config.yml:取消注释 RouteConfigPathOutboundConfigPath 后的路径
  2. 修改custom_outbound.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
    [
    {
    "tag": "IPv4_out",
    "protocol": "freedom",
    "settings": {}
    },
    {
    "tag": "IPv6_out",
    "protocol": "freedom",
    "settings": {
    "domainStrategy": "UseIPv6"
    }
    },
    {
    "tag": "socks5-warp",
    "protocol": "socks",
    "settings": {
    "servers": [
    {
    "address": "127.0.0.1",
    "port": 40000
    }
    ]
    }
    },
    {
    "protocol": "blackhole",
    "tag": "block"
    }
    ]
  3. 修改route.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
    {
    "domainStrategy": "IPOnDemand",
    "rules": [
    {
    "type": "field",
    "outboundTag": "block",
    "ip": [
    "geoip:private"
    ]
    },
    {
    "type": "field",
    "outboundTag": "block",
    "protocol": [
    "bittorrent"
    ]
    },
    {
    "type": "field",
    "outboundTag": "socks5-warp",
    "domain": [
    "geosite:openai"
    ]
    },
    {
    "type": "field",
    "outboundTag": "IPv4_out",
    "network": "udp,tcp"
    }
    ]
    }
  4. 重启 XrayR:xrayr restart

ARM 机器的安装方法

第三方脚本

Ref: https://github.com/fscarmen/unlock_warp

1
2
3
sudo -i

bash <(curl -sSL https://gitlab.com/fscarmen/warp_unlock/-/raw/main/unlock.sh)
  1. 依次选择 2 -> 1 -> 2 -> 13

    image-20240217155553594

  2. 接下来会让你设置端口和账户,直接默认回车就好了image-20240217155828564

  3. 后面如何添加出站和路由规则跟上面一样的

调用脚本:warp [option] [lisence]

wgcf

WARP 官方并未支持 ARM 架构,不过有人做了类似的轮子,拿过来用就好了,教程参考 Xray 的 Wiki

以下以 Ubuntu 22.04 系统为例

安装 wgcf

仓库:https://github.com/ViRb3/wgcf

1
2
3
4
5
6
7
8
9
wget https://github.com/ViRb3/wgcf/releases/download/v2.2.20/wgcf_2.2.20_linux_arm64 # 下载预编译二进制文件

chmod +x wgcf_2.2.20_linux_arm64 # 设置可执行权限

mv wgcf_2.2.20_linux_arm64 /usr/local/bin/wgcf # 移动到系统的可执行路径,以便在任何位置运行它

wgcf register # 注册新账户

wgcf generate # 生成 WireGuard 配置文件

将会生成 wgcf-account.tomlwgcf-profile.conf 两个文件,wgcf-profile.conf 拷贝内容如下:

1
2
3
4
5
6
7
8
9
10
11
[Interface]
PrivateKey = 我的私钥
Address = 172.16.0.2/32
Address = 2606:4700:110:8949:fed8:2642:a640:c8e1/128
DNS = 1.1.1.1
MTU = 1280
[Peer]
PublicKey = Warp公钥
AllowedIPs = 0.0.0.0/0
AllowedIPs = ::/0
Endpoint = engage.cloudflareclient.com:2408

添加出站规则

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"protocol": "wireguard",
"tag": "wgcf",
"settings": {
"secretKey": "我的私钥",
"address":[
"172.16.0.2/32",
"2606:4700:110:8c26:d454:88f4:7751:3f28/128"
],
"mtu": 1280,
"peers": [
{
"publicKey": "Warp公钥",
"endpoint": "engage.cloudflareclient.com:2408"
}
]
}
},

添加路由分流

1
2
3
4
5
6
7
{
"type": "field",
"outboundTag": "wgcf",
"domain": [
"geosite:openai"
]
},

Alpine

配置环境

1
apk add wget bash sudo 

WARP 安装

1
wget -N https://gitlab.com/fscarmen/warp/-/raw/main/menu.sh && bash menu.sh