chika0801 / sing-box-examples

sing-box 配置示例
https://github.com/SagerNet/sing-box
1.61k stars 268 forks source link

win7环境使用sing-box客户端,dns没法远程解析,请帮忙看看是不是配置文件配的有问题,谢谢! #119

Closed mebest100 closed 2 weeks ago

mebest100 commented 3 weeks ago

win7环境使用sing-box客户端,dns没法远程解析,请帮忙看看配置文件配的有问题,谢谢! 以下是配置文件:

{
    "log": {
        "level": "info",
        "timestamp": true
    },
    "dns": {      
        "independent_cache": true,
        "rules": [
            {
                "outbound": [
                    "any"
                ],
                "server": "local"
            },
            {
                "disable_cache": true,
                "rule_set": [
                    "AdGuardSDNSFilter",
                    "chrome-doh"
                ],
                "server": "block"
            },
            {
                 "clash_mode": "global",
                "server": "remote"
            },

            {
                "clash_mode": "direct",
                "server": "local"
            },
            {
                "rule_set": "geosite-cn",
                "server": "local"
            }
        ],
        "servers": [
            {
                "address": "https://1.1.1.1/dns-query",
                "detour": "select",
                "tag": "remote"
            },
            {
                "address": "https://223.5.5.5/dns-query",
                "detour": "direct",
                "tag": "local"
            },
            {
                "address": "rcode://success",
                "tag": "block"
            }
        ],
        "strategy": "prefer_ipv4"
    },
    "experimental": {
        "cache_file": {
            "enabled": true
        },
        "clash_api": {
            "external_controller": "127.0.0.1:9090",
            "secret": ""
        }
    },

    "inbounds": [
         {
            "domain_strategy": "prefer_ipv4",
            "listen": "127.0.0.1",
            "listen_port": 2333,
            "tag": "socks-in",
            "type": "socks",
            "users": []
        },
        {
            "domain_strategy": "prefer_ipv4",
            "listen": "127.0.0.1",
            "listen_port": 2334,
            "tag": "mixed-in",
            "type": "mixed",
            "users": []
        }
    ],
    "outbounds": [   
     {
            "tag": "select",
            "type": "selector",
            "default": "TuicV5",
            "outbounds": [
                "TuicV5"
            ]
        },

        {
            "tag": "TuicV5",
            "type": "tuic",
            "server": "xxxxxx",
            "server_port": 13131,
            "uuid": "xxxxxx",
            "password": "xxxxx",           
            "congestion_control": "bbr",
            "tls": {
                "enabled": true,
                "server_name": "xxxxxx",
                "alpn": ["h3"]
            }
        },
        {
            "type": "direct",
            "tag": "direct"
        },
        {
            "type": "block",
            "tag": "block"
        },
        {
            "type": "dns",
            "tag": "dns-out"
        }
    ],
    "route": {
        "auto_detect_interface": true,
        "rule_set": [
            {
                "format": "binary",
                "tag": "geoip-cn",
                "type": "local",
                "path": "./geoip-cn.srs"
            },
            {
                "format": "binary",
                "tag": "geosite-cn",
                "type": "local",
                "path": "./geosite-geolocation-cn.srs"
            },
            {
                "format": "binary",
                "tag": "AdGuardSDNSFilter",
                "type": "local",
                "path": "./AdGuardSDNSFilter.srs"
            },
            {
                "format": "source",
                "tag": "chrome-doh",
                "type": "local",
                "path": "./chrome-doh.json"
            }
        ],
        "rules": [
            {
                "outbound": "dns-out",
                "protocol": "dns"
            },
            {
                "clash_mode": "direct",
                "outbound": "direct"
            },
            {
                "clash_mode": "global",
                "outbound": "select"
            },
            {
                "ip_is_private": true,
                "outbound": "direct"
            },
            {
                "outbound": "direct",
                "rule_set": "geoip-cn"
            }
        ]
    }

}
chika0801 commented 3 weeks ago

看了你配置,你入站部分,只有2个,不知道你这2个入站前端是接的什么,比如浏览器chrome用的代理插件接这2个端口。

