前言
由于众所周知的GFW,大陆用git或者海外的模型都会随机需要一些门槛,在最开始学agent的时候正好是anthropic开始大规模封号,其中一个原因就是用公用梯子导致的ip频繁变动。为了防止被封,就搭了自己的服务器开shadowsocks服务,但因为懒一直没有记录过程。而今天开始记录,是因为发现vps的ip竟然被封了。
开始尝试一些不同的方法,看看能存活多久。
初次搭建
第一次搭建主要参考了这篇blog,感谢。
第一步:租一台VPS
自己搭建和直接买服务最大的一个区别是稳定的ip,可以避免一部分的检测,速度也更稳定,也可以尝试更多的花样,当然也需要更多的心思。
目前用的Lisahost,也是看网友推荐,试了一个月之后买了一年。拿到公网ip和端口、用户名(一般是root)、密码就算完事。
第二步:服务器部署代理服务
这里初次选的是shadowsocks协议,主要也是看中稳定、教程多,但后来踩坑也踩在这里,后面会讲。
具体的部署方式选用docker,也是考虑在服务器上方便迁移,比如要换ip。
登录vps,安装docker,创建一个docker-compose.yml如下:
version: '3.8'
services:
shadowsocks:
image: shadowsocks/shadowsocks-rust:latest
container_name: shadowsocks-rust
ports:
- "8388:8388/tcp" # 将服务器的 8388 端口映射到容器的 8388 端口
- "8388:8388/udp"
environment:
- METHOD=aes-256-gcm # 加密方法
- PASSWORD=YOUR_STRONG_PASSWORD # ‼️ 在这里设置一个你自己的强密码
restart: unless-stopped
启动命令docker-compose up -d。
第三步:客户端配置
客户端选择了用shadowrockets,也就是大名鼎鼎的小火箭进行配置,主要原因一是覆盖了我常用的操作系统,不用重复学习;二是提供流量分发,并且提供了默认的规则文件,基本可以覆盖日常的使用网站,可以按照规则选择走不走代理,日常可以保持连接。
约等于傻瓜式,新建一个节点,按照上面的信息去填,使用默认规则集,测一下连通性就完事。
被封
在用了一个多月的时候,明显感觉有降速,在git clone的时候跌到几十kb的速度,然后没过几天就连不上,测试一下发现是被封ip了。这时候才知道原来自建的也是有被封风险,查了一下可能主要触雷的点有:
shadowsocks不再安全。虽然本身是加密协议,但GFW检测的时候并不需要知道密文内容,而是根据流量特征,比如规则的长度、握手特征接等等特征进行检测。在被动检测发现可疑ip后会主动发送探测性密文,一旦发送对应回复就会被确认然后封杀。具体可以看这篇对GFW report的讲解。
长时间连接,也属于被检测的重点特征
使用了非常规端口,而不是常用的443
尝试绕开
目前有两个思路,一是换ip,然后用VLESS + Reality,更难被检测但可能也只是时间问题。二是用CloudFlare做流量转发,优点是比较安全,GFW还不太敢封CF的ip,但缺点是有可能降速。还有一种方法是用naiveproxy,伪装性更好更难被探测。
准备先走一的路径,也即vless +reality+tcp。
服务器安装Xray
安装基础工具:
sudo apt install curl unzip -y
使用Xray实现v2ray代理。官方安装脚本安装Xray:
bash <(curl -Ls https://raw.githubusercontent.com/XTLS/Xray-install/main/install-release.sh)
安装后确认/usr/local/bin/xray路径存在。
Xray配置
生成UUID,
执行:
xray uuid
得到uuid类似于xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx。
生成REALITY密钥
执行:
xray x25519
记录输出的privateKey/publicKey。
修改配置文件
编辑/usr/local/etc/xray/config.json,最小可用示例如下:
{
"inbounds": [
{
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "你的UUID",
"flow": "xtls-rprx-vision"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "reality",
"realitySettings": {
"show": false,
"dest": "www.microsoft.com:443",
"xver": 0,
"serverNames": [
"www.microsoft.com"
],
"privateKey": "你的PrivateKey",
"shortIds": [
"6ba85179e30d4fc2"
]
}
}
}
],
"outbounds": [
{
"protocol": "freedom"
}
]
}
这样REALITY服务会模仿Microsoft的TLS行为,进而躲避审查。
一个更完备的VLESS + REALITY + Vision组合入下:
{
"log": {
"loglevel": "warning",
"access": "none",
"error": "/var/log/xray/error.log"
},
"dns": {
"servers": [
"1.1.1.1",
"8.8.8.8",
"localhost"
],
"queryStrategy": "UseIP"
},
"inbounds": [
{
"tag": "vless-reality-in",
"listen": "0.0.0.0",
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "替换成你的UUID",
"flow": "xtls-rprx-vision",
"email": "user1"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "reality",
"tcpSettings": {
"acceptProxyProtocol": false
},
"realitySettings": {
"show": false,
"target": "www.microsoft.com:443",
"serverNames": [
"www.microsoft.com"
],
"privateKey": "替换成你的PrivateKey",
"shortIds": [
"6ba85179e30d4fc2"
]
}
},
"sniffing": {
"enabled": true,
"destOverride": [
"http",
"tls",
"quic"
],
"routeOnly": true
}
}
],
"outbounds": [
{
"tag": "direct",
"protocol": "freedom",
"settings": {
"domainStrategy": "UseIP"
}
},
{
"tag": "block",
"protocol": "blackhole"
}
],
"routing": {
"domainStrategy": "IPIfNonMatch",
"rules": [
{
"type": "field",
"protocol": [
"bittorrent"
],
"outboundTag": "block"
},
{
"type": "field",
"ip": [
"geoip:private"
],
"outboundTag": "block"
},
{
"type": "field",
"outboundTag": "direct",
"network": "tcp,udp"
}
]
}
}
启动服务
启动服务并查看状态和日志:
sudo systemctl restart xray
sudo systemctl status xray
journalctl -u xray -f
status应显示active(running),日志有started字样表示启动成功。
客户端配置
rocket也支持配置v2ray的配置,填写下面对应信息:
协议:VLESS
地址:你的 VPS IP
端口:443
UUID:同服务端 id
Flow:xtls-rprx-vision
传输:TCP
TLS/安全:REALITY
SNI/serverName:www.microsoft.com
Public Key:xray x25519 生成的 Public key
Short ID:同服务端 shortIds
Fingerprint:chrome
这样整个流程就是配置完成了,看后续能存在多久吧,再持续更新。
Previous
手搓框架M1:LLM基类的进化