feat: SNI默认使用的DNS,可在 `DNS服务管理` 中配置。

release-2.0.0.2
王良 2025-03-10 15:53:32 +08:00
parent 60386edc07
commit 7f86c455b0
3 changed files with 15 additions and 2 deletions

View File

@ -393,6 +393,7 @@ const defaultConfig = {
type: 'https',
server: 'https://doh.360.cn/dns-query',
cacheSize: 1000,
forSNI: true,
},
rubyfish: {
type: 'https',

View File

@ -1,4 +1,5 @@
const matchUtil = require('../../utils/util.match')
const log = require('../../utils/util.log.server')
const DNSOverPreSetIpList = require('./preset.js')
const DNSOverHTTPS = require('./https.js')
const DNSOverTLS = require('./tls.js')
@ -72,10 +73,19 @@ module.exports = {
dnsMap[provider] = new DNSOverUDP(provider, conf.cacheSize, preSetIpList, server, port)
}
}
if (conf.forSNI || conf.forSni) {
dnsMap.ForSNI = dnsMap[provider]
}
}
// 创建预设IP的DNS
dnsMap.PreSet = new DNSOverPreSetIpList(preSetIpList)
if (dnsMap.ForSNI == null) {
dnsMap.ForSNI = dnsMap.PreSet
}
log.info(`设置SNI默认使用的DNS为 '${dnsMap.ForSNI.dnsName}'当某个域名配置了SNI但未配置DNS时将默认使用该DNS`)
return dnsMap
},

View File

@ -116,9 +116,11 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
if (dnsConfig && dnsConfig.dnsMap) {
let dns = DnsUtil.hasDnsLookup(dnsConfig, rOptions.hostname)
if (!dns && rOptions.servername) {
dns = dnsConfig.dnsMap.quad9
dns = dnsConfig.dnsMap.ForSNI
if (dns) {
log.info(`域名 ${rOptions.hostname} 在dns中未配置但使用了 sni: ${rOptions.servername}, 必须使用dns现默认使用 'quad9' DNS.`)
log.info(`域名 ${rOptions.hostname} 在dns中未配置但使用了 sni: ${rOptions.servername}, 必须使用dns现默认使用 '${dns.dnsName}' DNS.`)
} else {
log.warn(`域名 ${rOptions.hostname} 在dns中未配置但使用了 sni: ${rOptions.servername}且DNS服务管理中也未指定SNI默认使用的DNS。`)
}
}
if (dns) {