mirror of
https://github.com/XTLS/Xray-docs-next.git
synced 2026-09-22 22:38:05 +03:00
Refine tproxy article layout
This commit is contained in:
@@ -20,18 +20,18 @@
|
||||
|
||||
---
|
||||
|
||||
[Nginx 或 Haproxy 搭建 TLS 隧道隐藏指纹](./nginx_or_haproxy_tls_tunnel.md) by <img src="https://avatars.githubusercontent.com/u/110686480?s=32" width="24" height="24" alt="a" style="display:inline-block;vertical-align:middle;border-radius:50%;margin:0 0.25em;"/> [@SQLimit](https://github.com/SQLimit)
|
||||
|
||||
双端使用 Nginx 或 Haproxy 搭建 TLS 隧道隐藏指纹
|
||||
|
||||
---
|
||||
|
||||
[[透明代理]通过 gid 规避 Xray 流量](./iptables_gid.md) by <img src="https://avatars2.githubusercontent.com/u/57820613?s=32" width="24" height="24" alt="a" style="display:inline-block;vertical-align:middle;border-radius:50%;margin:0 0.25em;"/> [@kirin](https://github.com/kirin10000)
|
||||
|
||||
在 iptables/nftables 实现的透明代理中,一种新的规避 Xray 流量的方式。
|
||||
|
||||
---
|
||||
|
||||
[Nginx 或 Haproxy 搭建 TLS 隧道隐藏指纹](./nginx_or_haproxy_tls_tunnel.md) by <img src="https://avatars.githubusercontent.com/u/110686480?s=32" width="24" height="24" alt="a" style="display:inline-block;vertical-align:middle;border-radius:50%;margin:0 0.25em;"/> [@SQLimit](https://github.com/SQLimit)
|
||||
|
||||
双端使用 Nginx 或 Haproxy 搭建 TLS 隧道隐藏指纹
|
||||
|
||||
---
|
||||
|
||||
[通过 Xray 将特定的流量指向特定出口,实现全局路由“分流”](./redirect.md) by <img src="https://avatars.githubusercontent.com/u/28607089?s=32" width="24" height="24" alt="a" style="display:inline-block;vertical-align:middle;border-radius:50%;margin:0 0.25em;"/> [@Zzz3m](https://github.com/Zzz3m)
|
||||
|
||||
将 Xray 玩出花:基于 fwmark 、 sendThrough 或 sockopt.interface 方式实现“分流”。
|
||||
@@ -50,6 +50,6 @@ Xray v1.6.5 新增 WireGuard 出站的使用介绍。
|
||||
|
||||
---
|
||||
|
||||
[VLESS 反向代理](./vless_reverse.md)
|
||||
[VLESS 反向代理](./vless_reverse.md) by <img src="https://avatars.githubusercontent.com/u/197331664?s=32" width="24" height="24" alt="a" style="display:inline-block;vertical-align:middle;border-radius:50%;margin:0 0.25em;"/> [@Meo597](https://github.com/Meo597)
|
||||
|
||||
VLESS 反向代理教程。
|
||||
|
||||
@@ -161,7 +161,7 @@ sudo curl -oL /usr/local/share/xray/geosite.dat https://github.com/Loyalsoldier/
|
||||
|
||||
## 策略路由配置
|
||||
|
||||
```
|
||||
```sh
|
||||
sudo ip route add local default dev lo table 100 # 添加路由表 100
|
||||
sudo ip rule add fwmark 1 table 100 # 为路由表 100 设定规则
|
||||
```
|
||||
@@ -170,9 +170,13 @@ sudo ip rule add fwmark 1 table 100 # 为路由表 100 设定规则
|
||||
|
||||
::: warning 注意
|
||||
nftables 配置与 iptables 配置二选一,不可同时使用。
|
||||
|
||||
将所选配置写入文件,赋予可执行权限后,再使用 root 权限执行该文件即可。
|
||||
:::
|
||||
|
||||
```nftables
|
||||
::: code-group
|
||||
|
||||
```bash [nftables.conf]
|
||||
#!/usr/sbin/nft -f
|
||||
|
||||
flush ruleset
|
||||
@@ -210,12 +214,7 @@ table ip xray {
|
||||
}
|
||||
```
|
||||
|
||||
::: tip 使用方法
|
||||
|
||||
将上述配置写入一个文件(如 `nft.conf`),之后将该文件赋予可执行权限,最后使用 root 权限执行该文件即可(`# ./nft.conf`)。
|
||||
:::
|
||||
|
||||
```bash
|
||||
```bash [iptables.sh]
|
||||
iptables -t mangle -N XRAY
|
||||
iptables -t mangle -A XRAY -d 10.0.0.0/8 -j RETURN
|
||||
iptables -t mangle -A XRAY -d 100.64.0.0/10 -j RETURN
|
||||
@@ -250,13 +249,31 @@ iptables -t mangle -A XRAY_SELF -p udp -j MARK --set-mark 1
|
||||
iptables -t mangle -A OUTPUT -j XRAY_SELF
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
配置完成后,将局域网内其它设备的默认网关改为该设备 IP,就可以直接翻墙了。在其它主机和本机皆测试成功后,可进行下一步配置。
|
||||
|
||||
## 配置永久化与开机自启
|
||||
|
||||
首先将已经编辑好的 nftables 配置文件移动到 `/etc` 目录下,并重命名为 `nftables.conf`。然后编辑 `/lib/systemd/system/nftables.service`。
|
||||
根据前面 Netfilter 配置中的选择,这里应使用对应的持久化方式。
|
||||
|
||||
```ini
|
||||
- **如果使用 `nftables`**
|
||||
|
||||
先将已经编辑好的配置文件移动到 `/etc` 目录下,然后编辑 `/lib/systemd/system/nftables.service`
|
||||
|
||||
- **如果使用 `iptables`**
|
||||
|
||||
建议直接安装 `iptables-persistent`
|
||||
|
||||
安装过程中会提示你选择“是否保存配置”,如果已经将 `iptables` 配置写入系统,那么此时选择“是”即可;如果尚未写入也没有关系,安装完毕后将配置写入,然后执行 `netfilter-persistent save` 即可(需要 root 权限)
|
||||
|
||||
之后编辑 `/lib/systemd/system/netfilter-persistent.service`
|
||||
|
||||
最后 enable 所选服务即可。
|
||||
|
||||
::: code-group
|
||||
|
||||
```ini [nftables.service]
|
||||
[Unit]
|
||||
Description=nftables
|
||||
Documentation=man:nft(8) http://wiki.nftables.org
|
||||
@@ -279,15 +296,7 @@ ExecStop=/usr/sbin/nft flush ruleset ; /usr/sbin/ip route del local default dev
|
||||
WantedBy=sysinit.target
|
||||
```
|
||||
|
||||
最后 enable 即可。
|
||||
|
||||
关于 iptables 的永久化,建议直接安装 `iptables-persistent`。
|
||||
|
||||
安装过程中会提示你选择“是否保存配置”,如果已经将 iptables 配置写入系统,那么此时选择“是”即可;如果尚未写入也没有关系,安装完毕后将配置写入,然后执行 `netfilter-persistent save` 即可(需要 root 权限)。
|
||||
|
||||
之后编辑 `/lib/systemd/system/netfilter-persistent.service`。
|
||||
|
||||
```ini
|
||||
```ini [netfilter-persistent.service]
|
||||
[Unit]
|
||||
Description=netfilter persistent configuration
|
||||
DefaultDependencies=no
|
||||
@@ -306,3 +315,5 @@ ExecStop=/usr/sbin/netfilter-persistent stop ; /usr/sbin/ip route flush dev lo t
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
@@ -260,7 +260,7 @@
|
||||
|
||||
### 首先设置策略路由
|
||||
|
||||
```bash
|
||||
```sh
|
||||
# 设置策略路由 v4
|
||||
ip rule add fwmark 1 table 100
|
||||
ip route add local 0.0.0.0/0 dev lo table 100
|
||||
@@ -287,7 +287,7 @@ ip -6 route add default via fd00:6868:6868::1 #写主路由 ipv6, 采用局域
|
||||
|
||||
如果是在路由器上指定了默认网关为旁路由(亦即下述“局域网设备上网设置方法二”),那么就需要设置上述 `# 直连从主路由发出` ,除了通过 iproute2 命令行方式设置,也可以通过 dhcpcd 或者 systemctl-network 设置静态 IP,这里以 dhcpcd 为例,编辑 `/etc/dhcpcd.conf` 文件,在最下方加入如下配置,具体 IP 根据你的实际情况修改,其中 `interface` 可以通过 `# ip link show` 查看要设定的网口或者无线设备。
|
||||
|
||||
```
|
||||
```ini
|
||||
interface enp0s25
|
||||
static ip_address=192.168.31.100/24
|
||||
static ip6_address=fd00:6868:6868::8888/64
|
||||
@@ -300,13 +300,13 @@ static domain_name_servers=192.168.31.1 fd00:6868:6868::1
|
||||
::: warning 注意
|
||||
|
||||
以下 nftables 配置与 iptables 配置二选一,不可同时使用。
|
||||
|
||||
将所选配置写入文件,赋予可执行权限后,再使用 root 权限执行该文件即可。
|
||||
:::
|
||||
|
||||
### 使用 iptables
|
||||
::: code-group
|
||||
|
||||
此处配置将 ipv4 与 ipv6 写在同一文件中。
|
||||
|
||||
```bash
|
||||
```bash [iptables.rules]
|
||||
# 代理局域网设备 v4
|
||||
iptables -t mangle -N XRAY
|
||||
iptables -t mangle -A XRAY -d 127.0.0.1/32 -j RETURN
|
||||
@@ -365,18 +365,7 @@ ip6tables -t mangle -I PREROUTING -p tcp -m socket -j DIVERT
|
||||
|
||||
```
|
||||
|
||||
::: tip 使用方法
|
||||
|
||||
将上述配置写入一个文件(如 `iptables.rules`),之后将该文件赋予可执行权限`# chmod 700 ./iptables.rules`
|
||||
|
||||
最后使用 root 权限执行该文件即可:`# ./iptables.rules`或`# source iptables.rules`。
|
||||
:::
|
||||
|
||||
### 使用 nftables
|
||||
|
||||
此处合并 ipv4 与 ipv6
|
||||
|
||||
```
|
||||
```bash [nftables.rules]
|
||||
#!/usr/sbin/nft -f
|
||||
|
||||
flush ruleset
|
||||
@@ -415,11 +404,6 @@ table inet xray {
|
||||
|
||||
```
|
||||
|
||||
::: tip 使用方法
|
||||
|
||||
将上述配置写入一个文件(如 `nftables.rules`),之后将该文件赋予可执行权限`# chmod 700 ./nftables.rules`
|
||||
|
||||
最后使用 root 权限执行该文件即可:`# ./nftables.rules`或`# source nftables.rules`
|
||||
:::
|
||||
|
||||
其中,网关地址`192.168.0.0/16`, `fd00::/8`等可由`ip address | grep -w inet | awk '{print $2}'`以及`ip address | grep -w inet6 | awk '{print $2}'`[获得](https://xtls.github.io/document/level-2/iptables_gid.html#_4-%E8%AE%BE%E7%BD%AE-iptables-%E8%A7%84%E5%88%99)
|
||||
@@ -434,13 +418,19 @@ table inet xray {
|
||||
|
||||
首先确认已经运行过上述相应 Netfilter 命令,并且成功测试透明代理配置,以确保接下来输出正确的文件。
|
||||
|
||||
#### 若使用 iptables 配置
|
||||
- **如果使用 `iptables`**
|
||||
|
||||
1. 首先通过 `# iptables-save > /root/iptables.rulesv4` `# ip6tables-save > /root/iptables.rulesv6` 将 iptables 配置写入 `iptables.rulesv4` 和 `iptables.rulesv6` 文件中
|
||||
先通过 `# iptables-save > /root/iptables.rulesv4` `# ip6tables-save > /root/iptables.rulesv6` 将配置写入 `iptables.rulesv4` 和 `iptables.rulesv6`
|
||||
|
||||
2. 然后在 `/etc/systemd/system/` 目录下创建一个名为 `tproxyrules.service` 的文件,添加以下内容并保存
|
||||
- **如果使用 `nftables`**
|
||||
|
||||
```
|
||||
先通过 `# nft list ruleset > /root/nftables.rulesv46` 将配置写入 `nftables.rulesv46`
|
||||
|
||||
随后在 `/etc/systemd/system/` 目录下创建 `tproxyrules.service`,根据所选方案写入对应内容,最后执行 `systemctl enable tproxyrules`。
|
||||
|
||||
::: code-group
|
||||
|
||||
```ini [iptables tproxyrules.service]
|
||||
[Unit]
|
||||
Description=Tproxy rules
|
||||
|
||||
@@ -469,15 +459,7 @@ ExecStop=/sbin/ip rule del fwmark 1 table 100 ; \
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
3. 最后执行 `systemctl enable tproxyrules` 命令。
|
||||
|
||||
#### 如果使用 nftables 配置
|
||||
|
||||
1. 首先通过 `# nft list ruleset > /root/nftables.rulesv46` 将 nftables 配置写入 `nftables.rulesv46` 文件中
|
||||
|
||||
2. 在 `/etc/systemd/system/` 目录下创建一个名为 `tproxyrules.service` 的文件,然后添加以下内容并保存
|
||||
|
||||
```
|
||||
```ini [nftables tproxyrules.service]
|
||||
[Unit]
|
||||
Description=Tproxy rules
|
||||
|
||||
@@ -504,7 +486,7 @@ ExecStop=/sbin/ip rule del fwmark 1 table 100 ; \
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
3. 最后执行 `systemctl enable tproxyrules` 命令。
|
||||
:::
|
||||
|
||||
::: tip tproxyrules.service
|
||||
|
||||
|
||||
Reference in New Issue
Block a user