mellow-io/mellow

请教一下如何配合其他代理软件一起使用

njzydark opened this issue · 19 comments

我想将mellow配合clashx一起使用。clashx本地socks端口为1088。由于clashx目前没有tun,所以我想配合mellow一起使用,从而实现透明代理。请教一下配置文件如何配置。

这是我目前的配置文件:

{
  "log": {
    "loglevel": "info"
  },
  "inbounds": [
    {
      "port": 1080,
      "protocol": "socks",
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ]
      },
      "settings": {
        "auth": "noauth"
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "socks",
      "settings": {
        "servers": [
          {
            "address": "127.0.0.1",
            "port": 1088
          }
        ]
      },
      "tag": "clashx"
    },
    {
      "protocol": "freedom",
      "settings": {
        "domainStrategy": "UseIP"
      },
      "tag": "direct"
    }
  ],
  "routing": {
    "domainStrategy": "IPIfNonMatch",
    "rules": [
      {
        "app": [
          "ClashX"
        ],
        "type": "field",
        "outboundTag": "direct"
      }
    ]
  }
}

inbound 可以删去,app 里应该要写 clash,clashX 只是个 wrapper,正真发网络数据的进程猜是叫 clash,你可以打开 statistics 确认下

inbound 可以删去,app 里应该要写 clash,clashX 只是个 wrapper,正真发网络数据的进程猜是叫 clash,你可以打开 statistics 确认下

inbound我删了,app里我加了clash clashx ClashX ,启动之后没网,这是启动日志:

[2019-08-11 11:12:00.927] [info] Checking helper files.
[2019-08-11 11:12:01.186] [info] Original gateway is 192.168.0.1
[2019-08-11 11:12:01.186] [info] Original send through 192.168.0.124 en0
[2019-08-11 11:12:01.190] [info] Core started.
[2019-08-11 11:12:01.196] [info] The default gateway before configuring routes:
[2019-08-11 11:12:01.196] [info] { gateway: '192.168.0.1', interface: 'en0' }
[2019-08-11 11:12:01.197] [info] The TUN interface before configuring routes:
[2019-08-11 11:12:01.197] [info] { address: '10.255.0.2', interface: 'utun1' }
[2019-08-11 11:12:01.221] [info] Set 10.255.0.1 as the default gateway.
[2019-08-11 11:12:01.224] [info] 2019/08/11 11:12:01 [Warning] v2ray.com/core: V2Ray 4.19.1 started

[2019-08-11 11:12:01.225] [info] 2019/08/11 11:12:01 Restoring Fake DNS records from cache...
2019/08/11 11:12:01 Start session stater.
2019/08/11 11:12:01 Relay ICMP packets.
2019/08/11 11:12:01 Running tun2socks

inbound不删的话,虽然没网,但是启动日志是这样的:

2019-08-11 11:15:41.608] [info] 2019/08/11 11:15:41 [Info] [2104202606] v2ray.com/core/app/dispatcher: default route for tcp:91.108.56.140:443
2019/08/11 11:15:41 [Info] [2104202606] v2ray.com/core/transport/internet/tcp: dialing TCP to tcp:127.0.0.1:1088
2019/08/11 11:15:41 [Info] [496648811] v2ray.com/core/app/dispatcher: default route for tcp:91.108.56.140:443
2019/08/11 11:15:41 [Info] [496648811] v2ray.com/core/transport/internet/tcp: dialing TCP to tcp:127.0.0.1:1088
2019/08/11 11:15:41 [] tcp:127.0.0.1:53910 accepted [clashx] tcp:91.108.56.140:5222 
2019/08/11 11:15:41 [] tcp:127.0.0.1:53908 accepted [clashx] tcp:91.108.56.140:443 
2019/08/11 11:15:41 [] tcp:127.0.0.1:53907 accepted [clashx] tcp:91.108.56.140:443 

[2019-08-11 11:23:59.486] [info] 2019/08/11 11:23:59 [Info] [4031550129] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/socks: connection ends > read tcp 192.168.0.124:55572->127.0.0.1:1088: read: connection reset by peer
2019/08/11 11:23:59 [Info] [3858689277] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/socks: connection ends > read tcp 192.168.0.124:55574->127.0.0.1:1088: read: connection reset by peer

[2019-08-11 11:23:59.487] [info] 2019/08/11 11:23:59 [Info] [3858689277] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/socks: connection ends > v2ray.com/core/proxy/socks: failed to transport all TCP response > io: read/write on closed pipe
2019/08/11 11:23:59 [Info] [4031550129] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/socks: connection ends > v2ray.com/core/proxy/socks: failed to transport all TCP response > io: read/write on closed pipe
2019/08/11 11:23:59 [Info] [647073132] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/socks: connection ends > read tcp 192.168.0.124:55573->127.0.0.1:1088: read: connection reset by peer
2019/08/11 11:23:59 [Info] [647073132] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/socks: connection ends > v2ray.com/core/proxy/socks: failed to transport all TCP response > io: read/write on closed pipe