从现在的配置来看,假设是chrome用的代理插件接这2个端口,发到Sing-box入站的请求都是域名,你入站配置没加

"domain_strategy": "prefer_ipv6",

这参数时,入站接到请求,进路由部分,匹配的条件就只有域名,没命中的走第1个默认出站,发到VPS(服务端)的请求类型是域名。

大概分析了一下你的配置是这意思。

mebest100 commented 3 weeks ago

我入站走其中一个就可以了,比如socket 2333端口,我chrome就是这么配的。 另外我不走ipv6,所以就不需要配你说的

 "domain_strategy": "prefer_ipv6"

我贴出来的是网上抄来的一份配置。 我的要求很简单,就是要求所有走代理的请求都dns远程解析(也就是在vps上解析dns),而且远程解析dns是1.1.1.1

{
                "address": "https://1.1.1.1/dns-query",
                "detour": "select",
                "tag": "remote"
            },

但是这样配貌似没有生效: image

dns如果不能远程解析,直接就造成dns污染,也就是没法正常上网

我在windows使用clash-meta是没有问题的,貌似他们在代理时会自动dns远程解析,但是sing-box就不行。

chika0801 commented 3 weeks ago

我入站走其中一个就可以了,比如socket 2333端口,我chrome就是这么配的。

你是在chrome用插件进socks端口,那么这种形式,前面说了“发到Sing-box入站的请求都是域名”。 如果你在客户端不需求以IP作为条件分流,只看看域名是不是合你规则,你则不需要使用“ "domain_strategy": "prefer_ipv6" “ 这参数,这参数不是说你不用ipv6就不写它,它的具体作用你要有点基础看sing-box的文档有解释。你不写它时,现在你的这种用法模式,进Singbox的请求类型只是域名,前面说过,请求进来,进路由部分,条件只有域名,没命中,走默认第1个出站。

这类知识,网上基本没有针对sing-box的原理的博文和讲得很入门的视频教程,都是自己悟自学。

继续,按你上面这用法,你客户端实际没做过DNS,请求的域名发到了服务端,剩下就是你服务端配置做的事情了。

chika0801 commented 3 weeks ago

https://tachyondevel.medium.com/%E6%BC%AB%E8%B0%88%E5%90%84%E7%A7%8D%E9%BB%91%E7%A7%91%E6%8A%80%E5%BC%8F-dns-%E6%8A%80%E6%9C%AF%E5%9C%A8%E4%BB%A3%E7%90%86%E7%8E%AF%E5%A2%83%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8-62c50e58cbd0

你可以以这个为例理解下chrome浏览器用插件无论是http还是socks端口的处理原理

sing-box的流程与ray系比较类似,你如果有用ray系的基本就很好入门,你应该没有。

mebest100 commented 3 weeks ago

v2ray系基本都是用ui界面的,我很少使用config.json,而且从未碰到过dns问题,也不需要我手动去做配置。

而且我的服务端肯定是没有问题的,因为我在客户端使用clash-meta和安卓都是可以连上的。

我不明白: 我把安卓的那套配置文件直接给windows使用(唯一的区别是:我只是把tun配置去掉了),为什么就不行了? 下面是安卓端的配置文件,使用是没有问题的

