docs: 优化issue说明文档
This commit is contained in:
+47
-52
@@ -1,35 +1,10 @@
|
||||
# easytier 被 transparent OUTPUT 规则截获
|
||||
# easytier 连接 peer 超时
|
||||
|
||||
## 现象
|
||||
## 问题原因
|
||||
|
||||
开启 `pyxray` transparent redirect 后,`easytier` 持续连接 peer 超时:
|
||||
`easytier` 使用 `network_mode: host`,它发起的 peer 连接属于宿主机本机流量,会经过 `nat OUTPUT`。
|
||||
|
||||
```text
|
||||
connecting to peer dst=tcp://117.72.47.28:33010
|
||||
connect to peer error ... Timeout
|
||||
```
|
||||
|
||||
临时添加绕过规则后立即恢复:
|
||||
|
||||
```sh
|
||||
sudo iptables -w 2 -t nat -I TP_OUT 1 -p tcp -d 117.72.47.28 --dport 33010 -j RETURN
|
||||
```
|
||||
|
||||
## 机理
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
E[easytier-core<br/>host network + UID 0] --> O[nat OUTPUT]
|
||||
O --> TPO[TP_OUT]
|
||||
TPO --> TPR[TP_RULE]
|
||||
TPR --> R[REDIRECT :52345]
|
||||
R --> X[Xray transparent inbound]
|
||||
X --> P[peer 117.72.47.28:33010]
|
||||
```
|
||||
|
||||
`easytier` 使用 `network_mode: host`,它发出的 peer TCP 连接属于宿主机本机流量,会进入 `nat OUTPUT`。
|
||||
|
||||
`pyxray` redirect transparent 会安装:
|
||||
`pyxray` 开启 transparent redirect 后,会把宿主机本机 TCP 流量转到 Xray transparent inbound:
|
||||
|
||||
```sh
|
||||
iptables -t nat -I OUTPUT -p tcp -j TP_OUT
|
||||
@@ -37,43 +12,63 @@ iptables -t nat -A TP_OUT -j TP_RULE
|
||||
iptables -t nat -A TP_RULE -p tcp -j REDIRECT --to-ports 52345
|
||||
```
|
||||
|
||||
因此 `easytier -> 117.72.47.28:33010` 被重定向到 `127.0.0.1:52345`,不再按 easytier 预期直连 peer,最终表现为连接超时。
|
||||
|
||||
## 为什么不用 UID 绕过
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
R[按 UID 绕过] --> U0{easytier UID}
|
||||
U0 -->|0/root| Wide[会放过所有 root 本机连接]
|
||||
U0 -->|非 root| OK[可精确绕过]
|
||||
```
|
||||
|
||||
当前 `easytier`、`pyxray`、`xray` 都以 root 运行。按 UID 0 绕过范围过大,不适合作为默认方案。
|
||||
|
||||
## 推荐修复
|
||||
|
||||
在 `TP_OUT` 跳转到 `TP_RULE` 前,按目标地址和端口添加 RETURN:
|
||||
因此 easytier 访问 peer 时,连接会被改写:
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
E[easytier-core] --> O[nat OUTPUT]
|
||||
E[easytier-core<br/>tcp://117.72.47.28:33010] --> O[nat OUTPUT]
|
||||
O --> TPO[TP_OUT]
|
||||
TPO --> B{match tcp<br/>117.72.47.28:33010}
|
||||
B -->|yes| D[RETURN 直连]
|
||||
B -->|no| TPR[TP_RULE -> REDIRECT :52345]
|
||||
TPO --> TPR[TP_RULE]
|
||||
TPR --> R[REDIRECT :52345]
|
||||
R --> X[Xray transparent inbound]
|
||||
```
|
||||
|
||||
配置示例:
|
||||
结果是 easytier 没有直连到自己的 peer,日志表现为:
|
||||
|
||||
```text
|
||||
connecting to peer dst=tcp://117.72.47.28:33010
|
||||
connect to peer error ... Timeout
|
||||
```
|
||||
|
||||
## 解决方案
|
||||
|
||||
在 UI 的“核心 -> transparent”里添加 OUTPUT 绕过规则,让 easytier peer 连接在进入 `TP_RULE` 前直接 `RETURN`。
|
||||
|
||||
示例:
|
||||
|
||||
```text
|
||||
tcp 117.72.47.28:33010
|
||||
```
|
||||
|
||||
也支持网段:
|
||||
生成后的关键规则:
|
||||
|
||||
```sh
|
||||
iptables -t nat -A TP_OUT -p tcp -d 117.72.47.28 --dport 33010 -j RETURN
|
||||
iptables -t nat -A TP_OUT -j TP_RULE
|
||||
```
|
||||
|
||||
修复后的流量路径:
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
E[easytier-core<br/>tcp://117.72.47.28:33010] --> O[nat OUTPUT]
|
||||
O --> TPO[TP_OUT]
|
||||
TPO --> B{match tcp<br/>117.72.47.28:33010}
|
||||
B -->|yes| D[RETURN<br/>直连 peer]
|
||||
B -->|no| TPR[TP_RULE]
|
||||
TPR --> R[REDIRECT :52345]
|
||||
```
|
||||
|
||||
规则格式:
|
||||
|
||||
```text
|
||||
tcp 117.72.47.28:33010
|
||||
all 192.168.0.0/24
|
||||
udp 198.51.100.10:3478
|
||||
```
|
||||
|
||||
该规则只影响宿主机本机 `OUTPUT`,不改变 Docker 容器透明代理的 `PREROUTING` 行为。
|
||||
说明:
|
||||
|
||||
- `redirect` 模式只处理 TCP,因此只生成 TCP 绕过规则。
|
||||
- `tproxy` 模式支持 TCP 和 UDP。
|
||||
- 规则只作用于宿主机本机 `OUTPUT`,不改变 Docker 容器透明代理的 `PREROUTING` 行为。
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "pyxray"
|
||||
version = "1.0.2"
|
||||
version = "1.0.3"
|
||||
description = "A lightweight Linux xray control plane."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.14"
|
||||
|
||||
Reference in New Issue
Block a user