我不熟悉 clash,你可以试下从最简单的配置开始,先用 go-shadowsocks2 来代替 clashX:

go-shadowsocks2 -socks 127.0.0.1:1088 -u -c server.com:10086 -password password -verbose
{
    "outbounds": [
        {
            "protocol": "socks",
            "settings": {
                "servers": [
                    {
                        "address": "127.0.0.1",
                        "port": 1088
                    }
                ]
            }
        },
        {
            "protocol": "freedom",
            "settings": {
                "domainStrategy": "UseIP"
            },
            "tag": "direct"
        }
    ],
    "routing": {
        "domainStrategy": "IPIfNonMatch",
        "rules": [
            {
                "app": [
                    "*shadowsocks*"
                ],
                "type": "field",
                "outboundTag": "direct"
            }
        ]
    }
}

这样配合 go-shadowsocks2 我测试过是可以的。

你也可以打开 Statistics 看看有没什么不正常的请求,比如有可能 mDNSResponder 所发出的 DNS 请求造成环路,你也可以把它加到 app 里。

我不熟悉 clash,你可以试下从最简单的配置开始,先用 go-shadowsocks2 来代替 clashX:

go-shadowsocks2 -socks 127.0.0.1:1088 -u -c server.com:10086 -password password -verbose
{
    "outbounds": [
        {
            "protocol": "socks",
            "settings": {
                "servers": [
                    {
                        "address": "127.0.0.1",
                        "port": 1088
                    }
                ]
            }
        },
        {
            "protocol": "freedom",
            "settings": {
                "domainStrategy": "UseIP"
            },
            "tag": "direct"
        }
    ],
    "routing": {
        "domainStrategy": "IPIfNonMatch",
        "rules": [
            {
                "app": [
                    "*shadowsocks*"
                ],
                "type": "field",
                "outboundTag": "direct"
            }
        ]
    }
}

这样配合 go-shadowsocks2 我测试过是可以的。

你也可以打开 Statistics 看看有没什么不正常的请求,比如有可能 mDNSResponder 所发出的 DNS 请求造成环路,你也可以把它加到 app 里。

go-shadowsocks2 我试了 shadowsocks-ng我也试了 单独用没问题 只要一开mellow就没网 mellow日志就只有启动信息 大佬你多开几个标签页试试 我刷百度没问题 刷其他网站就打不开

  1. 版本信息
  2. 日志,所有相关 app 的日志
  3. 配置,系统代理,系统 DNS,路由表,statistics 里的信息

你多开几个标签页试试

开多少个标签都没问题

@0njzy0 想起个事情,你用 go-shadowsocks2 时,得自己拿 master 去编译,它有个 SOCKS UDP 的修复它没有发布出来:shadowsocks/go-shadowsocks2#140

我没用mellow 直接用你的go-tun2socks 执行这个脚本 是没问题的
现在就是不知道怎么用mellow实现 我之前是fork了一份 直接改的启动参数

#!/bin/bash

default_gw=$(networksetup -getinfo Wi-Fi | grep '^Router' | awk '{print $2}')
gw="250.0.200.1"
ip=$(ipconfig getifaddr en0)
app_name="go-shadowsocks2"
propxy_type="d"
proxy_server="127.0.0.1:1080"
flag="uninstall"

pkill -f tun2socks

if [[ ${1} == ${flag} ]]; then
	sudo route delete default
	sudo route delete default ${default_gw} -ifscope en0
	sudo route add default ${default_gw}
	exit
fi

config_route() {
	sudo route delete default
	sudo route add default ${default_gw} -ifscope en0
	sudo route add default ${gw}
}

config_route&
if [[ ${1} != ${flag} ]]; then
	sudo tun2socks -tunGw ${gw} -proxyType ${propxy_type} -proxyServer ${proxy_server} -exceptionSendThrough ${ip}:0 -exceptionApps ${app_name} -loglevel info
fi
  1. 版本信息
  2. 日志,所有相关 app 的日志
  3. 配置,系统代理,系统 DNS,路由表,statistics 里的信息

版本信息

  • macOS 10.14.6
  • Mellow 0.0.5
  • go-shadowsocks2 master编译

cfg.json

{
  "outbounds": [
    {
      "protocol": "socks",
      "settings": {
        "servers": [
          {
            "address": "127.0.0.1",
            "port": 1088
          }
        ]
      }
    },
    {
      "protocol": "freedom",
      "settings": {
        "domainStrategy": "UseIP"
      },
      "tag": "direct"
    }
  ],
  "routing": {
    "domainStrategy": "IPIfNonMatch",
    "rules": [
      {
        "app": [
          "*shadowsocks*"
        ],
        "type": "field",
        "outboundTag": "direct"
      }
    ]
  }
}

