这篇文章上次修改于 1396 天前,可能其部分内容已经发生变化,如有疑问可询问作者。
因工作需要,经常要登录gmail邮箱和google voice,国内访问确实很困难,少不了要科学上网,但是每个设备都设置一遍,挺麻烦,于是就有了本文安装clash搭建透明网关。
使用
准备
由于armbian的默认配置占用了53端口,这里修改一下配置vi /etc/systemd/resolved.conf,将其中的DNSStubListener=no#取消注释,把yes改为no
安装arm版本的clash
mkdir clash
cd clash
wget wget https://github.com/Dreamacro/clash/releases/download/v0.19.0/clash-linux-armv7-v0.19.0.gz
gzip -d clash-linux-armv7-v0.19.0.gz
chmod +x clash-linux-armv7-v0.19.0
mv clash-linux-armv7-v0.19.0 clash
配置clash
这里实例的是一个简单的配置, 进入clash目录,新建配置文件vi config.yaml
port: 7890
socks-port: 7891
#透明代理需要
redir-port: 7892
#透明代理需要允许来自局域网的访问
allow-lan: true
mode: Rule
log-level: info
#流量出口使用的网络接口
interface-name: eth0
# hosts设置,只有当DNS模式为redir-host时生效
hosts:
# '*.clash.dev': 127.0.0.1
# '.dev': 127.0.0.1
# 'alpha.clash.dev': '::1'
# DNS设置,透明代理需要使用clash提供的DNS服务
dns:
enable: true
listen: 0.0.0.0:53
default-nameserver:
- 114.114.114.114
- 8.8.8.8
enhanced-mode: fake-ip # 可选:fake-ip
fake-ip-range: 198.18.0.1/16
nameserver:
- 114.114.114.114 # default value
- 8.8.8.8 # default value
- tls://dns.rubyfish.cn:853 # DNS over TLS
- https://1.1.1.1/dns-query # DNS over HTTPS
fallback-filter:
geoip: true
ipcidr:
# - 240.0.0.0/4
#节点配置,此处可以参考:https://lancellc.gitbook.io/clash/clash-config-file/an-example-configuration-file
Proxy:
#v2y节点示例
- name: "v2y"
type: vmess
server: server3_of_ss
port: 443
uuid: uuid
alterId: 0
cipher: auto
#节点组配置,可以将多个节点组合成一个组,并且按照一定的规则访问组内节点
Proxy Group:
#节点组示例,使用该组节点时将会自动选择延迟较低的节点
- name: "auto"
type: url-test
proxies:
- v2y
url: 'http://www.gstatic.com/generate_204'
interval: 300
#路由规则,将指定流量使用何种规则
Rule:
#本地流量需要直接放行
- IP-CIDR,127.0.0.0/8,DIRECT
- IP-CIDR,192.168.0.0/16,DIRECT
- MATCH,auto
设置防火墙
tproxy运行需要iptables的支持
iptables -t nat -N clash iptables -t nat -A clash -d 0.0.0.0/8 -j RETURN iptables -t nat -A clash -d 10.0.0.0/8 -j RETURN iptables -t nat -A clash -d 127.0.0.0/8 -j RETURN iptables -t nat -A clash -d 169.254.0.0/16 -j RETURN iptables -t nat -A clash -d 172.16.0.0/12 -j RETURN iptables -t nat -A clash -d 192.168.0.0/16 -j RETURN iptables -t nat -A clash -d 224.0.0.0/4 -j RETURN iptables -t nat -A clash -d 240.0.0.0/4 -j RETURN iptables -t nat -A clash -p tcp -j REDIRECT --to-port 7892 iptables -t nat -A PREROUTING -p tcp -j clash
由于iptables的设置重启会消失,可以将上述内容放到/etc/rc.local的exit 0之前即可。
设置开机启动
echo '[Unit] Description=clash auto run [Service] Type=simple ExecStart=/usr/local/bin/clash -d /root/clash/ [Install] WantedBy=default.target' > /etc/systemd/system/clash.service
运行clash
systemctl enable clash && systemctl start clash
设置网关
只需要将需要科学上网的设备的网关和DNS都设置为赚钱宝Pro的IP,即可开始网上冲浪