From aa79eac0a09d5d5b584a6da77d6f962877d54395 Mon Sep 17 00:00:00 2001 From: mack-a <57424792+mack-a@users.noreply.github.com> Date: Fri, 26 Jan 2024 15:22:27 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=84=9A=E6=9C=AC):=20sing-box=E6=94=AF?= =?UTF-8?q?=E6=8C=81dns=E5=88=86=E6=B5=81=E3=80=81=E8=AE=A2=E9=98=85?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=80=E6=9C=BA=E8=87=AA=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 137 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 89 insertions(+), 48 deletions(-) diff --git a/install.sh b/install.sh index 68514c1d..23d6f192 100644 --- a/install.sh +++ b/install.sh @@ -5826,7 +5826,7 @@ ipv6Routing() { if [[ -n "${singBoxConfigPath}" ]]; then addSingBoxRouteRule "IPv6_out" "${domainList}" "IPv6_route" - + addSingBoxOutbound direct addSingBoxOutbound IPv6_out addSingBoxOutbound IPv4_out fi @@ -6400,7 +6400,7 @@ routingToolsMenu() { echoContent yellow "4.Socks5分流" echoContent yellow "5.DNS分流" # echoContent yellow "6.VMess+WS+TLS分流" - # echoContent yellow "7.SNI反向代理分流" + echoContent yellow "7.SNI反向代理分流" read -r -p "请选择:" selectType @@ -6418,9 +6418,6 @@ routingToolsMenu() { socks5Routing ;; 5) - if [[ -n "${singBoxConfigPath}" ]]; then - echoContent red "\n ---> 此功能不支持Hysteria2、Tuic" - fi dnsRouting 1 ;; # 6) @@ -7039,62 +7036,105 @@ EOF fi exit 0 } -# 设置dns -setUnlockDNS() { - read -r -p "请输入分流的DNS:" setDNS - if [[ -n ${setDNS} ]]; then - echoContent red "==============================================================" - echoContent yellow "录入示例:netflix,disney,hulu" - echoContent yellow "默认方案请输入1,默认方案包括以下内容" - echoContent yellow "netflix,bahamut,hulu,hbo,disney,bbc,4chan,fox,abema,dmm,niconico,pixiv,bilibili,viu" - read -r -p "请按照上面示例录入域名:" domainList - if [[ "${domainList}" == "1" ]]; then - cat <${configPath}11_dns.json + +# 添加xray dns 配置 +addXrayDNSConfig() { + local ip=$1 + local domainList=$2 + local domains=[] + while read -r line; do + local geositeStatus + geositeStatus=$(curl -s "https://api.github.com/repos/v2fly/domain-list-community/contents/data/${line}" | jq .message) + + if [[ "${geositeStatus}" == "null" ]]; then + domains=$(echo "${domains}" | jq -r '. += ["geosite:'"${line}"'"]') + else + domains=$(echo "${domains}" | jq -r '. += ["domain:'"${line}"'"]') + fi + done < <(echo "${domainList}" | tr ',' '\n') + + if [[ "${coreInstallType}" == "1" ]]; then + + cat <${configPath}11_dns.json { "dns": { "servers": [ { - "address": "${setDNS}", + "address": "${ip}", "port": 53, - "domains": [ - "geosite:netflix", - "geosite:bahamut", - "geosite:hulu", - "geosite:hbo", - "geosite:disney", - "geosite:bbc", - "geosite:4chan", - "geosite:fox", - "geosite:abema", - "geosite:dmm", - "geosite:niconico", - "geosite:pixiv", - "geosite:bilibili", - "geosite:viu" - ] + "domains": ${domains} }, "localhost" ] } } EOF - elif [[ -n "${domainList}" ]]; then - cat <${configPath}11_dns.json + fi +} + +# 添加sing-box dns配置 +addSingBoxDNSConfig() { + local ip=$1 + local domainList=$2 + + local rules= + rules=$(initSingBoxRules "${domainList}" "dns") + # domain精确匹配规则 + local domainRules= + domainRules=$(echo "${rules}" | jq .domainRules) + + # ruleSet规则集 + local ruleSet= + ruleSet=$(echo "${rules}" | jq .ruleSet) + + # ruleSet规则tag + local ruleSetTag=[] + if [[ "$(echo "${ruleSet}" | jq '.|length')" != "0" ]]; then + ruleSetTag=$(echo "${ruleSet}" | jq '.|map(.tag)') + fi + if [[ -n "${singBoxConfigPath}" ]]; then + cat <"${singBoxConfigPath}dns.json" { - "dns": { - "servers": [ - { - "address": "${setDNS}", - "port": 53, - "domains": [ - "geosite:${domainList//,/\",\"geosite:}" - ] - }, - "localhost" - ] - } + "dns": { + "servers": [ + { + "tag": "local", + "address": "local" + }, + { + "tag": "dnsRouting", + "address": "${ip}" + } + ], + "rules": [ + { + "rule_set": ${ruleSetTag}, + "domain": ${domainRules}, + "server":"dnsRouting" + } + ] + }, + "route":{ + "rule_set":${ruleSet} + } } EOF + fi +} +# 设置dns +setUnlockDNS() { + read -r -p "请输入分流的DNS:" setDNS + if [[ -n ${setDNS} ]]; then + echoContent red "==============================================================" + echoContent yellow "录入示例:netflix,disney,hulu" + read -r -p "请按照上面示例录入域名:" domainList + + if [[ "${coreInstallType}" == "1" ]]; then + addXrayDNSConfig "${setDNS}" "${domainList}" + fi + + if [[ -n "${singBoxConfigPath}" ]]; then + addSingBoxDNSConfig "${setDNS}" "${domainList}" fi reloadCore @@ -7600,6 +7640,7 @@ server { EOF handleNginx stop handleNginx start + systemctl enable nginx fi if [[ -z $(pgrep -f "nginx") ]]; then handleNginx start @@ -8657,7 +8698,7 @@ menu() { cd "$HOME" || exit echoContent red "\n==============================================================" echoContent green "作者:mack-a" - echoContent green "当前版本:v3.2.1" + echoContent green "当前版本:v3.2.2" echoContent green "Github:https://github.com/mack-a/v2ray-agent" echoContent green "描述:八合一共存脚本\c" showInstallStatus