Clash 订阅配置教程
安装 Clash
确保你已经安装了 Clash,你可以通过以下命令安装 Clash(在 macOS 或 Linux 上):
curl -L https://github.com/yuuki/Clash/releases/download/vX.YZ/Clash-App-OSX.pkg | open -a Clash-App.pkg
将 X.YZ 替换为最新的版本号。
创建配置文件
Clash 的配置文件通常位于 ~/.clash/config.json,如果该文件不存在,可以创建一个新文件。
touch ~/.clash/config.json
配置订阅
在 config.json 文件中,添加一个订阅配置,以下是一个示例配置:
{
"proxies": [
{
"name": "VPN1",
"url": "http://example.com:1234",
"username": "user",
"password": "password"
},
{
"name": "VPN2",
"url": "http://example2.com:1234",
"username": "user2",
"password": "password2"
}
]
}
name:配置的名称(可选)。url:代理的地址和端口。username:代理账号的用户名。password:代理账号的密码。
添加配置
将配置文件添加到 Clash 中,你可以通过命令行或 GUI 来添加配置。
-
命令行:
clash -x add config.json
-
GUI: 打开 Clash 应用,点击右上角的加号(+),然后选择“添加配置文件”。
使用订阅配置
你已经添加了订阅配置,Clash 会自动根据配置创建代理规则,当你选择 VPN1 时,Clash 会使用 http://example.com:1234 作为代理服务器。
管理多个配置文件
你可以为不同的网络环境创建多个配置文件,一个用于工作,一个用于家用。
-
创建新的配置文件
config2.json:{ "proxies": [ { "name": "VPN3", "url": "http://example3.com:1234", "username": "user3", "password": "password3" } ] } -
将
config2.json添加到 Clash 中:clash -x add config2.json
使用不同的配置
当你切换到不同的网络环境时,可以使用 clash -x use 命令切换到不同的配置文件。
- 切换到
config2.json:clash -x use config2.json
示例:自动化配置
你可以通过脚本自动化配置,使用 curl 命令下载最新的代理地址,并写入配置文件。
curl -o config.json https://example.com/proxy-list.json clash -x update
注意事项
- 文件路径:确保配置文件位于正确的路径(
~/.clash)。 - 权限:确保配置文件和目录有正确的权限(
~/.clash可能需要 root 权限)。 - 常见错误:如果配置文件格式错误,Clash 会提示错误信息,检查括号、逗号和引号是否正确。
通过以上步骤,你可以轻松配置 Clash 来管理多个订阅或自定义代理配置,Clash 的灵活性和扩展性使其成为处理复杂网络环境的强大工具。




