From a8f36fd6a5139e577c34d8196145a5289d70c9a3 Mon Sep 17 00:00:00 2001 From: code-server-usr Date: Wed, 2 Sep 2026 22:56:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20check=5Fipv6=5Fprecedence?= =?UTF-8?q?=5Fwarning=20=E5=87=BD=E6=95=B0=E4=BB=A5=E6=A3=80=E6=9F=A5=20IP?= =?UTF-8?q?v6=20=E4=BC=98=E5=85=88=E7=BA=A7=E9=85=8D=E7=BD=AE=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E5=87=BA=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/1.sh b/1.sh index cdd3edc..4b5bf45 100644 --- a/1.sh +++ b/1.sh @@ -174,6 +174,48 @@ detect_cn_network() { return 1 } +check_ipv6_precedence_warning() { + local gai_conf=/etc/gai.conf + local ipv6_check_url="https://api64.ipify.org" + local has_external_ipv6=false + + # Force an IPv6-only request so an IPv4 connection cannot count as success. + if command -v curl >/dev/null 2>&1; then + if curl -6 --noproxy '*' -fsS --connect-timeout 3 --max-time 5 \ + "$ipv6_check_url" >/dev/null 2>&1; then + has_external_ipv6=true + fi + elif command -v wget >/dev/null 2>&1; then + if wget -6 -q -T 5 -O /dev/null "$ipv6_check_url" >/dev/null 2>&1; then + has_external_ipv6=true + fi + fi + + [ "$has_external_ipv6" = true ] && return 0 + [ -r "$gai_conf" ] || return 0 + + # Warn only when the matching rule exists in a commented form and is not + # overridden by an active copy of the same rule. + if awk ' + { + line = $0 + sub(/^[[:space:]]*/, "", line) + is_comment = (line ~ /^#/) + sub(/^#[[:space:]]*/, "", line) + if (line ~ /^precedence[[:space:]]+::ffff:0:0\/96[[:space:]]+100([[:space:]]|$)/) { + if (is_comment) { + commented = 1 + } else { + active = 1 + } + } + } + END { exit !(commented && !active) } + ' "$gai_conf"; then + print_yellow "警告:本机没有外网 IPv6,且 /etc/gai.conf 中 precedence ::ffff:0:0/96 100 仍处于注释状态。" + fi +} + check_container_runtime() { if [ -x "$(command -v podman)" ]; then echo "检测到 Podman 已安装,跳过 Docker 相关配置" @@ -332,5 +374,6 @@ install_docker # start_watchtower # install_zram sysctl_config +check_ipv6_precedence_warning # source <(curl -fsSL scripts.oo1.dev/nezha-v1.sh)