emmm,应某人要求写的。
Sing-box怎么安装就不说了。协议配置也不写了,和本文无关,简单来说一下GeoIP和Geosite的分流。
Sing-box的逻辑是,route里面的rules来判断什么样的规则(rule_set)走怎么样的出口线路(outbounts)。
比如下面这段简单的rules, 如果符合取名(tag)geosite-openai的rule_set,那么走取名(tag)openai的outbouns,tag名字可以随便取,一一对应即可。注意rules从上到下依次判断,有先后顺序(先走为敬)。
"rules": [
{
"rule_set": "geosite-openai",
"outbound": "openai"
},
{
"rule_set": "geosite-bbc",
"outbound": "bbc"
},
{
"rule_set": "geosite-google",
"outbound": "direct"
},
{
"rule_set": "geosite-cn",
"action": "reject"
},
{
"rule_set": "geoip-cn",
"action": "reject"
},
{
"outbound": "direct"
}
],
然后是rule_set。Sing-box可以自行设置很多rule_set,其中的GeoIP/GeoSite数据库地址可以在github上找,我用的是https://github.com/lyc8503/sing-box-rules。配置如下,举例来说,取名(tag)geosite-openai(和上面rules要对应)的rule_set,我选择远程数据库(因为每天在更新),二进制数据库,数据库下载地址https://github.com/lyc8503/sing-box-rules/raw/rule-set-geosite/geosite-openai.srs",下载方式direct。
"rule_set": [
{
"tag": "geosite-cn",
"type": "remote",
"format": "binary",
"url": "https://github.com/lyc8503/sing-box-rules/raw/rule-set-geosite/geosite-cn.srs"
"download_detour": "direct"
},
{
"tag": "geoip-cn",
"type": "remote",
"format": "binary",
"url": "https://github.com/lyc8503/sing-box-rules/raw/rule-set-geoip/geoip-cn.srs",
"download_detour": "direct"
},
{
"tag": "geosite-google",
"type": "remote",
"format": "binary",
"url": "https://github.com/lyc8503/sing-box-rules/raw/rule-set-geosite/geosite-google.srs"
"download_detour": "direct"
},
{
"tag": "geosite-openai",
"type": "remote",
"format": "binary",
"url": "https://github.com/lyc8503/sing-box-rules/raw/rule-set-geosite/geosite-openai.srs"
"download_detour": "direct"
},
{
"tag": "geosite-bbc",
"type": "remote",
"format": "binary",
"url": "https://github.com/lyc8503/sing-box-rules/raw/rule-set-geosite/geosite-bbc.srs"
"download_detour": "direct"
}
]
},
"experimental": {
"cache_file": {
"enabled": true
}
}
最后是outbounds。以下面举例,比如取名(tag)openai的outbounds,直接走本地IP(比如11.22.33.44),取名(tag)bbc的outbounds,也是走本地IP(比如11.22.33.44),其他流量,直接走名字叫warp的网卡。
"outbounds": [
{
"type": "direct",
"tag": "openai",
"inet4_bind_address": "11.22.33.44"
},
{
"type": "direct",
"tag": "bbc",
"inet4_bind_address": "11.22.33.44"
},
{
"type": "direct",
"tag": "direct",
"bind_interface": "warp"
}
],
写完了。