通过使用 tun 来实现透明代理。实现了类似 surge 增强模式与网关模式。
= Seeker
image::https://travis-ci.com/gfreezy/seeker.svg?branch=master[Build Status,link=https://travis-ci.com/gfreezy/seeker]
使用 Tun 实现 ss 透明代理(支持 Mac & Linux 系统),支持 TCP、UDP。
== Slack https://join.slack.com/t/allsunday/shared_invite/zt-f8xw3uzl-qchMa2jQOfQF1T89w3lfiw
== Download 访问 https://github.com/gfreezy/seeker/releases 下载最新 release
== Usage
seeker+ [source,bash] ---- Seeker 0.2.0 gfreezy [email protected] Tun to Shadowsockets proxy. https://github.com/gfreezy/seeker
USAGE: seeker [FLAGS] [OPTIONS]
FLAGS: --encrypt Encrypt config file and output to terminal -h, --help Prints help information -V, --version Prints version information
OPTIONS: -c, --config Sets config file. Sample config at https://github.com/gfreezy/seeker/blob/master/sampleconfig.yml --config-url <CONFIGURL> URL to config --key Key for encryption/decryption -l, --log Log file
+ 本地配置文件启动 +
+ 远程配置文件启动 +
+ 生成远程配置文件 +
seeker启动的时候会自动将本机 DNS 修改为
127.0.0.1,退出的时候将 DNS 设置为默认值
== Config
seeker直接使用的 clash 的规则。目前支持
DOMAIN
DOMAIN-KEYWORD
DOMAIN-SUFFIX
MATCH规则,不支持
IP相关的规则。
Action:
PROXY走代理
DIRECT直连
REJECT拒绝
PROBE默认尝试直连,如果超时,则走代理。由
direct_connect_timeout控制超时时间
tun_name
tun_ip和
tun_cidr与当前所处网络环境不在一个网段
seeker支持 socks5 代理、http 代理和 shadowsocks 代理。优先级为 socks5 代理 > shadowsocks 代理 > http 代理。
verbose: false dnsstartip: 10.0.0.10 dnsservers: - 223.5.5.5:53 - 114.114.114.114:53 - tcp://114.114.114.114:53 dnstimeout: 1s tunname: utun4 tunip: 10.0.0.1 tuncidr: 10.0.0.0/16 dnslisten: 0.0.0.0:53 gatewaymode: true pingtimeout: 2s probetimeout: 30ms # probetimeout 时间内如果 TCP 可以直接连接,则直连;否则走代理 connecttimeout: 1s readtimeout: 30s writetimeout: 5s maxconnect_errors: 2 # ss 服务器重试次数,到达重试次数后会自动选择下一个最快的服务器
servers: - name: socks5 proxy server addr: domain-or-ip-to-socks5-server:port protocol: Socks5 # Https or Http or Socks5 or Shadowsocks
name: http proxy server addr: domain-or-ip-to-socks5-server:port username: username password: pass protocol: Https # Https or Http or Socks5 or Shadowsocks
name: https proxy server addr: domain-or-ip-to-socks5-server:port username: username password: pass protocol: Https # Https or Http or Socks5 or Shadowsocks
name: server1 addr: domain-or-ip-to-ss-server:port method: chacha20-ietf password: password protocol: Shadowsocks
name: server2 addr: domain-or-ip-to-ss-server:port method: chacha20-ietf password: password protocol: Shadowsocks
rules: - 'DOMAIN,audio-ssl.itunes.apple.com,DIRECT' - 'DOMAIN,gspe1-ssl.ls.apple.com,REJECT' - 'DOMAIN-SUFFIX,aaplimg.com,DIRECT' - 'DOMAIN-SUFFIX,apple.co,DIRECT' - 'DOMAIN-KEYWORD,bbcfmt,PROXY' - 'DOMAIN-KEYWORD,uk-live,PROXY' - 'DOMAIN-SUFFIX,snssdk.com,DIRECT' - 'DOMAIN-SUFFIX,toutiao.com,PROBE'
== ⚠️使用 Socks5 或 http 代理服务器 使用 socks5 代理的时候,需要将所有直连的域名设置在配置文件里面,如果使用 ss 或者 vmess 之类的,需要将 ss 或 vmess server 的域名也加入配置文件。否则有可能会导致死循环,没法正常使用。
⚠️ http 代理只支持
CONNECT协议,而且不支持 UDP 协议。
== 指定 IP 或某网段走代理 修改路由表,将希望走代理的 IP 或者网段路由到虚拟网卡。如果使用了本机 socks5 代理,则必须确保 socks5 不会直连加入路由表的网段,否则会死循环。
比如我希望
8.8.8.8这个 IP 所有流量都走代理,且使用本地 ClashX 创建的 socks5 代理:
将
8.8.8.8路由到 utun4 +
修改 clashx 的规则,增加下面一条 +
== 代理局域网内其他机器 1. 打开
gateway_mode。
gateway_mode开启后,
dns_server会自动覆盖为
0.0.0.0:53+
查看本地 IP +
打开希望走代理的手机或者电脑的网络设置,将 DNS 与 网关 修改为步骤2获取到的 IP
== 重置 DNS 分配
== FAQ . If you encountered
"seeker" cannot be opened because the developer cannot be verified., you can go to
System Preferences->
Security & Privacy->
Generaland enable any blocked app from Allow apps downloaded from pane at the bottom of the window.
. Ubuntu 提示
Address already used, 查看这里 https://unix.stackexchange.com/questions/304050/how-to-avoid-conflicts-between-dnsmasq-and-systemd-resolved
== Build (rust >= 1.39)
git clone https://github.com/gfreezy/seeker.git cd seeker
编译完成后,程序在
target/release/seeker。
=== musl 编译
会在
target/x86_64-unknown-linux-musl/release目录下生成
seeker文件。
== 实现原理
seeker参考了
Surge for Mac的实现原理,基本如下:
.
seeker会在本地启动一个 DNS server,并自动将本机 DNS 修改为
seeker的 DNS 服务器地址 .
seeker会创建一个 TUN 设备,并将 IP 设置为
10.0.0.1,系统路由表设置
10.0.0.0/16网段都路由到 TUN 设备 . 有应用请求 DNS 的时候,
seeker会为这个域名返回
10.0.0.0/16网段内一个唯一的 IP .
seeker从 TUN 接受到 IP 包后,会在内部组装成 TCP/UDP 数据 .
seeker会根据规则和网络连接的 uid 判断走代理还是直连 . 如果需要走代理,将 TCP/UDP 数据转发到 SS 服务器/ socks5 代理,从代理接受到数据后,在返回给应用;如果直连,则本地建立直接将数据发送到目标地址
== 使用限制
只有通过域名访问网络的应用可以被代理。如果某个应用直接使用 IP 访问网络,则
seeker对这类应用无效。
== License
Licensed under either of
at your option.
== Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.