mirror of
https://github.com/fscarmen/sing-box.git
synced 2026-08-10 17:55:16 +08:00
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:
+7
-2
@@ -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}"
|
||||
|
||||
Reference in New Issue
Block a user