Featured image of post 『Blog』Use Hysteria through Clash.Meta in Android

『Blog』Use Hysteria through Clash.Meta in Android

通过 Clash Meta for Android 启动 Hysteria 代理核心

前言

本文涉及的开源项目:

项目名发行版本号用途
MetaCubeX/ClashMetaForAndroidv2.5.11-pre02图形化客户端
Loyalsoldier/clash-rules202208302241开源规则集

下文均以 CMFA 代称 Clash Meta for Android。

快速上手

下载 CMFA

推荐从 Releases 下载最新发行版软件。

通常,主流安卓手机使用带有 arm64-v8a 标签的 APK 文件。以你喜欢的方式在移动设备上安装 CMFA,不要点击多余的东西。

 Download CMFA release arm64-v8a.
Fig1. - Download CMFA release through GitHub.

导入配置文件

参考 文末附件 编写你的配置信息,导入移动设备。从 CMFA 应用主界面点击「配置」进入创建配置页面,导入配置文件,点击保存。

值得一提的是,目前 Hysteria 仍未被普及使用,你可能缺少一种合理的方式部署 URI 服务用于定时更新 Hysteria 配置信息。目前的最佳实践仍是通过配置文件导入相关数据,通过链接导入反而有订阅泄漏的风险。

Import rules file(yaml) of CMFA.
Fig2. - Import rules from external YAML file.
Waiting for external resources to load.
Fig3. - Waiting for rule-providers to load.
Select the (hysteria) configuration item.
Fig4. - Select the (hysteria) configuration item.

启动代理

返回 CMFA 应用主界面,点击「启动」即可。

Startup proxy.
Fig5. - Startup proxy.

黑名单访问控制模式

黑名单模式,意为「只有命中规则的网络流量,才使用代理」,这是一个大幅度提升网上冲浪体验的关键操作。在 Kotlin 系列的软件中,该选项还被称为「分应用代理」。

由于每个人的设备环境大相径庭,很难用一套模版覆盖所有环境,所以我们只说明操作方法以及注意事项,提供的 rules 仅供参考,你需要根据具体情况进一步调教。

关闭代理,从应用界面依次进入「设置 – 网络 」,将访问控制模式调整为「仅允许已选择的应用」,其他选项保持默认即可,具体内容如下所示:

 Access control mode of VpnService.
Fig6. - Access control mode of VpnService.

打开「访问控制应用包列表」,开始点选需要使用代理的应用软件。可供参考的应用包列表如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
com.azure.authenticator
com.android.chrome
com.discord
com.microsoft.office.excel
com.github.android
com.google.android.gm
com.google.ar.core
com.instagram.android
com.medium.reader
com.microsoft.office.officehubrow
com.picsart.studio
com.microsoft.office.powerpoint
com.reddit.frontpage
com.spotify.music
org.telegram.messenger
com.twitter.android
twittervideosaver.twittervideodownloader.twimate.savetwittergif
com.microsoft.office.word
com.google.android.youtube
photo.editor.photoeditor.photoeditorpro
com.google.earth
com.android.vending
com.google.android.gms
com.google.android.gsf

你可以在「访问控制应用包列表」中从外部(剪切板)导入以上内容,部分应用需要关闭包列表的系统应用过滤器才能看到。我们以上述内容为例阐述黑名单访问控制模式的最佳实践案例。

代理类备注
谷歌商店Google Play StoreGoogle Play 服务 以及 Google 服务框架
浏览器主用的浏览器,如 Google,Edge,Firefox,DuckGo 等,否则应用内的多种服务无法正常使用。
邮箱Gmail,Protonmail 等需要代理才能正常收发件的产品。
Authenticator用于二步验证或多因素验证的软件,若您使用的是国外产品(这类生态在国内不成熟),它们的云服务备份功能自然是需要通过代理的。
其他(1)各种需要代理的国外应用。如 YouTube,Twitter,Telegram,Instagram,Reddit,Spotify,Google Earth ,Microsoft Office 等人尽皆知的国外御三家应用;(2)Twitter、Instagram下载器(用于下载推文视频)之类的软件;(3)需要代理才能正常使用的游戏、流媒体及协作服务。