{
    "dns": {
        "fakeip": {
            "enabled": true,
            "inet4_range": "198.18.0.0/15",
            "inet6_range": "fc00::/18"
        },
        "independent_cache": true,
        "rules": [
            {
                "outbound": [
                    "any"
                ],
                "server": "local"
            },
            {
                "disable_cache": true,
                "rule_set": [
                    "AdGuardSDNSFilter",
                    "chrome-doh"
                ],
                "server": "block"
            },
            {
                "query_type": [
                    "A",
                    "AAAA"
                ],
                "rewrite_ttl": 1,
                "server": "fakeip"
            },
            {
                "clash_mode": "global",
                "server": "remote"
            },
            {
                "clash_mode": "direct",
                "server": "local"
            },
            {
                "rule_set": "geosite-cn",
                "server": "local"
            }
        ],
        "servers": [
            {
                "address": "https://1.1.1.1/dns-query",
                "detour": "select",
                "tag": "remote"
            },
            {
                "address": "https://223.5.5.5/dns-query",
                "detour": "direct",
                "tag": "local"
            },
            {
                "address": "rcode://success",
                "tag": "block"
            },
            {
                "address": "fakeip",
                "tag": "fakeip"
            }
        ],
        "strategy": "prefer_ipv4"
    },
    "experimental": {
        "cache_file": {
            "enabled": true
        },
        "clash_api": {
            "external_controller": "127.0.0.1:9090",
            "secret": ""
        }
    },
    "inbounds": [
        {
            "auto_route": true,
            "domain_strategy": "prefer_ipv4",
            "endpoint_independent_nat": true,
            "inet4_address": "172.19.0.1/30",
            "inet6_address": "2001:0470:f9da:fdfa::1/64",
            "mtu": 9000,
            "sniff": true,
            "strict_route": true,
            "type": "tun"
        },
        {
            "domain_strategy": "prefer_ipv4",
            "listen": "127.0.0.1",
            "listen_port": 2333,
            "tag": "socks-in",
            "type": "socks",
            "users": []
        },
        {
            "domain_strategy": "prefer_ipv4",
            "listen": "127.0.0.1",
            "listen_port": 2334,
            "tag": "mixed-in",
            "type": "mixed",
            "users": []
        }
    ],
    "log": {},
    "outbounds": [
        {
            "tag": "select",
            "type": "selector",
            "default": "urltest",
            "outbounds": [
                "urltest",
                "HysteriaV2"
            ]
        },
        {
            "password": "xxxx",
            "server": "xxxx",
            "server_port": xxxxx,
            "tag": "HysteriaV2",
            "tls": {
                "enabled": true,
                "server_name": "xxxxxx"
            },
            "type": "hysteria2",
            "down_mbps": 50,
            "up_mbps": 10
        },
        {
            "tag": "urltest",
            "type": "urltest",
            "outbounds": [
                "HysteriaV2"
            ]
        },
        {
            "tag": "direct",
            "type": "direct"
        },
        {
            "tag": "block",
            "type": "block"
        },
        {
            "tag": "dns-out",
            "type": "dns"
        }
    ],
    "route": {
        "auto_detect_interface": true,
        "rule_set": [
            {
                "format": "binary",
                "tag": "geoip-cn",
                "type": "remote",
                "url": "https://raw.githubusercontent.com/SagerNet/sing-geoip/rule-set/geoip-cn.srs"
            },
            {
                "format": "binary",
                "tag": "geosite-cn",
                "type": "remote",
                "url": "https://raw.githubusercontent.com/xmdhs/sing-geosite/rule-set-Loyalsoldier/geosite-geolocation-cn.srs"
            },
            {
                "format": "binary",
                "tag": "AdGuardSDNSFilter",
                "type": "remote",
                "url": "https://raw.githubusercontent.com/xmdhs/sing-box-ruleset/rule-set/AdGuardSDNSFilter.srs"
            },
            {
                "format": "source",
                "tag": "chrome-doh",
                "type": "remote",
                "url": "https://gist.githubusercontent.com/xmdhs/71fc5ff6ef29f5ecaf2c52b8de5c3172/raw/chrome-doh.json"
            }
        ],
        "rules": [
            {
                "outbound": "dns-out",
                "port": 53
            },
            {
                "clash_mode": "direct",
                "outbound": "direct"
            },
            {
                "clash_mode": "global",
                "outbound": "select"
            },
            {
                "ip_is_private": true,
                "outbound": "direct"
            },
            {
                "outbound": "direct",
                "rule_set": "geoip-cn"
            }
        ]
    }
}

我实在不太明白sing-box客户端的dns策略了。

chika0801 commented 3 weeks ago

因为安卓是TUN环境,你WIN用的是httpsocks环境,2个环境处理DNS的原理是不一样的。

具体到sing-box配置中也有一些区别。

v2ray系基本都是用ui界面的

你可以用v2rayN看看它生成的http/socks环境(模式)下的配置

