修改v6共存的类型为dhcp类型

修改v6共存的类型为dhcp类型
This commit is contained in:
spiritlhl 2023-07-31 15:16:01 +08:00 committed by GitHub
parent 8b8f13ff7e
commit 3a3e5e188a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -310,6 +310,11 @@ if ! grep -q "iface lo inet loopback" "/etc/network/interfaces"; then
chattr +i /etc/network/interfaces chattr +i /etc/network/interfaces
_blue "Can not find 'iface lo inet loopback' in /etc/network/interfaces, add it" _blue "Can not find 'iface lo inet loopback' in /etc/network/interfaces, add it"
fi fi
# 修改v6共存的类型为dhcp类型
if grep -q "iface ${interface} inet6 manual" /etc/network/interfaces && grep -q "try_dhcp 1" /etc/network/interfaces; then
sed -i 's/iface ${interface} inet6 manual/iface ${interface} inet6 dhcp/' /etc/network/interfaces
sed -i '/try_dhcp 1/d' /etc/network/interfaces
fi
# 反加载 # 反加载
if [[ -f "/etc/network/interfaces.new" && -f "/etc/network/interfaces" ]]; then if [[ -f "/etc/network/interfaces.new" && -f "/etc/network/interfaces" ]]; then
chattr -i /etc/network/interfaces.new chattr -i /etc/network/interfaces.new
@ -324,7 +329,7 @@ fi
} }
fix_interfaces_ipv6_auto_type(){ fix_interfaces_ipv6_auto_type(){
chattr -i $1 chattr -i /etc/network/interfaces
while IFS= read -r line while IFS= read -r line
do do
# 检测以 "iface" 开头且包含 "inet6 auto" 的行 # 检测以 "iface" 开头且包含 "inet6 auto" 的行
@ -333,7 +338,7 @@ do
matches=$(echo "$output" | grep "inet6.*global dynamic") matches=$(echo "$output" | grep "inet6.*global dynamic")
if [ -n "$matches" ]; then if [ -n "$matches" ]; then
# SLAAC动态分配暂不做IPV6的处理 # SLAAC动态分配暂不做IPV6的处理
sed -i "/iface $interface inet6 auto/d" $1 sed -i "/iface $interface inet6 auto/d" /etc/network/interfaces
echo "$interface" > "/usr/local/bin/iface_auto.txt" echo "$interface" > "/usr/local/bin/iface_auto.txt"
else else
# 将 "auto" 替换为 "static" # 将 "auto" 替换为 "static"
@ -353,10 +358,10 @@ do
else else
echo "$line" echo "$line"
fi fi
done < $1 > /tmp/interfaces.modified done < /etc/network/interfaces > /tmp/interfaces.modified
chattr -i $1 chattr -i /etc/network/interfaces
mv -f /tmp/interfaces.modified $1 mv -f /tmp/interfaces.modified /etc/network/interfaces
chattr +i $1 chattr +i /etc/network/interfaces
rm -rf /tmp/interfaces.modified rm -rf /tmp/interfaces.modified
} }
@ -687,7 +692,7 @@ dmidecode_output=$(dmidecode -t system)
rebuild_interfaces rebuild_interfaces
# cloudinit 重构 # cloudinit 重构
rebuild_cloud_init rebuild_cloud_init
fix_interfaces_ipv6_auto_type /etc/network/interfaces fix_interfaces_ipv6_auto_type
# 统计运行次数 # 统计运行次数
statistics_of_run-times statistics_of_run-times
# 检测是否已重启过 # 检测是否已重启过
@ -943,7 +948,7 @@ if echo $output | grep -q "NO_PUBKEY"; then
fi fi
# 修复网卡可能存在的auto类型 # 修复网卡可能存在的auto类型
rebuild_interfaces rebuild_interfaces
fix_interfaces_ipv6_auto_type /etc/network/interfaces fix_interfaces_ipv6_auto_type
auto_interface=$(grep '^auto ' /etc/network/interfaces | grep -v '^auto lo' | awk '{print $2}' | head -n 1) auto_interface=$(grep '^auto ' /etc/network/interfaces | grep -v '^auto lo' | awk '{print $2}' | head -n 1)
if ! grep -q "^post-up /sbin/ethtool" /etc/network/interfaces; then if ! grep -q "^post-up /sbin/ethtool" /etc/network/interfaces; then
chattr -i /etc/network/interfaces chattr -i /etc/network/interfaces