feat: add prefer_go option for local DNS and enhance system compatibility. https://github.com/fscarmen/sing-box/issues/280

- Set `prefer_go: true` for the local DNS server to resolve issues where `systemd-resolved` might be unavailable or inaccessible on certain Linux distributions (e.g., Alpine Linux, lightweight Debian).

- Improve DNS resolution reliability by prioritizing Go's internal resolver over the system's C library or DBus interfaces.

功能:为本地 DNS 添加 prefer_go 选项并增强系统兼容性

- 为本地 (local) DNS 服务器设置 `prefer_go: true`,以解决在某些 Linux 发行版(如 Alpine Linux、精简版 Debian)上因缺少 `systemd-resolved` 服务而导致的解析失败或报错问题。

- 通过优先使用 Go 内置的解析器而非系统的 C 库或 DBus 接口,提升 DNS 解析的可靠性和一致性。
This commit is contained in:
fscarmen
2026-03-27 10:56:29 +08:00
committed by GitHub
parent ac1e83558d
commit 87bb449303
+8 -3
View File
@@ -1542,8 +1542,9 @@ sing-box_variables() {
}
check_dependencies() {
# 如果是 Alpine,先升级 wget ,安装 systemctl-py 版
# 如果是 Alpine,先升级 wget
if [ "$SYSTEM" = 'Alpine' ]; then
IS_PREFER_GO=true
local CHECK_WGET=$(wget 2>&1 | sed -n 1p)
grep -qi 'busybox' <<< "$CHECK_WGET" && ${PACKAGE_INSTALL[int]} wget >/dev/null 2>&1
local DEPS_CHECK=("bash" "rc-update" "iptables" "ip6tables")
@@ -1556,6 +1557,9 @@ check_dependencies() {
${PACKAGE_UPDATE[int]} >/dev/null 2>&1
${PACKAGE_INSTALL[int]} ${DEPS_ALPINE[@]} >/dev/null 2>&1
fi
else
# 非 Alpine 系统,检查 systemd-resolved 状态,用于 DNS 配置里的 prefer_go 字段
[ -x "$(type -p systemctl)" ] && systemctl is-active --quiet systemd-resolved && IS_PREFER_GO=false || IS_PREFER_GO=true
fi
# 检测 Linux 系统的依赖,升级库并重新安装依赖
@@ -1941,7 +1945,8 @@ EOF
"dns":{
"servers":[
{
"type":"local"
"type":"local",
"prefer_go": ${IS_PREFER_GO}
}
],
"strategy": "${STRATEGY}"
@@ -4168,4 +4173,4 @@ elif [ "$IS_FAST_INSTALL" = 'is_fast_install' ]; then
else
menu_setting
menu
fi
fi