Files
knowledge-base/2 - Projects/VLESS-Reality/VLESS-REALITY-Setup-Guide.md

204 lines
6.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# VLESS + XTLS-Vision + REALITY 搭建文档
> 基于 Xray-core 官方仓库,当前最推荐的代理方案。
> 无需域名、无需 TLS 证书,流量伪装为正常 HTTPS 访问。
**部署状态:已完成** | 初始部署2026-03-14 | Xray 版本v26.2.6
**用途:翻墙回国** — 从瑞典通过国内代理访问国内资源
---
## 当前状态总览
### 已完成
- [x] 阿里云服务器 Xray-core 部署
- [x] iStoreOS 从旁路由升级为主网关
- [x] Deco BE65 切换为 AP 模式
- [x] DHCP 静态绑定19 台设备)
- [x] 端口映射迁移3 条规则)
- [x] OpenClash + mihomo 安装配置
- [x] 内网 DNSdnsmasq + OpenClash hosts
- [x] 广告拦截OpenClash GEOSITE 规则)
- [x] 翻墙回国验证v.qq.com 正常播放)
- [x] AdGuard Home 移除(由 OpenClash 接管广告拦截和 DNS
### 最终方案
不使用 AdGuard Home全部由 OpenClash + dnsmasq 处理:
- dnsmasq(:53) 负责内网 DNS + 转发到 OpenClash
- OpenClash(:7874) 负责 fake-ip 分流 + 广告拦截 + 翻墙回国
- NameServer 必须用海外 DNS8.8.8.8),不能用国内 DNS避免环路
---
## 服务器信息
| 项目 | 值 |
|------|-----|
| 服务器 | `8.138.1.192` (Ubuntu 24.04 LTS, 阿里云广州) |
| 端口 | `443` |
| UUID | `04a7cfe3-10f6-4e38-8319-22a604e24018` |
| Private Key | `mLQp0G0_yYYBNeviVJ674UmaYLimx9vbixVQhlESTWU` |
| Public Key | `RTO_UOk5ncr3DAAYR08g08L0fo5ax9pmGFj8c8lXWgk` |
| 伪装目标 | `www.microsoft.com` |
### 分享链接
```
vless://04a7cfe3-10f6-4e38-8319-22a604e24018@8.138.1.192:443?encryption=none&flow=xtls-rprx-vision&security=reality&sni=www.microsoft.com&fp=chrome&pbk=RTO_UOk5ncr3DAAYR08g08L0fo5ax9pmGFj8c8lXWgk&type=tcp#VLESS-Reality
```
---
## 网络拓扑
### 当前状态
```
光猫 (拨号, 瑞典 ISP)
▼ WAN (eth0, DHCP, 公网 IP)
iStoreOS / EasePi (192.168.68.63) ← 主网关
├── DHCP 服务器 (网关=.63, DNS=.63)
├── AdGuard Home Docker (:53) ← 临时,待迁出
├── OpenClash (已安装,未启用,与 AGH 冲突)
├── 端口映射 (2200, 443, 51888)
▼ LAN (eth1/eth2/eth3)
├── Deco BE65 (AP 模式) → mesh WiFi → 手机/平板/笔记本
└── 交换机 (2楼) → PVE + NAS + 其他有线设备
```
### 目标架构
```
光猫 → iStoreOS (192.168.68.63, 主网关)
├── DHCP (网关=.63, DNS=AGH的IP)
├── OpenClash (:7874, fake-ip + DNS劫持)
├── 端口映射
├── Deco BE65 (AP) → WiFi 设备
└── 交换机 (2楼)
├── PVE (192.168.68.69) → VM 跑 AdGuard Home
└── NAS (192.168.68.70)
DNS 链路:
设备 → AdGuard Home (PVE VM:53, 广告过滤+内网重写)
└→ 上游: OpenClash (192.168.68.63:7874, fake-ip)
├→ 国内域名 → VLESS 代理回国
└→ 海外域名 → 直连
```
---
## 物理布局
```
1楼: 光猫 → iStoreOS (EasePi) → Deco BE65 主机
2楼: 交换机 ← 网线连接 Deco → PVE 服务器 + NAS
```
注意2楼设备通过 Deco AP 桥接到 iStoreOS不是直连。
---
## 相关文档
| 文档 | 说明 |
|------|------|
| [主网关配置](./VLESS-REALITY-Router-iStoreOS.md) | iStoreOS 网络/DHCP/端口映射/OpenClash 配置 |
| [macOS 客户端](./VLESS-REALITY-Client-macOS.md) | ClashX Meta 客户端配置(外出时使用) |
| [AdGuard Home 备份](./adguardhome-backup-20260315.tar.gz) | 完整备份(配置+数据89MB |
---
## PVE 虚拟机列表
| VMID | 名称 | IP | 状态 | 说明 |
|------|------|-----|------|------|
| 100 | HA (Home Assistant) | - | running | 智能家居 |
| 101 | k8s-cp1 | - | running | K8s 控制面 |
| 102 | Wireguard | 192.168.68.107 | running | VPN |
| 103 | k8s-w1 | - | running | K8s 工作节点 |
| 104 | k8s-w2 | - | running | K8s 工作节点 |
| 105 | pg-01 | - | running | PostgreSQL |
| 106 | network-scanner | 192.168.68.84 | running | 网络扫描 |
| 110 | adguard-home (LXC) | 192.168.68.110 | running | AdGuard Home网络不稳定待修复 |
---
## 踩坑记录
### 1. OpenClash + AdGuard Home 53 端口冲突
OpenClash fake-ip 模式需要 DNS 劫持(占 53 端口),与 AdGuard Home 冲突。
尝试的方案:
- 关闭 DNS 劫持 → fake-ip 不生效,无法代理
- 开启防火墙转发 → dnsmasq 不运行DNS 全断
- AdGuard Home 上游指向 OpenClash → 其他设备(旁路由模式下)拿到 fake-ip 断网
**结论:必须分开部署在不同机器上。**
### 2. Deco BE65 不支持自定义 DHCP 网关/DNS
Deco 系列路由器的 DHCP 设置完全封闭,无法自定义下发网关和 DNS。
**解决方案:** Deco 切 AP 模式iStoreOS 接管 DHCP。
### 3. PVE LXC 容器网络延迟不稳定
Ubuntu 25.04 LXC 容器 eth0 不能自动启动,需要手动 `ip link set eth0 up`
即使手动配置后ping 延迟在 9ms~200ms 之间波动。
PVE 主机和 NAS 延迟正常3-7ms说明是 LXC 网络栈的问题。
**待解决:改用完整 VM 或修复 LXC 网络。**
### 4. 旁路由模式 bypass_gateway_compatible
OpenClash 旁路由模式下必须开启 `bypass_gateway_compatible=1`,否则转发流量不通。
同时必须关闭 `enable_redirect_dns=0`,否则会劫持所有设备 DNS 导致断网。
### 5. 1Password SSH Agent
SSH 到新 IP 时需要在 `~/.ssh/config` 中添加 `IdentityAgent` 配置指向 1Password socket。
不能用 `IdentitiesOnly=yes`,否则会阻止 1Password agent。
---
## 服务器管理
### 阿里云服务器 (8.138.1.192)
```bash
ssh admin@8.138.1.192
# Xray 管理
systemctl status xray
systemctl restart xray
journalctl -u xray -f
# 更新
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install
```
### iStoreOS 主网关 (192.168.68.63)
```bash
SSH_AUTH_SOCK="$HOME/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock" ssh root@192.168.68.63
# 紧急恢复(如果 OpenClash 搞坏了网络)
/etc/init.d/openclash stop
nft -a list chain inet fw4 dstnat | grep 'DNS Hijack' | grep -o 'handle [0-9]*' | while read h; do nft delete rule inet fw4 dstnat $h; done
nft -a list chain inet fw4 nat_output | grep 'DNS Hijack' | grep -o 'handle [0-9]*' | while read h; do nft delete rule inet fw4 nat_output $h; done
```
### PVE (192.168.68.69)
```bash
SSH_AUTH_SOCK="$HOME/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock" ssh root@192.168.68.69
# LXC 管理
pct list
pct start/stop/restart 110
pct exec 110 -- bash
```