SagerNet / sing-box

The universal proxy platform
https://sing-box.sagernet.org/
Other
18.82k stars 2.25k forks source link

route中只有cn ip规则,但是不知道为什么域名进来后没有触发内置dns解析,而是直接走了默认outbound proxy #286

Closed GeorgeRudd closed 1 year ago

GeorgeRudd commented 1 year ago

Welcome

Description of the problem

route中只有cn ip规则,但是不知道为什么域名进来后没有触发内置dns解析,而是直接走了默认outbound proxy

请问怎么设置可以实现v2ray routing "domainStrategy": "IPIfNonMatch" 的那种效果?

Version of sing-box

```console $ sing-box version sing-box version 1.1.1 Environment: go1.19.4 windows/amd64 Tags: with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api Revision: 8afb8ca7eb8aa52e7a3b44253be0f3df9474fa64 CGO: disabled ```

Server and client configuration file

```console { "log": { "disabled": false, "level": "info", "timestamp": false }, "dns": { "servers": [ { "tag": "1.1.1.1", "address": "1.1.1.1", "detour": "proxy-out" }, { "tag": "223.5.5.5", "address": "223.5.5.5", "detour": "direct-out" } ], "rules": [ { "geosite": "cn", "server": "223.5.5.5" } ], "final": "1.1.1.1", "strategy": "ipv4_only" }, "inbounds": [ { "type": "http", "tag": "http-in", "listen": "::", "listen_port": 10809, "sniff": true, "set_system_proxy": false } ], "outbounds": [ { "type": "vmess", "tag": "proxy-out", "server": "ip", "server_port": 80, "uuid": "uuid", "security": "auto", "alter_id": 0, "packet_encoding": "xudp", "transport": { "type": "ws", "path": "/path", "headers": { "Host": "domain.com" }, "max_early_data": 2048, "early_data_header_name": "Sec-WebSocket-Protocol" } }, { "type": "direct", "tag": "direct-out", "domain_strategy": "ipv4_only" }, { "type": "block", "tag": "block" } ], "route": { "geoip": { "path": "geoip.db" }, "geosite": { "path": "geosite.db" }, "rules": [ { "geoip": [ "cn", "private" ], "outbound": "direct-out" } ], "final": "proxy-out", "auto_detect_interface": true } } ```

Server and client log file

```console INFO[0000] router: loaded geoip database: 259 codes INFO[0000] router: loaded geosite database: 1318 codes INFO[0000] router: updated default interface WLAN, index 16 INFO[0000] inbound/http[http-in]: tcp server started at [::]:10809 INFO[0000] sing-box started (0.66s) INFO[0001] [111817524] inbound/http[http-in]: inbound connection from 127.0.0.1:1792 INFO[0001] [111817524] inbound/http[http-in]: inbound connection to sohu.com:443 INFO[0001] [111817524] outbound/vmess[proxy-out]: outbound connection to sohu.com:443 INFO[0001] [2063602170] inbound/http[http-in]: inbound connection from 127.0.0.1:1794 INFO[0001] [2063602170] inbound/http[http-in]: inbound connection to sohu.com:443 INFO[0001] [2063602170] outbound/vmess[proxy-out]: outbound connection to sohu.com:443 INFO[0001] [1750303998] inbound/http[http-in]: inbound connection from 127.0.0.1:1796 INFO[0001] [1750303998] inbound/http[http-in]: inbound connection to alive.github.com:443 INFO[0001] [1750303998] outbound/vmess[proxy-out]: outbound connection to alive.github.com:443 INFO[0002] [2473641796] inbound/http[http-in]: inbound connection from 127.0.0.1:1799 INFO[0002] [2473641796] inbound/http[http-in]: inbound connection to sohu.com:443 INFO[0002] [2473641796] outbound/vmess[proxy-out]: outbound connection to sohu.com:443 INFO[0003] [3219288708] inbound/http[http-in]: inbound connection from 127.0.0.1:1801 INFO[0003] [3219288708] inbound/http[http-in]: inbound connection to sohu.com:443 INFO[0003] [3219288708] outbound/vmess[proxy-out]: outbound connection to sohu.com:443 INFO[0008] [4150821719] inbound/http[http-in]: inbound connection from 127.0.0.1:1805 INFO[0008] [4150821719] inbound/http[http-in]: inbound connection to sohu.com:443 INFO[0008] [4150821719] outbound/vmess[proxy-out]: outbound connection to sohu.com:443 INFO[0008] [2587273940] inbound/http[http-in]: inbound connection from 127.0.0.1:1807 INFO[0008] [2587273940] inbound/http[http-in]: inbound connection to sohu.com:443 INFO[0008] [2587273940] outbound/vmess[proxy-out]: outbound connection to sohu.com:443 ```

同时服务端xray的日志显示sohu.com block,应该可以判断出是直接到服务端了

GeorgeRudd commented 1 year ago

将上面配置的http入站部分删掉,换成tun入站,其他不变,可以正常访问sohu

    "inbounds": [
        {
            "type": "tun",
            "tag": "tun-in",
            "inet4_address": "172.19.0.1/30",
            "inet6_address": "fdfe:dcba:9876::1/126",
            "auto_route": true,
            "strict_route": true,
            "sniff": true
        }
    ]
GeorgeRudd commented 1 year ago

@chika0801 @FranzKafkaYu 麻烦帮忙看下 谢谢

chika0801 commented 1 year ago

我没在客户端用过sing-box为core

你尝试修改入站部分

    "inbounds": [
        {
            "type": "http",
            "tag": "http-in",
            "listen": "::",
            "listen_port": 10809,
            "sniff": true,
                        "domain_strategy": "ipv4_only",
            "set_system_proxy": false
        }
    ],

"domain_strategy": "ipv4_only" 试试加这个参数,我在服务器端用的。进来的请求sniff还原成域名,根据domain_strategy要把这域名解析成IP,我看你写了DNS部分,这域名如何走这DNS部分我没研究(我在服务器用没写DNS部分)。 这域名解析成IP后,得到的这IP,进入路由模块,命中你的IP规则。

j0ck1e commented 6 months ago

1631

@chika0801 我遇到了类似的问题,当我使用domain_strategy后出站访问出现异常,outbound直接去连接ip地址而不是域名,我尝试在inbound中加入sniff参数但是没有用