net: 修复特殊情况下 dns 写入后又被清空

This commit is contained in:
bin456789 2025-05-20 11:12:58 +08:00
parent 8a3ef0c875
commit 8895d23082
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B

View File

@ -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