Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.12.0-α13 dns.hosts_server的predefined配置无效 #2654

Open
4 of 5 tasks
ib8 opened this issue Feb 28, 2025 · 0 comments
Open
4 of 5 tasks

1.12.0-α13 dns.hosts_server的predefined配置无效 #2654

ib8 opened this issue Feb 28, 2025 · 0 comments

Comments

@ib8
Copy link

ib8 commented Feb 28, 2025

操作系统

Android

系统版本

10

安装类型

sing-box for Android 图形客户端程序

如果您使用图形客户端程序,请提供该程序版本。

1.12.0-alpha13

版本

1.12.0-alpha13

描述

源码似乎并没处理predefined

func NewTransport(ctx context.Context, logger log.ContextLogger, tag string, options option.HostsDNSServerOptions) (adapter.DNSTransport, error) {
var files []*File
if len(options.Path) == 0 {
files = append(files, NewFile(DefaultPath))
} else {
for _, path := range options.Path {
files = append(files, NewFile(filemanager.BasePath(ctx, os.ExpandEnv(path))))
}
}
return &Transport{
TransportAdapter: dns.NewTransportAdapter(C.DNSTypeHosts, tag, nil),
files: files,
}, nil
}
func (t *Transport) Reset() {
}
func (t *Transport) Exchange(ctx context.Context, message *mDNS.Msg) (*mDNS.Msg, error) {
question := message.Question[0]
domain := dns.FqdnToDomain(question.Name)
if question.Qtype == mDNS.TypeA || question.Qtype == mDNS.TypeAAAA {
for _, file := range t.files {
addresses := file.Lookup(domain)
if len(addresses) > 0 {
return dns.FixedResponse(message.Id, question, addresses, C.DefaultDNSTTL), nil
}
}
}
return &mDNS.Msg{
MsgHdr: mDNS.MsgHdr{
Id: message.Id,
Rcode: mDNS.RcodeNameError,
Response: true,
},
Question: []mDNS.Question{question},
}, nil
}

singbox文档中对应的部分dns.hosts_server.predefined

重现方式

启用配置后,浏览器访问pan.baidu.com,访问失败

{
  "log": {
    "disabled": false,
    "output": "g.log",
    "level": "debug",
    "timestamp": true
  },
  "dns": {
    "servers": [
      {
        "tag": "dns_alidns_doh_ip",
        "type": "https",
        "server": "223.5.5.5",
        "server_port": 443,
        "detour": "direct-out"
      },
      {
        "tag": "my_host",
        "type": "hosts",
        "predefined": {
          "pan.baidu.com": "36.110.192.103"
        }
      }
    ],
    "rules": [
      {
        "query_type": [
          "HTTPS",
          "AAAA"
        ],
        "action": "reject"
      },
      {
        "domain": "pan.baidu.com",
        "server": "my_host"
      }
    ],
    "final": "dns_alidns_doh_ip",
    "strategy": "ipv4_only"
  },
  "inbounds": [
    {
      "type": "tun",
      "tag": "tun-in",
      "address": [
        "172.19.0.1/30",
        "fdfe:dcba:9876::1/126"
      ],
      "auto_route": true,
      "strict_route": true,
      "route_address": [
        "0.0.0.0/1",
        "128.0.0.0/1",
        "::/1",
        "8000::/1"
      ]
    }
  ],
  "route": {
    "rules": [
      {
        "port": 53,
        "action": "hijack-dns"
      }
    ],
    "final": "direct-out",
    "auto_detect_interface": true,
    "default_domain_resolver": {
      "server": "dns_alidns_doh_ip"
    }
  },
  "outbounds": [
    {
      "tag": "direct-out",
      "type": "direct"
    }
  ]
}

日志

