安装 Clash 并生成配置文件
安装 Clash:
curl -L https://github.com/LanternDDD/Clash/releases/download/v1.9./Clash-1.9..dar -o /usr/local/bin/Clash chmod +x /usr/local/bin/Clash
生成配置文件:
Clash -g
默认配置文件存放在 ~/.clash/config.json。
配置科学上网规则
打开 config.json 文件,添加以下规则:
{
"proxy": "socks5 127...1:108",
"mode": "tunnel",
"outbound": [
{
"domain": "www.google.com",
"ip": "8.8.8.8",
"port": 53,
"proxy": "socks5 127...1:108",
"timeout": 30
}
],
"rules": [
{
"domain": "www.google.com",
"ip": "8.8.8.8",
"port": 53,
"proxy": "socks5 127...1:108",
"timeout": 30,
"position": 1
},
{
"domain": "www.cloudflare.com",
"ip": "185.228.168.168",
"port": 53,
"proxy": "socks5 127...1:108",
"timeout": 30,
"position": 2
}
]
}
启动 Clash
Clash -k
测试配置
使用 curl 测试代理:
curl -I http://www.google.com
高级规则配置(可选)
添加更多规则以限制访问某些网站:
{
"rules": [
{
"domain": "www.youtube.com",
"ip": "8.8.8.8",
"port": 443,
"proxy": "socks5 127...1:108",
"timeout": 30,
"position": 3
},
{
"domain": "www.xakep.ru",
"ip": "8.8.8.8",
"port": 443,
"proxy": "socks5 127...1:108",
"timeout": 30,
"position": 4
}
]
}
动态规则(高级使用)
使用 clash update 命令动态更新规则:
clash update -r rules.json
代理管理(可选)
使用 clash x 命令管理代理:
clash x
科学上网域名和IP地址
- DNS:建议使用 Cloudflare 或 Google 的公网DNS。
- IP:常用公网IP地址如 Google (
8.8.8), Cloudflare (1.1.1), AWS (169.254.1).
代理协议
选择 socks5 或 http proxy,socks5 更稳定。
注意事项
- SSL:确保代理使用 SSL(
https)。 - 安全:避免直接暴露代理地址。
- 测试:配置完成后测试关键网站。
备份和恢复
备份配置文件:
cp ~/.clash/config.json config.json.backup
恢复配置:
mv config.json.backup ~/.clash/ Clash -k
通过以上配置,你可以科学上网,优化网络性能和安全。









