前言
通常我们用Cloudflare WARP通过替换VPS的双栈或单栈网络来通过获得所谓“原生IP”,从而解锁Netflex等流媒体,而如果直接替换掉双栈网络会导致VPS失联,即使通过修改路由表正常使用也会影响到Docker等应用的NAT。实际上我们只需要让Xray的流量走WARP接口出去就行了,outbounds配置提供了sendThrough
用来指定出口IP,streamSettings.sockopt.mark
用来设置fwmark
。我之前直接指定为WARP的IP发现并不行,收不到回包(实际上如果直接指定接口名就正常使用了,可惜不支持)。在翻Xray的文档时才发现还需要配置一下路由表才行。
使用sendThrough
wireguard配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| [Interface] PrivateKey = <你的私钥> Address = <你的wireguard IPv4地址> Address = <你的wireguard IPv6地址> DNS = 8.8.8.8 MTU = 1280 Table = off PostUP = ip -4 rule add from <你的wireguard IPv4地址> lookup 51820 PostUP = ip -4 route add default dev <wireguard接口名> table 51820 PostUP = ip -4 rule add table main suppress_prefixlength 0 PostDown = ip -4 rule delete from 172.16.0.2/32 lookup 51820 PostDown = ip -4 rule delete table main suppress_prefixlength 0 [Peer] PublicKey = <你的公钥> Endpoint = engage.cloudflareclient.com:2408 AllowedIPs = 0.0.0.0/0,::/0
|
上述配置将所有来自wireguard IPv4地址的数据包指定走路由表51820,同时为路由表51820添加默认路由(表编号你取个其他名字也行)
然后测试一下curl https://api.0vo.moe/ip --interface <你的wireguard IPv4地址>
,显示WARP的IP就成功了
Xray配置
outbounds部分配置
1 2 3 4 5 6 7 8
| { "outbounds": [ { "protocol": "freedom", "sendThrough": "你的wireguard IPv4地址" } ] }
|
如果你使用机场后端,如XrayR,可如下配置
1 2
| ControllerConfig: SendIP: 你的wireguard IPv4地址
|
注:上文只配置了IPv4,如需IPv6请在Xray中新建一个使用IPv6的outbound,并使用routes进行匹配,同时在wireguard中添加IPv6的路由规则配置
使用fwmark
wireguard配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| [Interface] PrivateKey = <你的私钥> Address = <你的wireguard IPv4地址> Address = <你的wireguard IPv6地址> DNS = 8.8.8.8 MTU = 1280 Table = off PostUP = ip -4 rule add fwmark 51820 lookup 51820 PostUP = ip -4 route add default dev <wireguard接口名> table 51820 PostUP = ip -4 rule add table main suppress_prefixlength 0 PostUP = ip -6 rule add fwmark 51820 lookup 51820 PostUP = ip -6 route add ::/0 dev <wireguard接口名> table 51820 PostUP = ip -6 rule add table main suppress_prefixlength 0 PostDown = ip -4 rule delete fwmark 51820 lookup 51820 PostDown = ip -4 rule delete table main suppress_prefixlength 0 PostDown = ip -6 rule delete fwmark 51820 lookup 51820 PostDown = ip -6 rule delete table main suppress_prefixlength 0 [Peer] PublicKey = <你的公钥> Endpoint = engage.cloudflareclient.com:2408 AllowedIPs = 0.0.0.0/0,::/0
|
上述配置将所有mark为51820的数据包指定走路由表51820,同时为路由表51820添加默认路由,表编号和mark可自定义
Xray配置
outbounds部分配置
1 2 3 4 5 6 7 8
| { "protocol": "freedom", "streamSettings": { "sockopt": { "mark": 51820 } } }
|
这里的mark和路由的保持一致
相比使用sendThrough
,这里无需额外设置即可实现双栈访问
参考文档:https://xtls.github.io/Xray-docs-next/document/level-2/redirect.html