Clash 是一个基于规则的网络防火墙,用户可以通过它来管理网络流量、限制访问、过滤广告、保护隐私等。以下是 Clash 的安装和使用指南
Clash 安装指南
下载 Clash
Clash 提供了多种安装方式,包括通过官方网站、源代码编译、第三方包管理器等,以下是几种常见的安装方法:
-
通过官方网站:
- 访问 Clash 官方网站。
- 下载最新版本的
.zip或.tar.gz文件。
-
通过包管理器:
- Linux:
- 使用
apt或yum安装。 - 安装 Clash 过方便的包管理器:
# 安装 Clash 的包管理器 curl -fsSL https://raw.githubusercontent.com/Clash-Project/Clash/master/bootstrap.sh | bash
- 使用
- Mac:
- 使用 Homebrew:
brew install clash
- 使用 Homebrew:
- Windows:
使用 WSL 环境,可以使用包管理器安装。
- Linux:
-
源代码编译:
- 克隆源代码:
git clone https://github.com/Clash-Project/Clash.git
- 编译并安装:
cd Clash make sudo make install
- 克隆源代码:
启动 Clash
-
通过包管理器:
- Linux:
clash
- Mac:
brew services start clash
- Windows:
打开 WSL 界面,运行
clash。
- Linux:
-
通过源代码:
- 在编译好的目录中:
./clash
- 在编译好的目录中:
配置 Clash
Clash 的配置文件位于 ~/.clash/config.json,用户可以通过编辑这个文件来定制规则。
-
基本配置:
{ "port": 789, "log_level": "info", "max_connections": 100, "flush_interval": 15, "block_interval": 5, "listen": "...:789" } -
规则配置: Clash 使用 JSON 格式的规则文件,位于
~/.clash/rules.json。 以下是一个简单的例子:[ { "label": "允许所有网站", "uri": "**", "allowed": true, "position": 1 }, { "label": "允许特定网站", "uri": "www.example.com", "allowed": true, "position": 2 }, { "label": "阻止特定网站", "uri": "www.blocked-site.com", "allowed": false, "position": 3 } ] -
网站过滤: 在
rules.json中添加以下内容,可以过滤特定网站:{ "label": "过滤广告和不良网站", "uri": "ads.example.com", "allowed": false, "position": 1 } -
时间限制: 如果需要限制某些网站的访问时间,可以在
rules.json中添加时间规则:{ "label": "限制某个网站的访问时间", "uri": "www.example.com", "allowed": true, "position": 1, "time": { "start": "08:00", "end": "18:00" } } -
高级配置: Clash 支持插件和脚本,可以进一步定制功能,使用脚本来自动化规则管理:
# 示例脚本 echo '{"rule": {"uri": "www.example.com", "allowed": true}}' > /path/to/rules.json
使用 Clash
-
通过命令行:
- 查看现有的规则:
clash list
- 添加新的规则:
clash add rule uri:www.example.com allowed:true
- 删除规则:
clash remove rule uri:www.example.com
- 查看现有的规则:
-
通过 GUI: Clash 提供了一个简单的图形界面,可以通过浏览器访问
http://localhost:789。
常见问题
-
权限问题:
- 如果在 Linux 上运行,确保 Clash 有足够的权限:
sudo clash
- 如果在 Linux 上运行,确保 Clash 有足够的权限:
-
规则未生效:
- 检查规则是否正确添加并生效。
- 查看日志:
clash logs
-
端口冲突:
- 如果其他程序占用了
789端口,尝试更改默认端口:"listen": "...:7891"
- 如果其他程序占用了
Clash 的高级配置
-
脚本自动化:
- 使用脚本批量添加或修改规则。
- 示例脚本:
echo '{"rule": {"uri": "www.example.com", "allowed": true}}' > /path/to/rules.json
-
API 集成:
Clash 提供 REST API,可以通过 API 来管理规则和状态。

如果没有特点说明,本站所有内容均由原子加速器官方网站|提供客户端版本、线路管理与节点选择功能,适配Windows、Android、iOS等设备,便于用户进行网络连接优化原创,转载请注明出处!