我不明白: 我把安卓的那套配置文件直接给windows使用(唯一的区别是:我只是把tun配置去掉了),为什么就不行了?

这问题我在这 https://github.com/chika0801/sing-box-examples/issues/119#issuecomment-2162646781 应该是说的这意思,如果你看不明白我回的,主要是交流起成本也高,就不能再帮你回复详细了。

我实在不太明白sing-box客户端的dns策略了。

因为这类问题你说复杂吧,它是有一点,需求各方面知识,综合的一个流程,每个人使用的场景可能也不一样,所以没有什么人写文章做视频讲它。都是属于自己试,自己学,遇到有个群有个地方发个帖子问问最好,问不到解决不了也没法。这类的问题。

chika0801 commented 3 weeks ago

你如果什么也不想花太多时间 https://github.com/chika0801/sing-box-examples/tree/main/Tun

这里有配置,你写个批处理来启动sing-box.exe 自己复制这配置,小改改之类,都可以用。但是这些都需求一定的能力知识。

mebest100 commented 3 weeks ago

你如果什么也不想花太多时间 https://github.com/chika0801/sing-box-examples/tree/main/Tun

这里有配置,你写个批处理来启动sing-box.exe 自己复制这配置,小改改之类,都可以用。但是这些都需求一定的能力知识。

我不想使用tun,因为我不需要透明代理。我在你的这个模板上面加上了vps的outbound设置,然后把inbound里面的tun删除,换成了socket proxy监听,但是结果还是不行。

从现在的结果看来,貌似sing-box客户端如果没有tun配置,根本就没法正常工作。

chika0801 commented 3 weeks ago

从现在的结果看来,貌似sing-box客户端如果没有tun配置,根本就没法正常工作。

肯定能工作的,这点不用怀疑作者的水平。

你不用TUN,你1楼提问发的配置我也给你分析了,把它看成客户端,原理也给你说了,匹配条件只有接到到的域名,在客户端侧结合你的配置用不到你客户端配置中你写的DNS,原理也给你说了是那个参数。剩下只有你自己研究学习达成你想要的目的了。

mebest100 commented 3 weeks ago

从现在的结果看来,貌似sing-box客户端如果没有tun配置,根本就没法正常工作。

肯定能工作的,这点不用怀疑作者的水平。

你不用TUN,你1楼提问发的配置我也给你分析了,把它看成客户端,原理也给你说了,匹配条件只有接到到的域名,在客户端侧结合你的配置用不到你客户端配置中你写的DNS,原理也给你说了是那个参数。剩下只有你自己研究学习达成你想要的目的了。

我不是很认同你的看法:

  1. dns远程解析是我的目标,但是我之前一楼的配置并没有哪一点就证明了:我客户端没有用到配置的dns,而是发送到服务端了。如果是这样,那么dns也就能够远程解析了,那么问题也就解决了。
  2. 我并不认为dns是一个很复杂的东西,只不过是这个sing-box项目把简单的问题复杂化了。他的dns配置部分明显都是local本地解析的,绝对不是什么remote远程解析,这个我100%确信。他如果是远程解析dns, 但根本就没有任何转发的地方,怎么可能是远程解析。
  3. tun一定是必须的,这是作者自己说的, https://sing-box.sagernet.org/zh/manual/proxy/client/#virtual-interface 你既然必须全局,又何必搞个socks监听,简直是太好笑了! 我测试了网上别人提供的不下十几种配置,基本没有tun是绝对不能用的。

我当然要怀疑作者水平,客户端做的太烂了,文档也写的很垃圾。

我并不是非要使用他的客户端,我现在clash-meta用的就很好,只是没想到它原生的客户端做的这么烂。

chika0801 commented 3 weeks ago

我再看了一个你1楼配置如下,当时这句话 https://github.com/chika0801/sing-box-examples/issues/119#issuecomment-2160552851 我说错了,你配置入站中写了 "domain_strategy": "prefer_ipv4", 这参数。给你分析下过程,你chrome浏览器用插件对接socks端口2333,sing-box接收到的请求是域名,由于这参数,这域名进配置中的dns部分,走第1个DNS即1.1.1.1,得到域名的IP后,域名和IP同时作为条件,进路由部分进行匹配,如果都没命中,走第1个出站发出,然后发到VPS服务端的请求类型是域名在你客户端解析得到的那个IP。

