core: 添加 ra dns

This commit is contained in:
bin456789 2023-08-22 23:14:13 +08:00
parent 2fcc131ecb
commit c30c5ecc4c
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
2 changed files with 10 additions and 2 deletions

View File

@ -77,9 +77,9 @@ fi
# 如果ipv4/ipv6不联网则删除该协议的dns # 如果ipv4/ipv6不联网则删除该协议的dns
if $ipv4_has_internet && ! $ipv6_has_internet; then if $ipv4_has_internet && ! $ipv6_has_internet; then
sed -i '/:/d' /etc/resolv.conf sed -i '/^[[:blank:]]*nameserver[[:blank:]].*:/d' /etc/resolv.conf
elif ! $ipv4_has_internet && $ipv6_has_internet; then elif ! $ipv4_has_internet && $ipv6_has_internet; then
sed -i '/\./d' /etc/resolv.conf sed -i '/^[[:blank:]]*nameserver[[:blank:]].*\./d' /etc/resolv.conf
fi fi
# 如果联网了,但没获取到默认 DNS则添加我们的 DNS # 如果联网了,但没获取到默认 DNS则添加我们的 DNS

View File

@ -279,6 +279,7 @@ EOF
echo "$ra" | cat -n echo "$ra" | cat -n
echo "$ra" | grep 'Autonomous address conf' | grep Yes && is_slaac=true echo "$ra" | grep 'Autonomous address conf' | grep Yes && is_slaac=true
echo "$ra" | grep 'Stateful address conf' | grep Yes && is_dhcpv6=true echo "$ra" | grep 'Stateful address conf' | grep Yes && is_dhcpv6=true
ra_dns=$(echo "$ra" | grep 'Recursive DNS server' | cut -d: -f2- | xargs)
fi fi
# 删除临时安装的软件,不然会带到新系统 # 删除临时安装的软件,不然会带到新系统
@ -306,6 +307,13 @@ EOF
fi fi
fi fi
# udhcpc/dhcpcd + slaac不会自动写入ra dns
# 如果有ra dns则删除自己添加的dns再添加ra dns
if [ -n "$ra_dns" ]; then
sed -i '/^[[:blank:]]*nameserver[[:blank:]].*:/d' /etc/resolv.conf
echo "nameserver $ra_dns" >>/etc/resolv.conf
fi
ip addr ip addr
cat -n /etc/network/interfaces cat -n /etc/network/interfaces
rc-update add networking boot rc-update add networking boot