本文最后更新于:2026年3月3日 晚上
在树莓派5/4G版本上部署clash
参考链接1,树莓派4B_linux clash部署教程(2024.3.4)
参考链接2,在 Raspberry Pi 上运行 Clash 作为透明代理
参考链接3,树莓派(无桌面)运行 clash 代理服务
确认系统架构
返回的型号应当是aarch64, 因此选择mihomo-arm64版本进行下载
如果不希望使用TUN模式的话也可以下载使用老的clash-armv8内核
选择此内核的原因是希望能开启TUN模式
通过官方github release页面下载 mihomo-linux-arm64-v1.19.20.gz,注意是arm64的gz包
1 2 3 4
| gunzip mihomo-linux-arm64-v1.19.20.gz
sudo mv mihomo-linux-arm64-v1.19.20 /usr/local/bin/clash sudo chmod +x /usr/local/bin/clash
|
下载Country.mmdb
Country.mmdb 地理位置数据库文件,可以从官方github release页面 下载
下载config.yaml
自行寻找,注意名字需要调整为config.yaml,因为这是默认加载的配置文件,如果是别的名字的话请参考后面的注册为后台服务章节
将配置文件放入文件夹
1 2 3
| sudo mkdir -p ~/.config/clash/ sudo mv config.yaml ~/.config/clash/ sudo mv Country.mmdb ~/.config/clash/
|
运行
确认版本号
输出应当类似Clash Meta v1.xx.x
启动
1
| clash -d ~/.config/clash
|
注意:ctrl+c不能关闭clash,需要额外输入关闭命令以正确停止clash运行
注册为后台服务
可以实现自动重启、开机自启
创建服务
1
| sudo vim /etc/systemd/system/clash.service
|
编写服务文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| [Unit] Description=Clash Proxy Service After=network-online.target Wants=network-online.target
[Service] Type=simple User=myusername Group=myusername
ExecStart=/usr/local/bin/clash -d /home/myusername/.config/clash -f /home/myusername/.config/clash/config.yaml Restart=on-failure RestartSec=5s
# ===== TUN 必须的权限 ===== AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE NoNewPrivileges=true
LimitNOFILE=1048576
[Install] WantedBy=multi-user.target
|
注意:需要根据你的用户名替换myusername,clash的config.yaml可以根据你的配置文件名进行修改
启动服务
1 2 3
| sudo systemctl daemon-reload sudo systemctl enable clash sudo systemctl start clash
|
增加TUN模式
在config.yaml中增加一下内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| tun: enable: true stack: system dns-hijack: - any:53 auto-route: true auto-detect-interface: true
dns: enable: true listen: 0.0.0.0:1053 enhanced-mode: fake-ip fake-ip-range: 198.18.0.1/16 use-hosts: true
nameserver: - 223.5.5.5 - 119.29.29.29
fallback: - 8.8.8.8 - 1.1.1.1 - tls://[2606:4700:4700::1111]:853 - tls://[2001:4860:4860::8888]:853
fallback-filter: geoip: true geoip-code: CN ipcidr: - 240.0.0.0/4
|
1 2 3
| ip a | grep 198.18
inet 198.18.0.1/30 brd 198.18.0.3 scope global Meta
|
常用的config.yaml配置
1 2 3 4
| ipv6: true allow-lan: true external-controller: 0.0.0.0:9090 secret: 自行填写密钥,注意双引号也会被作为密钥使用
|
定期更新订阅
config.yaml 里加入如下内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| profile: store-selected: true store-fake-ip: true interval: 86400
proxy-providers: airport: type: http url: https://你的订阅地址 interval: 86400 path: ./providers/airport.yaml health-check: enable: true url: http://www.gstatic.com/generate_204 interval: 300
proxy-groups: - name: 🔰 选择节点 type: select use: - airport
|
部署基于本地的web ui
yacd,简单稳定的web ui
下载yacd文件
1 2 3 4 5 6 7 8 9 10
| cd ~/.config/clash mkdir -p yacd cd yacd
wget https://github.com/haishanh/yacd/releases/latest/download/yacd.tar.xz tar -xf yacd.tar.xz
ls
|
配置yacd界面
1
| vim ~/.config/clash/config.yaml
|
打开config.yaml并增加以下内容
重启clash,查看页面树莓派ip地址:9090
1
| sudo systemctl restart clash
|
创建目录(严格对齐)
1 2
| mkdir -p ~/.config/clash/meta-dashboard cd ~/.config/clash/meta-dashboard
|
下载官方构建好的 UI(不是源码)
1 2
| wget https://github.com/MetaCubeX/metacubexd/releases/latest/download/metacubexd.tar.gz tar -xzf metacubexd.tar.gz
|
解压后你应该看到:
确认路径最终是:
1
| ~/.config/clash/meta-dashboard/index.html
|
1
| vim ~/.config/clash/config.yaml
|
打开config.yaml并增加以下内容
1
| external-ui: meta-dashboard
|
重启clash,查看页面树莓派ip地址:9090
1
| sudo systemctl restart clash
|