安装Clash
- 下载安装包:访问Clash官方网站或通过包管理器安装,使用以下命令安装(Debian/Ubuntu):
sudo apt-get install clash
- 验证版本:确保安装了稳定版本(如
v1.19.3)。
配置Clash
- 创建配置文件:默认配置文件位于
/etc/clash/clash.conf。 - 编辑配置文件:
sudo nano /etc/clash/clash.conf
- 基本设置:
# 网络接口 interface eth # 代理端口 port 808 # 转发HTTP和HTTPS请求到上游服务器 http://127...1:80 https://127...1:443
上游服务器设置
- 配置上游服务器:
# HTTP上游服务器 http 127...1:80 # HTTPS上游服务器 https 127...1:443
设置过滤规则
- 允许本地访问:
# 允许本地访问127...1:80 allow 127...1:80 # 允许访问自己服务器的80和443端口 allow 192.168.1.101:80 allow 192.168.1.101:443
设置防火墙策略
- 允许Clash管理接口访问:
sudo ufw allow out 808 sudo iptables -A OUTPUT -p tcp --dport 808 -j ACCEPT
高级配置
- IP转换规则:
# 转换规则 ruleset { # 将10.../24转换为192.168.1./24 rule 10.../24 -> 192.168.1./24 } - 负载均衡:
# 负载均衡:根据源IP分配请求 loadbalancing source-ip
- SSL设置:
# 信任上游的证书 ssl { verify none }
启动Clash
- 启动服务:
sudo systemctl start clash
- 设置开机启动:
sudo systemctl enable clash
测试配置
- 检查Clash状态:
sudo systemctl status clash
- 测试HTTP转发:
curl -I http://localhost:808
- 测试HTTPS转发:
curl -I https://localhost:808
优化和维护
- 日志设置:
sudo nano /etc/clash/clash.conf
添加日志配置:
log { level: debug } - 监控性能:
# 使用Prometheus收集Clash指标 sudo apt-get install prometheus-node-exporter
- 定期检查日志:
sudo tail -f /var/log/clash/clash.log
故障排除
- 配置错误:检查配置文件语法,确保没有遗漏括号或逗号。
- 上游服务器问题:验证上游服务器是否运行且监听正确的端口。
- 防火墙问题:确保防火墙允许Clash的管理接口(808)正常通信。
通过以上步骤,你可以配置并运行一个功能强大的Clash代理节点,管理本地网络的流量转发和过滤。









