最近被下载网速反复折磨,换源又不能解决全部问题,索性给手头的服务器装上Clash,实现上网自由。

Clash Dashboard

可选安装,我觉得用处不大

web端控制台,新手向,相关设置一目了然

https://github.com/Dreamacro/clash-dashboard

在本地下载并构建,上传至/opt/clash/ui

后续设置的secret将用于登录

Clash控制面板

Clash Premium

Premium版Clash,可实现TUN模式

https://github.com/Dreamacro/clash/releases/tag/premium

wget -O clash.gz https://github.com/Dreamacro/clash/releases/download/premium/clash-linux-amd64-2023.08.17.gz
gzip -dc clash.gz > /usr/local/bin/clash
chmod +x /usr/local/bin/clash

Country.mmdb

提高网络分流的效率和质量

https://github.com/Dreamacro/maxmind-geoip/releases

mkdir /etc/clash
wget -O /etc/clash/Country.mmdb https://github.com/Dreamacro/maxmind-geoip/releases/download/20230812/Country.mmdb

clash.service

创建clash对应的systemd脚本,实现开机自启,持久化运行

vim /etc/systemd/system/clash.service
[Unit]
Description=clash daemon

[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/clash -d /etc/clash/
Restart=on-failure

[Install]
WantedBy=multi-user.target

重载 systemd

systemctl daemon-reload

config.yaml

根据机场订阅链接下载

wget -O /etc/clash/config.yaml https://XXXXX/config.yaml

自定义修改

port: 7890
socks-port: 7891

allow-lan: true

mode: rule

external-controller: :9090
external-ui: /opt/clash/ui

secret: "******"

dns:
enable: true
listen: :53
enhanced-mode: fake-ip
fake-ip-range: 198.18.0.1/16
fake-ip-filter:
- '*.btwoa.com'
nameserver:
- 114.114.114.114
- 8.8.8.8
- tls://dns.rubyfish.cn:853
- https://1.1.1.1/dns-query
- dhcp://en0
fallback:
- 8.8.8.8
tun:
enable: true
stack: system
dns-hijack:
- 8.8.8.8:53
- tcp://8.8.8.8:53
- any:53
- tcp://any:53
auto-route: true
auto-detect-interface: true

.bashrc

vim ~/.bashrc
export http_proxy="127.0.0.1:7890"
export https_proxy="127.0.0.1:7891"
export all_proxy="socks5://127.0.0.1:7891"

重载

source ~/.bashrc

TUN模式

/etc/sysctl.conf

开启转发功能

vim /etc/sysctl.conf
net.ipv4.ip_forward=1

重载

sysctl -p

运行并自启

systemctl start clash
systemctl enable clash

测试

启动Clash服务

Ping Google

问题

TUN 模式导致Docker容器服务无法从外网访问

目前这是个bug,可前往issues查看https://github.com/Dreamacro/clash/issues/2733

期待后续修复

最简单的解决办法是外网访问容器时关闭clash