From 8895d230829efc351b73ed7502b99224ef4459a0 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Tue, 20 May 2025 11:12:58 +0800 Subject: [PATCH] =?UTF-8?q?net:=20=E4=BF=AE=E5=A4=8D=E7=89=B9=E6=AE=8A?= =?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8B=20dns=20=E5=86=99=E5=85=A5=E5=90=8E?= =?UTF-8?q?=E5=8F=88=E8=A2=AB=E6=B8=85=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- initrd-network.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/initrd-network.sh b/initrd-network.sh index 2c295a8..d6c0e20 100644 --- a/initrd-network.sh +++ b/initrd-network.sh @@ -466,11 +466,16 @@ if ! $ipv6_has_internet; then fi # 如果联网了,但没获取到默认 DNS,则添加我们的 DNS -if $ipv4_has_internet && ! { [ -e /etc/resolv.conf ] && is_have_ipv4_dns; }; then + +# 有一种情况是,多网卡,且能上网的网卡先完成了这个脚本,不能上网的网卡后完成 +# 无法上网的网卡通过 flush_ipv4_config 删除了不能上网的 IP 和 dns +# (原计划是删除无法上网的网卡 dhcp4 获取的 dns,但实际上无法区分) +# 因此这里直接添加 dns,不判断是否联网 +if ! is_have_ipv4_dns; then echo "nameserver $ipv4_dns1" >>/etc/resolv.conf echo "nameserver $ipv4_dns2" >>/etc/resolv.conf fi -if $ipv6_has_internet && ! { [ -e /etc/resolv.conf ] && is_have_ipv6_dns; }; then +if ! is_have_ipv6_dns; then echo "nameserver $ipv6_dns1" >>/etc/resolv.conf echo "nameserver $ipv6_dns2" >>/etc/resolv.conf fi