Skip to content

Commit

Permalink
Sing-box, Clash DNS revision.
Browse files Browse the repository at this point in the history
  • Loading branch information
bia-pain-bache committed Jan 17, 2025
1 parent add559f commit 33c5ad0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
20 changes: 8 additions & 12 deletions src/cores-configs/clash.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ async function buildClashDNS (proxySettings, isChain, isWarp) {
"nameserver": isWarp
? warpRemoteDNS.map(dns => isChain ? `${dns}#💦 Warp - Best Ping 🚀` : `${dns}#✅ Selector`)
: [isChain ? `${remoteDNS}#proxy-1` : `${remoteDNS}#✅ Selector`],
"proxy-server-nameserver": [`${localDNS}#DIRECT`]
"proxy-server-nameserver": [`${localDNS}#DIRECT`],
"nameserver-policy": {
"raw.githubusercontent.com": `${localDNS}#DIRECT`,
"time.apple.com": `${localDNS}#DIRECT`
}
};

if (isChain && !isWarp) {
const chainOutboundServer = JSON.parse(outProxyParams).server;
if (isDomain(chainOutboundServer)) dns["nameserver-policy"] = {
[chainOutboundServer]: `${remoteDNS}#proxy-1`
};
if (isDomain(chainOutboundServer)) dns["nameserver-policy"][chainOutboundServer] = `${remoteDNS}#proxy-1`;
}

if (isBypass) {
Expand All @@ -55,17 +57,11 @@ async function buildClashDNS (proxySettings, isChain, isWarp) {
rule && geosites.push(geosite)
});

dns["nameserver-policy"] = {
...dns["nameserver-policy"],
[`rule-set:${geosites.join(',')}`]: [`${localDNS}#DIRECT`]
};
dns["nameserver-policy"][`rule-set:${geosites.join(',')}`] = [`${localDNS}#DIRECT`];
}

customBypassRulesDomains.forEach( domain => {
dns["nameserver-policy"] = {
...dns["nameserver-policy"],
[`+.${domain}`]: [`${localDNS}#DIRECT`]
};
dns["nameserver-policy"][`+.${domain}`] = [`${localDNS}#DIRECT`];
});

const dohHost = getDomain(remoteDNS);
Expand Down
15 changes: 11 additions & 4 deletions src/cores-configs/sing-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ function buildSingBoxDNS (proxySettings, outboundAddrs, isWarp, remoteDNSDetour)
{
address: isWarp ? "1.1.1.1" : remoteDNS,
address_resolver: dohHost.isHostDomain ? "doh-resolver" : "dns-direct",
strategy: isIPv6 ? "prefer_ipv4" : "ipv4_only",
detour: remoteDNSDetour,
tag: "dns-remote"
},
{
address: localDNS,
strategy: isIPv6 ? "prefer_ipv4" : "ipv4_only",
detour: "direct",
tag: "dns-direct"
},
Expand All @@ -58,8 +56,7 @@ function buildSingBoxDNS (proxySettings, outboundAddrs, isWarp, remoteDNSDetour)

dohHost.isHostDomain && !isWarp && servers.push({
address: 'https://8.8.8.8/dns-query',
strategy: isIPv6 ? "prefer_ipv4" : "ipv4_only",
detour: remoteDNSDetour,
detour: "direct",
tag: "doh-resolver"
});

Expand All @@ -80,6 +77,13 @@ function buildSingBoxDNS (proxySettings, outboundAddrs, isWarp, remoteDNSDetour)

const rules = [
outboundRule,
{
domain: [
"raw.githubusercontent.com",
"time.apple.com"
],
server: "dns-direct"
},
{
clash_mode: "Direct",
server: "dns-direct"
Expand Down Expand Up @@ -589,6 +593,7 @@ export async function getSingBoxWarpConfig (request, env, client) {
const {rules, rule_set} = buildSingBoxRoutingRules(proxySettings);
config.dns.servers = dnsObject.servers;
config.dns.rules = dnsObject.rules;
config.dns.strategy = proxySettings.warpEnableIPv6 ? "prefer_ipv4" : "ipv4_only";
if (dnsObject.fakeip) config.dns.fakeip = dnsObject.fakeip;
config.route.rules = rules;
config.route.rule_set = rule_set;
Expand Down Expand Up @@ -667,6 +672,7 @@ export async function getSingBoxCustomConfig(request, env, isFragment) {
config.dns.servers = dnsObject.servers;
config.dns.rules = dnsObject.rules;
if (dnsObject.fakeip) config.dns.fakeip = dnsObject.fakeip;
config.dns.strategy = enableIPv6 ? "prefer_ipv4" : "ipv4_only";
config.route.rules = rules;
config.route.rule_set = rule_set;
const selector = config.outbounds[0];
Expand Down Expand Up @@ -803,6 +809,7 @@ const singboxConfigTemp = {
},
{
type: "direct",
domain_strategy: "ipv4_only",
tag: "direct"
},
{
Expand Down

0 comments on commit 33c5ad0

Please sign in to comment.