分享一份个人的 clash meta 的配置,主打一个能用就行,总共不到100行,支持多订阅,无需订阅转换,无需GUI客户端,改写自官方文档的快捷配置 。
配置
监听端口:用 listeners
而不是 mixed-port
,因为可以添加其它端口。
WebUI:替代GUI客户端用于切换节点,这里使用的是 yacd ,手动下载压缩包并解压到 external-ui
文件夹。
geox:规则集合,比 rule-providers
更简洁。第一次启动可能需要手动下载dat文件。
dns:这部分也是最简单的配置,论坛里有很多帖子分享了详细配置,可以参考他们的,这里就不展开了。
proxy-providers :代理集合,这部分填写自己的订阅链接。模板里给了两个示例,是论坛里的热心老哥分享的, https://linux.do/t/topic/162639 , https://linux.do/t/topic/163475 ,需要把 url 复制过来。
proxy-groups:代理分组,PROXY分组可以选择Auto自动和Select手动,通过include-all-providers
引用所有代理集合里的节点;还有一个AI分组,用正则表达式筛选出所有非香港节点。
rules:规则部分,同样是极简配置,主要使用geosite和geoip,比如openai相关网站走AI分组的节点。想要添加其他网站的规则可以在 MetaCubeX/meta-rules-dat 搜索文件,也可以自己添加 rule-providers
。
完整配置:
config.yaml
mode: rule
log-level: info
ipv6: false
## WebUI,访问: http://{external-controller}/ui/
## 手动下载并解压到 {external-ui} ,或者:
## curl.exe http://{external-controller}/upgrade/ui -X POST -H 'Authorization: Bearer {secret}'
external-controller: 127.0.0.1:9090
secret: "123456"
external-ui: ./ui
external-ui-url: "https://github.com/haishanh/yacd/archive/gh-pages.zip"
keep-alive-interval: 3600
unified-delay: true
## 可能需要手动下载一次
geo-auto-update: true
geo-update-interval: 24
geodata-mode: true
geox-url:
geo-ip: "https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geoip.dat"
geosite: "https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geosite.dat"
listeners:
- name: mixed-1
type: mixed
listen: 127.0.0.1
port: 7890
dns:
enable: true
ipv6: false
enhanced-mode: fake-ip
fake-ip-range: 198.18.0.1/16
fake-ip-filter:
- "*"
- "+.lan"
- "+.local"
nameserver:
- 223.5.5.5
- 8.8.8.8
proxy-provider: &proxy-provider
type: http
proxy: Select
interval: 86400
health-check:
enable: true
interval: 600
url: https://www.gstatic.com/generate_204
proxy-providers:
linux.do.162639:
<<: *proxy-provider
path: ./subscribe/linux.do.162639.yaml
url: "https://dy.shihuijeidian.xyz/api/v1/client/subscribe?token=d32e6f96255728f5d5fdccf6162a03f6"
linux.do.163475:
<<: *proxy-provider
path: ./subscribe/linux.do.163475.yaml
url: "https://591haoka.com/wmapma"
override:
additional-prefix: "linux.do.163475 | "
proxy-groups:
- name: PROXY
type: select
proxies:
- Auto
- Select
- name: Select
type: select
include-all-providers: true
- name: Auto
type: url-test
include-all-providers: true
- name: AI
type: select
include-all-providers: true
exclude-filter: "(?i)港|HK"
rules:
- GEOSITE,meta,AI
- GEOSITE,openai,AI
- GEOSITE,anthropic,AI
- GEOSITE,bing,AI
- GEOSITE,github,PROXY
- GEOSITE,microsoft,DIRECT
- GEOSITE,private,DIRECT
- GEOSITE,cn,DIRECT
- GEOIP,lan,DIRECT,no-resolve
- GEOIP,cn,DIRECT,no-resolve
- MATCH,PROXY
开机启动和日志
linux
ubuntu 和 archlinux 都有 systemd 管理服务。
/etc/systemd/system/clash.service
[Unit]
Description=Clash, A rule-based proxy in Go.
After=network.target
[Service]
Type=simple
Restart=always
ExecStart=/usr/local/bin/clash -d /etc/clash
[Install]
WantedBy=multi-user.target
启停服务和查看日志:
systemctl enable clash
systemctl start clash
systemctl stop clash
journalctl --since "1 minute ago" -u clash
windows
windows 上没找到特别好用的服务管理软件, winsw 差强人意。
下载 winsw 并重命名为 clash-service.exe
,配置 clash-service.xml
:
clash-service.xml
<service>
<id>clash</id>
<name>clash</name>
<description>A rule-based tunnel in Go.</description>
<executable>clash.exe</executable>
<arguments>-d .</arguments>
<poststart>
<executable>powershell.exe</executable>
<arguments>-NoProfile -File system-proxy.ps1 up 127.0.0.1 7890</arguments>
<stdoutPath>logs\start.out.log</stdoutPath>
<stderrPath>logs\start.err.log</stderrPath>
</poststart>
<poststop>
<executable>powershell.exe</executable>
<arguments>-NoProfile -File system-proxy.ps1 down</arguments>
<stdoutPath>logs\stop.out.log</stdoutPath>
<stderrPath>logs\stop.err.log</stderrPath>
</poststop>
<log mode="roll-by-size"></log>
<logpath>logs</logpath>
</service>
自动开关系统代理的脚本 system-proxy.ps1
:
system-proxy.ps1
Param(
[Parameter(Mandatory = $false, Position = 0)]
[ValidateSet('up', 'down', 'status')]
$command,
[Parameter(Mandatory = $false, Position = 1)]
$server,
[Parameter(Mandatory = $false, Position = 2)]
$port
)
Write-Output "$(Get-Date)"
# access current user' settings from Local System Account
# FIXME: sometimes got null sid
$domain, $userName = (Get-WmiObject -Class Win32_ComputerSystem).UserName -split '\\', 2
$user = [System.Security.Principal.NTAccount]::new($domain, $userName)
Write-Output "$($user.Value)"
$sid = $user.Translate([System.Security.Principal.SecurityIdentifier]).Value
$path = "Registry::HKEY_USERS\$sid\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
switch ($command) {
'up' {
if ($server -ne $null -and $port -ne $null) {
Set-ItemProperty -Path $path -name ProxyServer -Value "$($server):$($port)"
}
Set-ItemProperty -Path $path -name ProxyEnable -Value 1
}
'down' {
# Set-ItemProperty -Path $path -name ProxyServer -Value ""
Set-ItemProperty -Path $path -name ProxyEnable -Value 0
}
}
Get-ItemProperty -Path $path | Select-Object ProxyEnable, ProxyServer | Write-Output
启停服务:
clash-service.exe install
clash-service.exe start
clash-service.exe stop
<<<<<<
有用的话记得点个赞啊!