新增 check_ipv6_precedence_warning 函数以检查 IPv6 优先级配置并发出警告
This commit is contained in:
1 parent
dcc9e0d96b
commit
a8f36fd6a5
1 file changed
+43
@@ -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)
|
||||
Reference in new issue
Block a user