eycorsican / go-tun2socks

A tun2socks implementation written in Go.
MIT License
1.3k stars 432 forks source link

为什么我在macOS下尝试dynamic routing,好像死循环一样 #64

Closed tony1016 closed 5 years ago

tony1016 commented 5 years ago

我的v2ray配置文件大概是这样子

{
    "log":
    {
        "loglevel": "debug"
    },
    "outbounds": [
    {
        "protocol": "vmess",
       ...
    },
    {
        "protocol": "freedom",
        "settings":
        {},
        "tag": "direct"
    }],
    "routing":
    {
        "domainStrategy": "IPOnDemand",
        "rules": [
        {
            "type": "field",
            "outboundTag": "direct",
            "domain": ["geosite:cn"]
        },
        {
            "type": "field",
            "outboundTag": "direct",
            "ip": [
                "geoip:cn",
                "geoip:private"
            ]
        }]
    }
}

开启动态路由:

sudo tun2socks -proxyType v2ray -vconfig tun2socks.json -gateway 172.31.80.1

然后我仅仅是尝试把114.114.114.114路由到该tun,用dig t.cn @114.114.114.114进行测试,结果日志像死循环一样:


new proxy connection for target: udp:114.114.114.114:53
2019/06/12 14:54:43 [Debug] v2ray.com/core/transport/internet/udp: dispatch request to: udp:114.114.114.114:53
2019/06/12 14:54:43 [Info] v2ray.com/core/transport/internet/udp: establishing new connection for udp:114.114.114.114:53
2019/06/12 14:54:43 [Info] v2ray.com/core/app/dispatcher: taking detour [direct] for [udp:114.114.114.114:53]
2019/06/12 14:54:43 [Info] v2ray.com/core/proxy/freedom: opening connection to udp:114.114.114.114:53
``
eycorsican commented 5 years ago

已经不建议用 dynamic routing。

其实可以加两条默认路由:https://github.com/eycorsican/go-tun2socks/blob/d0d16ba3c64f196ac4e2c1c1421cbe2296ba7055/proxy/d/tcp.go#L24

然后配置 v2ray 所有 outbound 的 sendThrough:https://github.com/eycorsican/go-tun2socks/blob/d0d16ba3c64f196ac4e2c1c1421cbe2296ba7055/proxy/d/tcp.go#L32

然后 freedom outbound 使用 UseIP。

这样一来其它 app 使用第一条路由转到 tun,再给到 v2ray,而由 v2ray 发出的所有流量就会使用第二条默认路由。

tony1016 commented 5 years ago

嗯,好主意,明白了

tony1016 commented 5 years ago

倒是成功了。可是如果是这样,那么网关的配置信息就变成要写死配置在v2ray的配置文件里了,那么岂不是很不方便,很不灵活?有没有什么解决方案??

eycorsican commented 5 years ago

看上面链接文件中的完整说明,但那种方法转发效率不高,而且也没什么本质变化

tony1016 commented 5 years ago

我的意思是v2ray的config中的这一行:

"sendThrough": "172.31.82.73",

这就变成在每个网络环境都要更改这一行。如果是是命令行参数,那还可以做到自动化,但是在配置文件中时,就不太好做了

eycorsican commented 5 years ago

明白你意思,按说明来配置,不需要在v2配置文件里做任何额外修改

pharra commented 5 years ago

windows没法用-ifscope en0命令,有什么替代方案吗

eycorsican commented 5 years ago

重点在于添加两条默认路由且到TUN的那条有较高优先级,windows可以直接添加多条默认路由,用metric参数设置优先级

pharra commented 5 years ago

重点在于添加两条默认路由且到TUN的那条有较高优先级,windows可以直接添加多条默认路由,用metric参数设置优先级

配置两条默认路由和sendThrough后,匹配direct规则的网站还是无法成功,看log好像还是死循环了