反模式警告,除非是特殊用途(比如装逼、连入公司内网、开发),否则你不应在任何情况下使用境外代理访问支付宝、微信、反炸中心、百度/高德地图、Bilibili、电商软件、抖音等知名国内御三家应用。

这种反模式的行为会不会带来意料之外的惊喜暂且不谈,就上网体验本身就非常糟糕,也许是出入公共场合地点码半分钟加载不出来,也许是 B站 的下饭体验极其恶劣,但无论如何,长期「异地登录人」的用户画像会给你今后的网上冲浪生活留下浓墨重彩的一笔。

附件

  1. 参考项目
  1. 配置文件

    根据注释修改配置信息

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
mixed-port: 7890
allow-lan: true
mode: rule
log-level: info
ipv6: true
dns:
  enable: true
  listen: 0.0.0.0:53
  ipv6: true
  default-nameserver:
    - 114.114.114.114
    - 223.5.5.5
  enhanced-mode: redir-host
  nameserver:
    - https://dns.alidns.com/dns-query
    - https://doh.pub/dns-query
  fallback:
    - 114.114.114.114
    - 223.5.5.5

# 编写 Hysteria 客户端的协商配置信息
proxies:
  - name: "CN2 GIA-E"
    type: hysteria
    server: # Hysteria 服务域名
    port: # Hysteria 服务端口
    auth_str: # 字符串校验密钥
    alpn: h3
    protocol: wechat-video # udp/wechat-video
    up: 25
    down: 125
    sni: # Hysteria 服务域名
    skip-cert-verify: false
    recv_window_conn: 12320768
    recv_window: 49283072
    disable_mtu_discovery: true

# 服务注册
# 将上文配置的 proxies-name 的值依次编排到下方的 proxies 列表中
proxy-groups:
  - name: "PROXY"
    type: select
    proxies:
     - "CN2 GIA-E" 

rule-providers:
  reject:
    type: http
    behavior: domain
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/reject.txt"
    path: ./ruleset/reject.yaml
    interval: 86400

  icloud:
    type: http
    behavior: domain
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/icloud.txt"
    path: ./ruleset/icloud.yaml
    interval: 86400

  apple:
    type: http
    behavior: domain
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/apple.txt"
    path: ./ruleset/apple.yaml
    interval: 86400

  proxy:
    type: http
    behavior: domain
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/proxy.txt"
    path: ./ruleset/proxy.yaml
    interval: 86400

  direct:
    type: http
    behavior: domain
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/direct.txt"
    path: ./ruleset/direct.yaml
    interval: 86400

  private:
    type: http
    behavior: domain
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/private.txt"
    path: ./ruleset/private.yaml
    interval: 86400

  gfw:
    type: http
    behavior: domain
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/gfw.txt"
    path: ./ruleset/gfw.yaml
    interval: 86400

  greatfire:
    type: http
    behavior: domain
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/greatfire.txt"
    path: ./ruleset/greatfire.yaml
    interval: 86400

  telegramcidr:
    type: http
    behavior: ipcidr
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/telegramcidr.txt"
    path: ./ruleset/telegramcidr.yaml
    interval: 86400

  cncidr:
    type: http
    behavior: ipcidr
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/cncidr.txt"
    path: ./ruleset/cncidr.yaml
    interval: 86400

  lancidr:
    type: http
    behavior: ipcidr
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/lancidr.txt"
    path: ./ruleset/lancidr.yaml
    interval: 86400

  applications:
    type: http
    behavior: classical
    url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/applications.txt"
    path: ./ruleset/applications.yaml
    interval: 86400

rules:
  - DOMAIN,clash.razord.top,DIRECT
  - DOMAIN,yacd.haishan.me,DIRECT
  - RULE-SET,proxy,PROXY
  - RULE-SET,telegramcidr,PROXY
  - RULE-SET,direct,DIRECT
  - RULE-SET,applications,DIRECT
  - RULE-SET,private,DIRECT
  - RULE-SET,icloud,DIRECT
  - RULE-SET,apple,DIRECT
  - RULE-SET,lancidr,DIRECT
  - RULE-SET,cncidr,DIRECT
  - RULE-SET,reject,RECEJT
  - GEOIP,LAN,DIRECT
  - GEOIP,CN,DIRECT
  - MATCH,PROXY
You will to enjoy grander sight / By climing to a greater height.