Mellow日志

[2019-08-11 15:00:00.721] [info] Checking helper files.
[2019-08-11 15:00:00.982] [info] Original gateway is 192.168.0.1
[2019-08-11 15:00:00.982] [info] Original send through 192.168.0.124 en0
[2019-08-11 15:00:00.992] [info] Core started.
[2019-08-11 15:00:00.998] [info] The default gateway before configuring routes:
[2019-08-11 15:00:01.001] [info] { gateway: '192.168.0.1', interface: 'en0' }
[2019-08-11 15:00:01.002] [info] The TUN interface before configuring routes:
[2019-08-11 15:00:01.002] [info] { address: '10.255.0.2', interface: 'utun1' }
[2019-08-11 15:00:01.024] [info] Set 10.255.0.1 as the default gateway.
[2019-08-11 15:00:01.032] [info] 2019/08/11 15:00:01 Restoring Fake DNS records from cache...

[2019-08-11 15:00:01.032] [info] 2019/08/11 15:00:01 Start session stater.

[2019-08-11 15:00:01.037] [info] 2019/08/11 15:00:01 Relay ICMP packets.

[2019-08-11 15:00:01.042] [info] 2019/08/11 15:00:01 Running tun2socks

[2019-08-11 15:00:01.043] [info] 2019/08/11 15:00:01 [Warning] v2ray.com/core: V2Ray 4.19.1 started

路由表

Destination        Gateway            Flags        Refs      Use   Netif Expire
default            10.255.0.1         UGSc          144        1   utun1
default            192.168.0.1        UGScI           4        0     en0
10.255.0.1         10.255.0.2         UH              0        0   utun2
127                127.0.0.1          UCS             0        0     lo0
127.0.0.1          127.0.0.1          UH           2042 105973550     lo0
169.254            link#14            UCS             2        0     en0      !
192.168.0          link#14            UCS             4        0     en0      !
192.168.0.1/32     link#14            UCS             1        0     en0      !
192.168.0.1        b0:95:8e:91:fe:24  UHLWIir        11      489     en0   1196
192.168.0.101      10:c7:53:b:7:57    UHLWI           0        1     en0    550
192.168.0.103      60:6b:ff:b4:84:fa  UHLWI           0        0     en0      !
192.168.0.113      a0:d3:7a:44:b7:8b  UHLWI           0       77     en0   1156
192.168.0.124/32   link#14            UCS             1        0     en0      !
192.168.0.124      f0:18:98:4f:a8:5c  UHLWI           0     1196     lo0
192.168.0.255      ff:ff:ff:ff:ff:ff  UHLWbI          0        3     en0      !
224.0.0/4          link#14            UmCS            2        0     en0      !
224.0.0.251        1:0:5e:0:0:fb      UHmLWI          0        0     en0
239.255.255.250    1:0:5e:7f:ff:fa    UHmLWI          0      208     en0
255.255.255.255/32 link#14            UCS             0        0     en0      !

statistics没有任何信息,dns系统默认,系统代理:127.0.0.1:1088

很神奇 我多次关闭mellow重新打开 竟然可以了 啥也没改

mellow日志

[2019-08-11 15:08:59.858] [info] 2019/08/11 15:08:59 [] [tcp] [go-shadowsocks2] tcp:112.74.49.246:17786
2019/08/11 15:08:59 [] [tcp] [go-shadowsocks2] tcp:112.74.49.246:17786

[2019-08-11 15:08:59.858] [info] 2019/08/11 15:08:59 [] [tcp] [go-shadowsocks2] tcp:112.74.49.246:17786

[2019-08-11 15:08:59.859] [info] 2019/08/11 15:08:59 [] [tcp] [go-shadowsocks2] tcp:112.74.49.246:17786
2019/08/11 15:08:59 [] [tcp] [go-shadowsocks2] tcp:112.74.49.246:17786
2019/08/11 15:08:59 [] [tcp] [go-shadowsocks2] tcp:112.74.49.246:17786

[2019-08-11 15:09:00.056] [info] 2019/08/11 15:09:00 [] [tcp] [go-shadowsocks2] tcp:112.74.49.246:17786

路由表

