使用 Homebrew 安装 macOS)

安装 Clash

确保你的环境支持 Clash 的安装。

方法 1: 使用包管理器安装

# 使用 Docker 安装
docker pull clash

方法 2: 从源代码安装

下载最新版本的 Clash 源代码并编译:

# 克隆仓库
git clone https://github.com/zserge/Clash.git
# 进入目录
cd Clash
# 编译
make

启动 Clash

# 启动 Clash
./clash -start

配置基本代理

在 Clash 启动后,打开浏览器访问 http://localhost:789,进入 Clash 的控制面板。

  1. 基本设置

    • Listen Address: 指定 Clash监听的地址,默认为 ...:789
    • Listen Port: 代理监听的端口,默认为 789
  2. HTTP/HTTPS代理

    • HTTP Port: HTTP代理端口,默认为 7891
    • HTTPS Port: HTTPS代理端口,默认为 7892
  3. 设置代理服务器

    • TCP/HTTP代理
      {
        "outbound": {
          "http": "http://example.com:80",
          "https": "http://example.com:443"
        }
      }
    • example.com 替换为你要代理的服务器地址。

高级配置

1 多级代理

Clash 支持多级代理,通过定义多个 outbound 配置。

{
  "outbound": {
    "http": "http://proxy1.com:80",
    "https": "http://proxy1.com:443",
    "socks5": "socks5://socks1.com:108"
  }
}

2 域间隧道(SSP)

域间隧道允许通过 Clash 转发域名到不同的服务器。

{
  "outbound": {
    "http": [
      {
        "domain": "www.example.com",
        "ip": "10.10.10.10",
        "port": 80
      }
    ]
  }
}
  • domain: 匹配的域名。
  • ip: 目标服务器的 IP 地址。
  • port: 目标服务器的端口。

3 负载均衡

Clash 支持多个后端服务器,使用轮询策略。

{
  "outbound": {
    "http": [
      {
        "domain": "www.example.com",
        "ip": "server1.com",
        "port": 80
      },
      {
        "domain": "www.example.com",
        "ip": "server2.com",
        "port": 80
      }
    ],
    "strategy": "roundrobin"
  }
}
  • strategy: 可选值有 roundrobin(轮询)、random(随机)、leastconn(最少连接)等。

4 过滤请求

使用 Clash 的过滤规则来允许或拒绝特定的请求。

{
  "rules": [
    {
      "domain": "www.example.com",
      "allowed_methods": ["GET", "POST"],
      "disallow": true
    }
  ]
}
  • allowed_methods: 允许的方法,GET, POST
  • disallow: 是否禁止访问该域名。

5 集群代理

Clash 支持多个代理服务器工作在同一时间。

{
  "outbound": {
    "http": "http://proxy1.com:80",
    "http": "http://proxy2.com:80"
  }
}

使用 CLI 配置

Clash 也支持通过命令行配置。

# 示例:设置域间隧道
./clash -add http://www.example.com --ip 10.10.10.10 --port 80
# 示例:设置多级代理
./clash -add http://proxy1.com:80 -add socks5://socks1.com:108

使用 WebSocket 代理

Clash 支持 WebSocket 代理,适用于实时通信。

{
  "outbound": {
    "ws": "ws://ws.example.com:808"
  }
}

高级配置(命令行)

1 设置工作线程

./clash -workers 4
  • 默认工作线程数为 4。

2 启用调试模式

./clash -debug

提供给其他设备

其他设备可以通过配置本地代理软件(如 iptablesfirewall)将流量转发到 Clash。


安全和权限

  • 防火墙设置:确保 Clash 所在的端口(789、7891、7892)在防火墙中开放。
  • 访问控制:在 Clash 的控制面板中设置访问权限,防止未经授权的访问。

希望这些教程能帮助你充分利用 Clash 的功能!如果有问题,可以查阅 Clash GitHub 仓库 或社区资源。

使用 Homebrew 安装 macOS)

扫码添加安易加速器官方微信

扫码添加安易加速器官方微信

021-64387251
扫码添加安易加速器官方微信

扫码添加安易加速器官方微信

网站地图