前言 简介 Clash 是一款用 Go 开发的支持 Linux/MacOS/Windows 等多平台的代理工具,支持 ss/v2ray(不支持 ssr),支持规则分流(类似于 Surge 的配置)。
项目地址:
本文测试用ip和端口
例子中使用到的本机ip为:192.168.1.230
clash中利用到的端口:http:7890 socks: 7891 redir:7892
测试结果:群晖,vm ubuntu18,pve ubuntu18,树莓派3b/3b+ 通过~~
安装clash 1. 设置dns 1 2 3 4 5 6 apt -y install iptables-persistent net-tools curl vim vim /etc/systemd/resolved.conf DNSStubListener=no
2. 下载安装clash 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 mkdir clashcd clashwget https://github.com/Dreamacro/clash/releases/download/v0.15.0/clash-linux-amd64-v0.15.0.gz gunzip clash-linux-amd64-v0.15.0.gz mv clash-linux-amd64-v0.15.0 clashchmod +x clash./clash -d . scp /sandyliao/Desktop/config.yml root@10.10.10.10:/root/clash
3. 编辑config.yml文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 port: 7890 socks-port: 7891 redir-port: 7892 allow-lan: true mode: Rule log-level: info external-controller: '0.0.0.0:6170' secret: '' dns: enable: true ipv6: false listen: 0.0 .0 .0 :53 enhanced-mode: redir-host nameserver: - 114.114 .114 .114 - 223.5 .5 .5 - tls://dns.rubyfish.cn:853 fallback: - 114.114 .114 .114 - tls://dns.rubyfish.cn:853 - 8.8 .8 .8 Proxy:
局域网转发:这里面有几个注意事项:
1.做透明代理,必须启用redir-port,也就是clash透明代理的端口。
2.做网关设备,你就必须得让其他局域网的机器能够连接到clash,所以allow-lan必须打开。
3.必须打开clash的DNS功能,并且使用redir-host模式,最重要的是你还需要在fallback:后面加上一个支持DoT的DNS。比如我这边是使用的dns.rubyfish.cn:853,如果你用普通的DNS无非解决域名被污染的问题。
4.设置端口转发 配置文件弄好了之后,现在我们需要把机器所有的流量都转发到clash的透明代理端口上面,当然192.168.0.0这个网段的流量我们不做转发:
1 2 3 4 5 iptables -t nat -N Clash iptables -t nat -A Clash -d 10.0.0.0/16 -j RETURN iptables -t nat -A Clash -p tcp -j REDIRECT --to-ports 27017 iptables -t nat -A PREROUTING -p tcp -j Clash iptables -t nat -A PREROUTING -p tcp -j REDIRECT --to-ports 27017
永久保存iptables规则:
1 netfilter-persistent save
5.开机运行 1. 利用screen来后台运行 首先安装screen
1 2 3 apt install screen screen -S clash ./clash -d .
2. 设置rc-local 设置开机启用,仅限ubuntu18版本
1 2 3 4 5 6 7 8 9 systemctl status rc-local.service vim /lib/systemd/system/rc-local.service [Install] WantedBy=multi-user.target Alias=rc-local.service
3. 编辑rc.local
1 2 3 4 5 6 7 8 9 10 11 12 13 14 #!/bin/bash bash /root/start.sh exit 0
4. 编辑start.sh文件
1 2 3 4 #!/bin/bash screen_name="clash" screen -dmS $screen_name screen -x -S $screen_name -p 0 -X stuff $'/root/clash/clash -d /root/clash &\n'
给予权限 ``bash chmod +x /etc/rc.local
1 2 3 ### 5. 开启服务 ```bash systemctl enable rc-local
启动服务并检查状态
1 2 sudo systemctl start rc-local.service sudo systemctl status rc-local.service
重新启动服务器
检测服务器是不是已经启动
1 sudo systemctl status rc-local.service
输出文字,字样就成功启动
1 2 Active: active (running) since Fri 2019-06-07 03:25:59 UTC; 19s ago screen -ls
输出文字,字样就成功启动
1 2 3 There is a screen on: 168.clash (06/08/19 07:14:04) (Detached) 1 Socket in /run/screen/S-root.
安装WEBUI:yacd 配置yacd 我们来配置yacd需要的组件,直接在这台旁路由上安装Node.js/Yarn:
1 2 3 4 5 6 apt -y install git build-essential curl -sL https://deb.nodesource.com/setup_12.x | bash - apt -y install nodejs curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.listapt -y update && apt -y install yarn
安装nginx 1 apt -y install nginx unzip
nginx安装完成之后把nginx的这个引用配置文件改个名:
1 mv /etc/nginx/sites-enabled/default /etc/nginx/sites-enabled/default.bak
新建一个nginx的conf:
1 vim /etc/nginx/conf.d/yacd.conf
配置如下:
1 2 3 4 5 6 server { listen 80 ; server_name 192.168.0.233 ; root /usr/share/nginx/html/yacd; index index.html; }
安装yacd 1 2 3 4 5 git clone https://github.com/haishanh/yacd.git cd yacdyarn yarn build cp -r public/. /usr/share/nginx/html/yacd
最后启动nginx:
1 2 3 systemctl restart nginx systemctl start nginx systemctl enable nginx
客户端设置 1. 手机和wifi在局域网的情况下设置 1 2 3 4 5 ip:192.168.1.211 掩码:255.255.255.0 网关:192.168.1.230 dns:192.168.1.230
无wifi,使用4g的情况下!使用frpc端
在frpc下增加下面一段http的透明代理
1 2 3 4 5 [clash] type = tcp local_ip =192.168.1.230 local_port = 7890 remote_port = 7890
手机上设置frps.ip:7890
说明文档和config.yml演示文件下载地址:https://drive.google.com/drive/folders/1XFeVHe61qbF2G0o38oCy0D0OfcGdnpzt?usp=sharing