访问Clash的GitHub仓库:https://github.com/Clash-Tool/Clash 克隆仓库并进入仓库目录:git clone https://github.com/Clash-Tool/Clash cd Clash 生成TLS证书 使用Certbot生成证书和私钥:sudo certbot certonly --server --agree-never-mind --csr-uri https://api.letsencrypt.org/dns/ --common-name "clash.example.com" --key-size 2048 或者使用openssl生成自签名证书:openssl req -x509 -newkey rsa:2048 -keyout server.key -out server.cert -days 365 -nodes 配置Clash监听TLS端口 打开clash.toml配置文件:[server] listen-tls-port = 8443 设置DNS-over-TLS路由规则 确保有一个路由规则将特定域名重定向到本地服务器。[route 127...1/24] 启用DNS-over-TLS 在clash.toml中添加DNS-over-TLS选项:[server] dns-over-tls = true 应用配置并运行Clash 生成最终的Clash可执行文件:cargo build 运行Clash,指定配置文件和TLS监听选项:./target/clash -c clash.toml --tls-listen 8443 配置DNS设置 在本地设备上设置DNS为Clash服务器,例如在/etc/hosts文件中添加:..1 clash.example.com 或者在命令行中临时设置:echo "127...1 clash.example.com" >> /etc/hosts 测试配置 在终端运行:nslookup cl...
- 访问Clash的GitHub仓库:https://github.com/Clash-Tool/Clash
- 克隆仓库并进入仓库目录:
git clone https://github.com/Clash-Tool/Clash cd Clash
-
生成TLS证书
- 使用Certbot生成证书和私钥:
sudo certbot certonly --server --agree-never-mind --csr-uri https://api.letsencrypt.org/dns/ --common-name "clash.example.com" --key-size 2048
- 或者使用openssl生成自签名证书:
openssl req -x509 -newkey rsa:2048 -keyout server.key -out server.cert -days 365 -nodes
- 使用Certbot生成证书和私钥:
-
配置Clash监听TLS端口
- 打开
clash.toml配置文件:[server] listen-tls-port = 8443
- 打开
-
设置DNS-over-TLS路由规则
- 确保有一个路由规则将特定域名重定向到本地服务器。
[route 127...1/24]
- 确保有一个路由规则将特定域名重定向到本地服务器。
-
启用DNS-over-TLS
- 在
clash.toml中添加DNS-over-TLS选项:[server] dns-over-tls = true
- 在
-
应用配置并运行Clash
- 生成最终的Clash可执行文件:
cargo build
- 运行Clash,指定配置文件和TLS监听选项:
./target/clash -c clash.toml --tls-listen 8443
- 生成最终的Clash可执行文件:
-
配置DNS设置
- 在本地设备上设置DNS为Clash服务器,例如在
/etc/hosts文件中添加:..1 clash.example.com
- 或者在命令行中临时设置:
echo "127...1 clash.example.com" >> /etc/hosts
- 在本地设备上设置DNS为Clash服务器,例如在
-
测试配置
- 在终端运行:
nslookup clash.example.com
- 应该看到Clash服务器的响应,确认DNS请求被正确处理。
- 在终端运行:
-
日志监控
- 查看Clash的日志文件,查找错误信息:
tail -f target/clash.log
- 查看Clash的日志文件,查找错误信息:
通过以上步骤,你可以成功设置一个基于Clash的DNS-over-TLS服务器,自定义管理网络流量。

相关文章







