diff --git a/README.md b/README.md index 2a50189..fcf680b 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ - 开设独立IPV4地址的虚拟机时,尝试增加自动附加IPV6地址的功能 - 增加一键开设纯IPV6虚拟机、纯IPV6容器的脚本 +- 修复可能的dns-nameservers存在多行导致网络异常的问题 [更新日志](CHANGELOG.md) diff --git a/scripts/install_pve.sh b/scripts/install_pve.sh index c6aef7b..391ebb4 100644 --- a/scripts/install_pve.sh +++ b/scripts/install_pve.sh @@ -212,6 +212,9 @@ if ! grep -q "iface lo inet loopback" "/etc/network/interfaces"; then chattr +i /etc/network/interfaces _blue "Can not find 'iface lo inet loopback' in /etc/network/interfaces, add it" fi +chattr -i /etc/network/interfaces +echo " " >> /etc/network/interfaces +chattr +i /etc/network/interfaces # 合并文件 if [ -d "/etc/network/interfaces.d/" ]; then if [ ! -f "/etc/network/interfaces" ]; then @@ -338,6 +341,26 @@ if ! grep -q "auto ${interface}" /etc/network/interfaces; then echo "auto ${interface}" >> /etc/network/interfaces chattr +i /etc/network/interfaces fi +# 删除可能的多个dns-nameservers的行只保留一行 +dns_lines=$(grep -c "dns-nameservers" /etc/network/interfaces) +if [ $dns_lines -gt 1 ]; then + rm -rf /tmp/interfaces.tmp + original_lines=$(wc -l < /etc/network/interfaces) + current_dns_lines=0 + while read -r line; do + if echo "$line" | grep -q "dns-nameservers"; then + current_dns_lines=$((current_dns_lines + 1)) + if [ $current_dns_lines -lt $dns_lines ]; then + continue + fi + fi + echo "$line" >> /tmp/interfaces.tmp + done < /etc/network/interfaces + chattr -i /etc/network/interfaces + mv /tmp/interfaces.tmp /etc/network/interfaces + chattr +i /etc/network/interfaces + rm -rf /tmp/interfaces.tmp +fi # 反加载 if [[ -f "/etc/network/interfaces.new" && -f "/etc/network/interfaces" ]]; then chattr -i /etc/network/interfaces.new