`
+0800 2025-02-28 16:46:04 INFO [3204139697 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:41065
+0800 2025-02-28 16:46:04 INFO [3204139697 0ms] inbound/tun[tun-in]: inbound packet connection to 172.19.0.2:53
+0800 2025-02-28 16:46:04 DEBUG [3204139697 0ms] router: match[0] port=53 => hijack-dns
+0800 2025-02-28 16:46:04 DEBUG [3204139697 1ms] dns: exchange pan.baidu.com. IN A
+0800 2025-02-28 16:46:04 DEBUG [3204139697 1ms] dns: match[3] domain=pan.baidu.com => route(my_host)
+0800 2025-02-28 16:46:04 DEBUG [3204139697 1ms] dns: exchanged pan.baidu.com NXDOMAIN 0 //找不到域名
+0800 2025-02-28 16:46:04 INFO [1525010190 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:8372
+0800 2025-02-28 16:46:04 INFO [1525010190 0ms] inbound/tun[tun-in]: inbound packet connection to 172.19.0.2:53
+0800 2025-02-28 16:46:04 DEBUG [1525010190 0ms] router: match[0] port=53 => hijack-dns
+0800 2025-02-28 16:46:04 DEBUG [1525010190 0ms] dns: exchange pan.baidu.com. IN HTTPS
+0800 2025-02-28 16:46:04 DEBUG [1525010190 0ms] dns: match[1] query_type=[HTTPS AAAA] => reject
+0800 2025-02-28 16:46:04 INFO [2812618252 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:56284
+0800 2025-02-28 16:46:04 INFO [2812618252 0ms] inbound/tun[tun-in]: inbound packet connection to 172.19.0.2:53
+0800 2025-02-28 16:46:04 DEBUG [2812618252 0ms] router: match[0] port=53 => hijack-dns
+0800 2025-02-28 16:46:04 DEBUG [2812618252 0ms] dns: exchange pan.baidu.com. IN AAAA
+0800 2025-02-28 16:46:04 DEBUG [2812618252 0ms] dns: match[1] query_type=[HTTPS AAAA] => reject
+0800 2025-02-28 16:46:04 INFO [4202478433 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:18030
+0800 2025-02-28 16:46:04 INFO [4202478433 0ms] inbound/tun[tun-in]: inbound packet connection to 172.19.0.2:53
+0800 2025-02-28 16:46:04 DEBUG [4202478433 0ms] router: match[0] port=53 => hijack-dns
+0800 2025-02-28 16:46:04 DEBUG [4202478433 0ms] dns: exchange pan.baidu.com. IN A
+0800 2025-02-28 16:46:04 DEBUG [4202478433 0ms] dns: match[3] domain=pan.baidu.com => route(my_host)
+0800 2025-02-28 16:46:04 DEBUG [4202478433 1ms] dns: exchanged pan.baidu.com NXDOMAIN 0 //找不到域名
+0800 2025-02-28 16:46:04 INFO [1401356791 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:48947
+0800 2025-02-28 16:46:04 INFO [1401356791 0ms] inbound/tun[tun-in]: inbound packet connection to 172.19.0.2:53
+0800 2025-02-28 16:46:04 DEBUG [1401356791 0ms] router: match[0] port=53 => hijack-dns
+0800 2025-02-28 16:46:04 INFO [3098572367 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:2670
+0800 2025-02-28 16:46:04 DEBUG [1401356791 0ms] dns: exchange pan.baidu.com. IN AAAA
+0800 2025-02-28 16:46:04 DEBUG [1401356791 1ms] dns: match[1] query_type=[HTTPS AAAA] => reject
+0800 2025-02-28 16:46:04 INFO [3433453450 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:59747
+0800 2025-02-28 16:46:04 INFO [3433453450 0ms] inbound/tun[tun-in]: inbound packet connection to 172.19.0.2:53
+0800 2025-02-28 16:46:04 DEBUG [3433453450 0ms] router: match[0] port=53 => hijack-dns
+0800 2025-02-28 16:46:04 DEBUG [3433453450 0ms] dns: exchange pan.baidu.com. IN HTTPS
+0800 2025-02-28 16:46:04 DEBUG [3433453450 0ms] dns: match[1] query_type=[HTTPS AAAA] => reject
+0800 2025-02-28 16:46:04 INFO [3098572367 1ms] inbound/tun[tun-in]: inbound packet connection to 172.19.0.2:53
+0800 2025-02-28 16:46:04 DEBUG [3098572367 2ms] router: match[0] port=53 => hijack-dns
`

支持我们

完整性要求

  • 我保证阅读了文档,了解所有我编写的配置文件项的含义,而不是大量堆砌看似有用的选项或默认值。
  • 我保证提供了可以在本地重现该问题的服务器、客户端配置文件与流程,而不是一个脱敏的复杂客户端配置文件。
  • 我保证提供了可用于重现我报告的错误的最简配置,而不是依赖远程服务器、TUN、图形界面客户端或者其他闭源软件。
  • 我保证提供了完整的配置文件与日志,而不是出于对自身智力的自信而仅提供了部分认为有用的部分。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant