From 30174545b08ec7d933ac48bfbbf1e47f24a3636d Mon Sep 17 00:00:00 2001 From: bin456789 Date: Sun, 10 Sep 2023 22:23:02 +0800 Subject: [PATCH] =?UTF-8?q?core:=20workaround=20ipv6=20=E4=B8=8D=E8=81=94?= =?UTF-8?q?=E7=BD=91=E6=97=B6=E6=97=A0=E6=B3=95=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=20alpine=20=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alpine-network.sh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/alpine-network.sh b/alpine-network.sh index e8ac34d..ac5e96d 100644 --- a/alpine-network.sh +++ b/alpine-network.sh @@ -48,6 +48,8 @@ get_ipv4_entry && dhcpv4=true || dhcpv4=false get_ipv6_entry | grep /128 && dhcpv6=true || dhcpv6=false # 检测是否有 slaac +# 也可以有地址就行,不管是slaac或者dhcpv6 +# 因为会在trans里判断 slaac=false for i in $(seq 10 -1 0); do echo "waiting slaac for ${i}s" @@ -68,10 +70,9 @@ fi # 检查 ipv4/ipv6 是否连接联网 ipv4_has_internet=false ipv6_has_internet=false -for i in $(seq 10); do - is_have_ipv4 && ipv4_test_complete=false || ipv4_test_complete=true - is_have_ipv6 && ipv6_test_complete=false || ipv6_test_complete=true - +is_have_ipv4 && ipv4_test_complete=false || ipv4_test_complete=true +is_have_ipv6 && ipv6_test_complete=false || ipv6_test_complete=true +for i in $(seq 5); do if ! $ipv4_test_complete && nslookup www.qq.com $ipv4_dns1; then ipv4_has_internet=true ipv4_test_complete=true @@ -94,11 +95,20 @@ if { $dhcpv4 || $dhcpv6 || $slaac; } && [ ! -e /etc/resolv.conf ]; then sleep 5 fi -# 如果ipv4/ipv6不联网,则删除该协议的dns -if [ -e /etc/resolv.conf ]; then - if $ipv4_has_internet && ! $ipv6_has_internet; then +# 如果有ipv6地址,但ipv6没网络 +# alpine只会用ipv6下载apk,而不用会ipv4下载 +# 所以要删除不联网协议的ip和dns + +# 甲骨文云管理面板添加ipv6地址然后取消 +# 依然会分配ipv6地址,但ipv6没网络 +if $ipv4_has_internet && ! $ipv6_has_internet; then + ip -6 addr flush scope global dev eth0 + if [ -e /etc/resolv.conf ]; then sed -i '/^[[:blank:]]*nameserver[[:blank:]].*:/d' /etc/resolv.conf - elif ! $ipv4_has_internet && $ipv6_has_internet; then + fi +elif ! $ipv4_has_internet && $ipv6_has_internet; then + ip -4 addr flush scope global dev eth0 + if [ -e /etc/resolv.conf ]; then sed -i '/^[[:blank:]]*nameserver[[:blank:]].*\./d' /etc/resolv.conf fi fi