Clash规则文件是基于JSON格式的文件,用于定义网络流量的拦截和重定向规则。以下是常见的规则配置示例
拦截所有域名访问,重定向到本地服务器
{
"rules": [
{
"match": {
"domain": ".*"
},
"route": {
"target": "http://localhost:300"
}
}
]
}
拦截特定域名(如谷歌),重定向到本地808端口
{
"rules": [
{
"match": {
"domain": "^google\\.com$"
},
"route": {
"target": "http://localhost:808"
}
}
]
}
拦截特定IP地址
{
"rules": [
{
"match": {
"ip": "192.168.1.1"
},
"route": {
"target": "http://localhost:300"
}
}
]
}
拦截特定端口流量(如80端口)
{
"rules": [
{
"match": {
"port": 80
},
"route": {
"target": "http://external-server.com"
}
}
]
}
拦截URL路径(如/api)
{
"rules": [
{
"match": {
"path": "^/api"
},
"route": {
"target": "http://localhost:300"
}
}
]
}
拦截域名和端口组合(如www.example.com:443)
{
"rules": [
{
"match": {
"domain": "^www\\.example\\.com$",
"port": 443
},
"route": {
"target": "http://localhost:300"
}
}
]
}
拦截多个域名到不同端口
{
"rules": [
{
"match": {
"domain": "^google\\.com$"
},
"route": {
"target": "http://localhost:808"
}
},
{
"match": {
"domain": "^amazon\\.com$"
},
"route": {
"target": "http://localhost:300"
}
}
]
}
拦截IP地址和端口组合
{
"rules": [
{
"match": {
"ip": "192.168.1.1",
"port": 808
},
"route": {
"target": "http://localhost:300"
}
}
]
}
拦截特定协议(HTTP/HTTPS)
{
"rules": [
{
"match": {
"scheme": ["http", "https"]
},
"route": {
"target": "http://localhost:300"
}
}
]
}
拦截国家域名(如日本.co.jp)
{
"rules": [
{
"match": {
"domain": "^\\.co\\.jp$"
},
"route": {
"target": "http://localhost:300"
}
}
]
}
注意事项
match中的domain、ip、port和path都支持正则表达式。- 使用
^和来精确匹配域名或路径,避免子域名或路径的误拦截。 - 需要确保Clash服务正在运行,并且规则文件路径正确。
- 建议在配置完成后,通过Clash的Web界面或命令行工具进行测试和验证。
通过以上配置,您可以根据具体需求定义不同的网络流量拦截规则,实现网络流量的管理和重定向。

如果没有特点说明,本站所有内容均由原子加速器官方网站|提供客户端版本、线路管理与节点选择功能,适配Windows、Android、iOS等设备,便于用户进行网络连接优化原创,转载请注明出处!