基于海外云服务器自建vpn节点

·335 阅读

第一步:基础环境

首先你需要准备一台 VPS 512MB 内存够用,我的服务器是腾讯云的OpenCloudOS,Ubuntu用户把 dnf 换成 apt、firewalld 换成 ufw 就行

# 安装常用工具
dnf install -y curl wget vim tar firewalld

# 启动防火墙
systemctl enable --now firewalld

# 关闭 SELinux(省得 Xray 被权限卡住)
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

# 开 BBR 加速
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sysctl -p

# 验证 BBR
sysctl net.ipv4.tcp_congestion_control   # 输出 bbr 就成功

第二步:装 Xray + 生成参数

# 装 Xray
bash <(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)

# 生成 UUID(你的身份密码)
xray uuid

# 生成 REALITY 密钥对
xray x25519

# 生成 shortId
openssl rand -hex 8

你要拿到四样东西,记下来:UUID、PrivateKey、PublicKey、shortId

第三步:写配置文件

cat > /usr/local/etc/xray/config.json << 'EOF'
{
  "log": {
    "loglevel": "warning"
  },
  "inbounds": [
    {
      "listen": "0.0.0.0",
      "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": [
            "你的shortId"
          ]
        }
      },
      "sniffing": {
        "enabled": true,
        "destOverride": ["http", "tls", "quic"]
      }
    }
  ],
  "outbounds": [
    {"protocol": "freedom", "tag": "direct"},
    {"protocol": "blackhole", "tag": "block"}
  ]
}
EOF

只替换 3 个地方:你的UUID、你的PrivateKey、你的shortId。

关于 www.microsoft.com这不是你的域名,是 REALITY 的伪装目标 外面看你就是在访问微软官网,你也可以换成 www.apple.comgateway.icloud.com 等支持 TLS 1.3 + H2 的大站

第四步:启动 + 防火墙

# 测试配置
xray run -test -c /usr/local/etc/xray/config.json

# 启动
systemctl enable xray
systemctl restart xray
systemctl status xray --no-pager

# 防火墙只留 443
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload
验证服务端:
ss -lntp | grep 443      # 看到 xray 监听 *:443 就对了
journalctl -u xray -n 30 --no-pager   # 没有报错就 OK

客户端配置

Clash Verge Rev 不能界面手动加节点,要导入 yaml 文件,新建 reality-proxy.yaml:

mixed-port: 7890
allow-lan: false
mode: rule
log-level: info

proxies:
  - name: "Reality"
    type: vless
    server: 你的VPS公网IP
    port: 443
    uuid: 你的UUID
    network: tcp
    tls: true
    udp: false
    servername: www.microsoft.com
    flow: xtls-rprx-vision
    client-fingerprint: chrome
    reality-opts:
      public-key: 你的PublicKey
      short-id: 你的shortId

proxy-groups:
  - name: "Proxy"
    type: select
    proxies: ["Reality", DIRECT]

rules:
  - GEOIP,CN,DIRECT
  - MATCH,Proxy

替换四个地方:你的VPS公网IP、你的UUID、你的PublicKey、你的shortId 导入方法: 打开 Clash Verge Rev → 订阅→ 拖拽 yaml 文件进去 → 点击新配置卡片激活 → 回到代理页面选Reality节点。

进阶:链式代理 + 静态住宅 IP 出口

如果你有额外买的静态住宅 IP(SOCKS5 格式),可以让流量走 Reality 出去后再走住宅 IP,最终出口变成住宅 IP。链路是你 → VPS(Reality) → 静态住宅 SOCKS5 → 目标网站 yaml 里加一个节点,用 dialer-proxy 串起来

proxies:
  - name: "Reality"
    type: vless
    server: 你的VPS公网IP
    port: 443
    uuid: 你的UUID
    network: tcp
    tls: true
    udp: false
    servername: www.microsoft.com
    flow: xtls-rprx-vision
    client-fingerprint: chrome
    reality-opts:
      public-key: 你的PublicKey
      short-id: 你的shortId

  - name: "ResiExit"
    type: socks5
    server: 住宅代理IP
    port: 住宅代理端口
    username: 用户名
    password: 密码
    udp: false
    dialer-proxy: "Reality"    # 关键:通过 Reality 这一跳拨出去

proxy-groups:
  - name: "Proxy"
    type: select
    proxies:
      - "Reality"       # 出口是 VPS IP
      - "ResiExit"       # 出口是住宅 IP
      - DIRECT

clash仓库

android:https://github.com/MetaCubeX/ClashMetaForAndroid

win/macOS/linux(GUI):https://github.com/clash-verge-rev/clash-verge-rev

linux:https://github.com/MetaCubeX/mihomo

测试方法

测 Reality 是否通了: 代理选 Reality,浏览器打开 https://ipconfig.io ,如果显示的是海外 IP(你 VPS 的 IP),代理就通了,再打开 Google、YouTube 确认正常。

测住宅出口是否生效: 先用 Reality 看一次 ipconfig.io 记下 IP,再切到住宅出口打开ipip.la,如果 IP 变了显示家庭住宅ip,链式代理就生效了。

其实你可以直接把这个链接给到agent,让他部署(手动狗头)