Clash 是一个强大的网络代理工具,可以用于管理和优化网络流量。以下是一个详细的 Clash 配置教程,分为基础配置和高级配置两部分,帮助你从零开始到高级使用

Clash 基础配置

安装 Clash

  • 下载 Clash

  • 安装命令行工具

    curl -L https://cli.clashdown.net | sh

    运行以上命令即可安装命令行工具。

  • 启动 Clash

    clash

    运行后会提示你输入配置文件路径或直接输入配置。

创建配置文件

Clash 的配置文件使用 JSON 格式,位于 clash.conf 文件中。

{
  "port": 789,
  "socks": "127...1:789",
  "max_connections": 100,
  "log_level": "debug",
  "log_file": "clash.log",
  "log_size_limit": 1024,
  "socks_bind": "127...1:789",
  "socks_listen": "...:789",
  "icmp_bind": "...:1234",
  "arp": "192.168.1.1",
  "dns": "192.168.1.1",
  "proxy": "http://127...1:789",
  "outgoing": [
    {
      "domain": ".../",
      "ip": "127...1",
      "port": 789
    }
  ],
  "rules": [
    {
      "domain": "google.com",
      "ip": "...",
      "type": "rewrite",
      "value": "127...1"
    }
  ]
}

配置文件字段解释

  • port:代理监听的本地端口,默认为 789
  • socks:Socks代理地址,用于其他程序连接。
  • max_connections:代理的最大连接数,默认为 100
  • log_level:日志级别,debuginfowarningerrorcritical
  • log_file:日志文件路径,默认为 clash.log
  • log_size_limit:日志文件最大大小,默认为 1024KB
  • socks_bind:将 Socks 代理绑定到指定地址。
  • socks_listen:Socks 代理的监听地址。
  • icmp_bind:ICMP 代理地址,默认为 1234 端口。
  • arp:指定局域网的 ARP 记录。
  • dns:指定 DNS 服务器地址。
  • proxy:HTTP 代理地址。
  • outgoing:规则,用于指定哪些域名或 IP 转向本地代理。
  • rules:自定义规则,用于匹配域名或 IP 并进行转向。

保存配置文件

将上述 JSON 配置保存为 clash.conf 文件。

启动 Clash

clash -c clash.conf

启动后,Clash 会以 JSON 格式打印配置信息,确认配置无误后继续运行。


Clash 常用功能配置

基础规则配置

  • 域名和 IP 转向

    {
      "outgoing": [
        {
          "domain": "google.com",
          "ip": "127...1",
          "port": 789
        },
        {
          "ip": "www.google.com",
          "ip": "127...1",
          "port": 789
        }
      ]
    }

    这将将 google.comwww.google.com 转向本地代理。

  • 默认规则

    {
      "outgoing": [
        {
          "domain": ".../",
          "ip": "127...1",
          "port": 789
        }
      ]
    }

    这将将所有域名和 IP 转向本地代理。

Socks 代理配置

  • 如果你需要其他程序使用 Socks 代理,可以将以下规则添加到 outgoing 数组:
    {
      "outgoing": [
        {
          "domain": ".../",
          "ip": "127...1",
          "port": 789
        }
      ]
    }

    这将将所有连接转向 Socks 代理。

过滤域名和 IP

  • 黑名单过滤

    {
      "rules": [
        {
          "domain": "ads.google.com",
          "type": "block",
          "ip": "..."
        },
        {
          "ip": "192.168.1.1",
          "type": "block",
          "value": "127...1"
        }
      ]
    }

    这将阻止访问 ads.google.com168.1.1

  • 允许访问特定域名或 IP

    {
      "rules": [
        {
          "domain": "www.google.com",
          "type": "allow",
          "ip": "..."
        },
        {
          "ip": "192.168.2.1",
          "type": "allow",
          "value": "127...1"
        }
      ]
    }

    这将允许访问 www.google.com168.2.1

代理设置

  • HTTP 代理

    {
      "proxy": "http://127...1:789"
    }

    将 HTTP 代理设置为 Clash 的本地代理。

  • HTTPS 代理

    {
      "proxy": "http://127...1:789",
      "proxy-verify": "false"
    }

    配置 HTTPS 代理,注意验证证书可以关闭(proxy-verify: false)。

限流配置

  • 限流规则

    {
      "outgoing": [
        {
          "domain": "example.com",
          "ip": "...",
          "port": 789,
          "limits": [
            {
              "end": 10,
              "unit": "second",
              "action": "throttle"
            }
          ]
        }
      ]
    }

    这将限制 example.com 的访问次数,每秒不超过 10 次。

  • 速率限制

    {
      "outgoing": [
        {
          "domain": ".../",
          "ip": "127...1",
          "port": 789,
          "limits": [
            {
              "end": 100,
              "unit": "kb/s",
              "action": "throttle"
            }
          ]
        }
      ]
    }

    这将限制总体的流量速度,不超过 100KB/s。

DNS 解析

  • 自定义 DNS 服务器

    {
      "dns": "192.168.1.1"
    }

    将 DNS 服务器设置为局域网的 DNS 服务器。

  • DNS 重写规则

    {
      "rules": [
        {
          "domain": "www.google.com",
          "type": "rewrite",
          "value": "127...1"
        }
      ]
    }

    这将将 www.google.com 重写为 ..1,实现 DNS 功能。

Brotli/HTTP/2 压缩

  • 启用 Brotli
    {
      "outgoing": [
        {
          "domain": ".../",
          "ip": "127...1",
          "port": 789,
          "options": {
            "brotli": true,
            "

Clash 是一个强大的网络代理工具,可以用于管理和优化网络流量。以下是一个详细的 Clash 配置教程,分为基础配置和高级配置两部分,帮助你从零开始到高级使用

扫码添加XVPN网络加速器官网微信

扫码添加XVPN网络加速器官网微信

400-725-6318
扫码添加XVPN网络加速器官网微信

扫码添加XVPN网络加速器官网微信

网站地图