至于你配置中用到了clash mode,select 这些,我是不用这些的,建议你排除从基础的开始。

另外不建议你喷sing-box作者,只有自己水平不行,别人都是高手,没空理我们这种普通水平用户,教学不是别人的义务。

{
    "log": {
        "level": "info",
        "timestamp": true
    },
    "dns": {      
        "independent_cache": true,
        "rules": [
            {
                "outbound": [
                    "any"
                ],
                "server": "local"
            },
            {
                "disable_cache": true,
                "rule_set": [
                    "AdGuardSDNSFilter",
                    "chrome-doh"
                ],
                "server": "block"
            },
            {
                 "clash_mode": "global",
                "server": "remote"
            },

            {
                "clash_mode": "direct",
                "server": "local"
            },
            {
                "rule_set": "geosite-cn",
                "server": "local"
            }
        ],
        "servers": [
            {
                "address": "https://1.1.1.1/dns-query",
                "detour": "select",
                "tag": "remote"
            },
            {
                "address": "https://223.5.5.5/dns-query",
                "detour": "direct",
                "tag": "local"
            },
            {
                "address": "rcode://success",
                "tag": "block"
            }
        ],
        "strategy": "prefer_ipv4"
    },
    "experimental": {
        "cache_file": {
            "enabled": true
        },
        "clash_api": {
            "external_controller": "127.0.0.1:9090",
            "secret": ""
        }
    },

    "inbounds": [
         {
            "domain_strategy": "prefer_ipv4",
            "listen": "127.0.0.1",
            "listen_port": 2333,
            "tag": "socks-in",
            "type": "socks",
            "users": []
        },
        {
            "domain_strategy": "prefer_ipv4",
            "listen": "127.0.0.1",
            "listen_port": 2334,
            "tag": "mixed-in",
            "type": "mixed",
            "users": []
        }
    ],
    "outbounds": [   
     {
            "tag": "select",
            "type": "selector",
            "default": "TuicV5",
            "outbounds": [
                "TuicV5"
            ]
        },

        {
            "tag": "TuicV5",
            "type": "tuic",
            "server": "xxxxxx",
            "server_port": 13131,
            "uuid": "xxxxxx",
            "password": "xxxxx",           
            "congestion_control": "bbr",
            "tls": {
                "enabled": true,
                "server_name": "xxxxxx",
                "alpn": ["h3"]
            }
        },
        {
            "type": "direct",
            "tag": "direct"
        },
        {
            "type": "block",
            "tag": "block"
        },
        {
            "type": "dns",
            "tag": "dns-out"
        }
    ],
    "route": {
        "auto_detect_interface": true,
        "rule_set": [
            {
                "format": "binary",
                "tag": "geoip-cn",
                "type": "local",
                "path": "./geoip-cn.srs"
            },
            {
                "format": "binary",
                "tag": "geosite-cn",
                "type": "local",
                "path": "./geosite-geolocation-cn.srs"
            },
            {
                "format": "binary",
                "tag": "AdGuardSDNSFilter",
                "type": "local",
                "path": "./AdGuardSDNSFilter.srs"
            },
            {
                "format": "source",
                "tag": "chrome-doh",
                "type": "local",
                "path": "./chrome-doh.json"
            }
        ],
        "rules": [
            {
                "outbound": "dns-out",
                "protocol": "dns"
            },
            {
                "clash_mode": "direct",
                "outbound": "direct"
            },
            {
                "clash_mode": "global",
                "outbound": "select"
            },
            {
                "ip_is_private": true,
                "outbound": "direct"
            },
            {
                "outbound": "direct",
                "rule_set": "geoip-cn"
            }
        ]
    }

}
chika0801 commented 3 weeks ago

只是没想到它原生的客户端做的这么烂。

这个倒是可以提一下,不做生成配置的GUI就是为了筛选用户的,你想想是不是。