From 2df34f274df3ffc28a6181fcac716772ce25763f Mon Sep 17 00:00:00 2001 From: spiritlhl <103393591+spiritLHLS@users.noreply.github.com> Date: Tue, 30 May 2023 21:59:29 +0800 Subject: [PATCH] Update build_nat_network.sh --- scripts/build_nat_network.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/build_nat_network.sh b/scripts/build_nat_network.sh index e941968..348d76e 100644 --- a/scripts/build_nat_network.sh +++ b/scripts/build_nat_network.sh @@ -43,6 +43,21 @@ else fi gateway=$(ip route | awk '/default/ {print $3}') +# 获取母鸡子网前缀 +SUBNET_PREFIX=$(ip -6 addr show | grep -E 'inet6.*global' | awk '{print $2}' | awk -F'/' '{print $1}' | head -n 1 | cut -d ':' -f1-5): + +# 提取IPV6地址 +content=$(cat /etc/network/interfaces.d/50-cloud-init) +ipv6_line=$(echo "$content" | grep "address 2a12:bec0:150:1a::a/64") +ipv6_address=$(echo "$ipv6_line" | awk '{print $2}') + +# 检查是否存在 IPV6 +if [ -z "$SUBNET_PREFIX" ]; then + _red "无 IPV6 子网,不进行自动映射" +else + _blue "母鸡的IPV6子网前缀为 $SUBNET_PREFIX" +fi + # 录入网关 cp /etc/network/interfaces /etc/network/interfaces.bak if grep -q "vmbr0" /etc/network/interfaces; then @@ -56,6 +71,9 @@ iface vmbr0 inet static bridge_ports $interface bridge_stp off bridge_fd 0 +iface vmbr0 inet6 static + address $ipv6_address + gateway ${SUBNET_PREFIX}1 EOF fi if grep -q "vmbr1" /etc/network/interfaces; then