文章

linux下简单的clash使用教程

  编辑于:2020-09-11
文章目录

介绍

clashs一个用go编写的基于规则的代理软件客户端,支持shadowsocks,v2ray,Trojan等多个平台配合,再配合其强大的规则支持可以实现定制化的使用体验。

使用

下载clash

根据系统架构下载相应的文件:https://github.com/Dreamacro/clash/releases
windows图形界面:https://github.com/Fndroid/clash_for_windows_pkg
这里以clash-linux-amd64为例。
下载clash

mkdir clash 
cd clash
wget https://github.com/Dreamacro/clash/releases/download/v1.1.0/clash-linux-amd64-v1.1.0.gz
gzip -d clash-linux-amd64-v1.1.0.gz
chmod +x clash-linux-amd64-v1.1.0
mv clash-linux-amd64-v1.1.0 clash

新建配置文件vi config.yaml

# 本地http(s)代理端口
port: 8080

# 本地socks5代理端口
socks-port: 1080

# 是否允许局域网中其他机器访问
allow-lan: false

# 仅当allow-lan设置为true时生效
# '*': 绑定所有IP
# 192.168.122.11:绑定单个IPV4
# "[aaaa::a8aa:ff:fe09:57d8]":绑定单个IPV6
bind-address: '*'

# 玉兴模式
# rule: 基于规则
# global: 全局代理
# direct: 不代理
mode: rule

# 日志输出级别
# info / warning / error / debug / silent
log-level: info

# 当设置为false时,不解析IPV6地址
ipv6: false

# 流量出的接口
interface-name: eth0

proxies:
#代理服务器配置,更多的代理设置请查看:https://lancellc.gitbook.io/clash/clash-config-file/an-example-configuration-file
  # vmess
  # cipher support auto/aes-128-gcm/chacha20-poly1305/none
  - name: "vmess"
    type: vmess
    server: server
    port: 443
    uuid: uuid
    alterId: 32
    cipher: auto
    # udp: true
    # tls: true
    # skip-cert-verify: true
    # servername: example.com # priority over wss host
    # network: ws
    # ws-path: /path
    # ws-headers:
    #   Host: v2ray.com

proxy-groups:
  #组策略
  # url-test 自动选择最快的节点进行访问.
  - name: "auto"   #策略名
    type: url-test
    proxies:
      - ss1
      - ss2
      - vmess1
    # tolerance: 150
    url: 'http://www.gstatic.com/generate_204'
    interval: 300

rules:
#节点选择策略
   #当一级域名是google.com时使用auto策略
  - DOMAIN-SUFFIX,google.com,auto
   #当域名含有关键词google时使用auto
  - DOMAIN-KEYWORD,google,auto
  - DOMAIN,google.com,auto
   #当一级域名是ad.com时拒绝访问,可以用于屏蔽广告
  - DOMAIN-SUFFIX,ad.com,REJECT
  - SRC-IP-CIDR,192.168.1.201/32,DIRECT
  # 可选参数 "no-resolve" ,基于IP的规则 (GEOIP, IP-CIDR, IP-CIDR6)
  - IP-CIDR,127.0.0.0/8,DIRECT
  - GEOIP,CN,DIRECT
   #目标端口是80时,直接访问不走代理
  - DST-PORT,80,DIRECT
  - SRC-PORT,7777,DIRECT
  - RULE-SET,apple,REJECT # 仅限Premium版本
   #默认规则
  - MATCH,auto

这里只是简单的规则,需要更多内容请查看:https://lancellc.gitbook.io/clash/

设置开机启动

如果系统支持systemd
编写配置文件

echo '[Unit]
Description=clash auto run

[Service]
Type=simple

ExecStart=/root/clash/clash -f /root/clash/config.yaml

[Install]
WantedBy=default.target' > /etc/systemd/system/clash.service

开启自动启动

systemctl enable clash && systemctl start clash

自此clash的简易配置就完成了。

参考链接:https://lancellc.gitbook.io/clash/

发表回复