default            10.255.0.1         UGSc           79        2   utun2
default            192.168.0.1        UGScI           5        0     en0
10.255.0.1         10.255.0.2         UHr             4        0   utun2
127                127.0.0.1          UCS             0        0     lo0
127.0.0.1          127.0.0.1          UH           2114 105980406     lo0
169.254            link#14            UCS             2        0     en0      !
192.168.0          link#14            UCS             3        0     en0      !
192.168.0.1/32     link#14            UCS             1        0     en0      !
192.168.0.1        b0:95:8e:91:fe:24  UHLWIir        12      541     en0   1186
192.168.0.101      10:c7:53:b:7:57    UHLWI           0        1     en0    134
192.168.0.103      60:6b:ff:b4:84:fa  UHLWI           0        0     en0   1156
192.168.0.113      a0:d3:7a:44:b7:8b  UHLWIi          1       97     en0   1151
192.168.0.124/32   link#14            UCS             1        0     en0      !
192.168.0.124      f0:18:98:4f:a8:5c  UHLWIi          2     1491     lo0
224.0.0/4          link#14            UmCS            2        0     en0      !
224.0.0.251        1:0:5e:0:0:fb      UHmLWI          0        0     en0
239.255.255.250    1:0:5e:7f:ff:fa    UHmLWI          0      220     en0
255.255.255.255/32 link#14            UCS             0        0     en0      !

wow 发现问题了

第一次开启mellow 路由表是这样的 一个是utun1 一个是utun2

default            10.255.0.1         UGSc          144        1   utun1
default            192.168.0.1        UGScI           4        0     en0
10.255.0.1         10.255.0.2         UH              0        0   utun2

在stop之后再次start 路由表是这样的 都是utun2 此时网络正常

default            10.255.0.1         UGSc           79        2   utun2
default            192.168.0.1        UGScI           5        0     en0
10.255.0.1         10.255.0.2         UHr             4        0   utun2

跟其它也用 TUN 的软件冲突了吗?ifconfig 看一看?

跟其它也用 TUN 的软件冲突了吗?ifconfig 看一看?

嗯 除了utun0外确实还有一个 重启解决了 感谢大佬的耐心指导 谢谢!

截屏2019-10-20下午1 20 17

clash里链接用的节点
截屏2019-10-20下午1 44 06

@eycorsican

我用了和 @0njzy0 一样的配置,但发现clash链接远端的请求被dispatcher解析为混淆的域名。导致连接失败。

clash直连的没问题

出口连接没绑定 laddr 吗?

net.DialTCP("tcp", laddr, raddr)

我理解任何 socks5 客户端,只要配置了 laddr ,都可以配合 go-tun2socks 之类使用的;
要是不指定 laddr ,系统会自动选择路由,结果是流量又回到 tun 那里,出现死循环;

我没用mellow 直接用你的go-tun2socks 执行这个脚本 是没问题的
现在就是不知道怎么用mellow实现 我之前是fork了一份 直接改的启动参数

#!/bin/bash

default_gw=$(networksetup -getinfo Wi-Fi | grep '^Router' | awk '{print $2}')
gw="250.0.200.1"
ip=$(ipconfig getifaddr en0)
app_name="go-shadowsocks2"
propxy_type="d"
proxy_server="127.0.0.1:1080"
flag="uninstall"

pkill -f tun2socks

if [[ ${1} == ${flag} ]]; then
	sudo route delete default
	sudo route delete default ${default_gw} -ifscope en0
	sudo route add default ${default_gw}
	exit
fi

config_route() {
	sudo route delete default
	sudo route add default ${default_gw} -ifscope en0
	sudo route add default ${gw}
}

config_route&
if [[ ${1} != ${flag} ]]; then
	sudo tun2socks -tunGw ${gw} -proxyType ${propxy_type} -proxyServer ${proxy_server} -exceptionSendThrough ${ip}:0 -exceptionApps ${app_name} -loglevel info
fi

@njzydark 这你修改参数后的tun2sock的代码方便分享一下吗?

我没用mellow 直接用你的go-tun2socks 执行这个脚本 是没问题的
现在就是不知道怎么用mellow实现 我之前是fork了一份 直接改的启动参数

#!/bin/bash

default_gw=$(networksetup -getinfo Wi-Fi | grep '^Router' | awk '{print $2}')
gw="250.0.200.1"
ip=$(ipconfig getifaddr en0)
app_name="go-shadowsocks2"
propxy_type="d"
proxy_server="127.0.0.1:1080"
flag="uninstall"

pkill -f tun2socks

if [[ ${1} == ${flag} ]]; then
	sudo route delete default
	sudo route delete default ${default_gw} -ifscope en0
	sudo route add default ${default_gw}
	exit
fi

config_route() {
	sudo route delete default
	sudo route add default ${default_gw} -ifscope en0
	sudo route add default ${gw}
}

config_route&
if [[ ${1} != ${flag} ]]; then
	sudo tun2socks -tunGw ${gw} -proxyType ${propxy_type} -proxyServer ${proxy_server} -exceptionSendThrough ${ip}:0 -exceptionApps ${app_name} -loglevel info
fi

@njzydark 这你修改参数后的tun2sock的代码方便分享一下吗?

根据这个 自行编译即可 https://github.com/eycorsican/go-tun2socks/blob/1b8c82f9a597c056ffdfc43fefe5d2f96e429f56/README.md#build