From 7f506c30fd445280e85d584114e151d68ead9ca0 Mon Sep 17 00:00:00 2001 From: spiritlhl <103393591+spiritLHLS@users.noreply.github.com> Date: Tue, 22 Aug 2023 02:00:28 +0000 Subject: [PATCH] update --- scripts/build_nat_network.sh | 4 ++-- scripts/buildct.sh | 2 +- scripts/buildct_onlyv6.sh | 2 +- scripts/buildvm.sh | 2 +- scripts/buildvm_onlyv6.sh | 2 +- scripts/install_pve.sh | 16 ++++++++-------- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/scripts/build_nat_network.sh b/scripts/build_nat_network.sh index 6fa9a40..202355d 100644 --- a/scripts/build_nat_network.sh +++ b/scripts/build_nat_network.sh @@ -1,7 +1,7 @@ #!/bin/bash # from # https://github.com/spiritLHLS/pve -# 2023.08.21 +# 2023.08.22 ########## 预设部分输出和部分中间变量 @@ -225,7 +225,7 @@ if [ "$ipv6_prefixlen" -le 64 ]; then cat << EOF | sudo tee -a "$interfaces_file" auto vmbr2 iface vmbr2 inet6 static - address ${ipv6_address_without_last_segment}2/${ipv6_prefixlen} + address ${ipv6_address_without_last_segment}1/${ipv6_prefixlen} bridge_ports none bridge_stp off bridge_fd 0 diff --git a/scripts/buildct.sh b/scripts/buildct.sh index 5683e68..d57bf40 100644 --- a/scripts/buildct.sh +++ b/scripts/buildct.sh @@ -245,7 +245,7 @@ pct set $CTID --hostname $CTID if [ "$independent_ipv6" == "Y" ]; then if [ "$ipv6_prefixlen" -le 64 ]; then if [ ! -z "$ipv6_address" ] && [ ! -z "$ipv6_prefixlen" ] && [ ! -z "$ipv6_gateway" ] && [ ! -z "$ipv6_address_without_last_segment" ]; then - pct set $CTID --net0 name=eth0,ip6="${ipv6_address_without_last_segment}${CTID}/128",bridge=vmbr2,gw6="${ipv6_address_without_last_segment}2" + pct set $CTID --net0 name=eth0,ip6="${ipv6_address_without_last_segment}${CTID}/128",bridge=vmbr2,gw6="${ipv6_address_without_last_segment}1" pct set $CTID --net1 name=eth1,ip=${user_ip}/24,bridge=vmbr1,gw=172.16.1.1 pct set $CTID --nameserver 8.8.8.8,2001:4860:4860::8888 --nameserver 8.8.4.4,2001:4860:4860::8844 independent_ipv6_status="Y" diff --git a/scripts/buildct_onlyv6.sh b/scripts/buildct_onlyv6.sh index 5f09f9c..ad1612b 100644 --- a/scripts/buildct_onlyv6.sh +++ b/scripts/buildct_onlyv6.sh @@ -210,7 +210,7 @@ fi pct start $CTID pct set $CTID --hostname $CTID user_ip="172.16.1.${num}" -pct set $CTID --net0 name=eth0,ip6="${ipv6_address_without_last_segment}${CTID}/128",bridge=vmbr2,gw6="${ipv6_address_without_last_segment}2" +pct set $CTID --net0 name=eth0,ip6="${ipv6_address_without_last_segment}${CTID}/128",bridge=vmbr2,gw6="${ipv6_address_without_last_segment}1" pct set $CTID --net1 name=eth1,ip=${user_ip}/24,bridge=vmbr1,gw=172.16.1.1 pct set $CTID --nameserver 8.8.8.8,2001:4860:4860::8888 --nameserver 8.8.4.4,2001:4860:4860::8844 sleep 3 diff --git a/scripts/buildvm.sh b/scripts/buildvm.sh index a8c40d0..8a7d449 100644 --- a/scripts/buildvm.sh +++ b/scripts/buildvm.sh @@ -268,7 +268,7 @@ user_ip="172.16.1.${num}" if [ "$independent_ipv6" == "Y" ]; then if [ "$ipv6_prefixlen" -le 64 ]; then if [ ! -z "$ipv6_address" ] && [ ! -z "$ipv6_prefixlen" ] && [ ! -z "$ipv6_gateway" ] && [ ! -z "$ipv6_address_without_last_segment" ]; then - qm set $vm_num --ipconfig0 ip6="${ipv6_address_without_last_segment}${vm_num}/128",gw6="${ipv6_address_without_last_segment}2" + qm set $vm_num --ipconfig0 ip6="${ipv6_address_without_last_segment}${vm_num}/128",gw6="${ipv6_address_without_last_segment}1" qm set $vm_num --ipconfig1 ip=${user_ip}/24,gw=172.16.1.1 qm set $vm_num --nameserver 8.8.8.8,2001:4860:4860::8888 qm set $vm_num --searchdomain 8.8.4.4,2001:4860:4860::8844 diff --git a/scripts/buildvm_onlyv6.sh b/scripts/buildvm_onlyv6.sh index fbbefdf..328c085 100644 --- a/scripts/buildvm_onlyv6.sh +++ b/scripts/buildvm_onlyv6.sh @@ -232,7 +232,7 @@ qm set $vm_num --ide2 ${storage}:cloudinit qm set $vm_num --nameserver 8.8.8.8,2001:4860:4860::8888 qm set $vm_num --searchdomain 8.8.4.4,2001:4860:4860::8844 user_ip="172.16.1.${num}" -qm set $vm_num --ipconfig0 ip6="${ipv6_address_without_last_segment}${vm_num}/128",gw6="${ipv6_address_without_last_segment}2" +qm set $vm_num --ipconfig0 ip6="${ipv6_address_without_last_segment}${vm_num}/128",gw6="${ipv6_address_without_last_segment}1" qm set $vm_num --ipconfig1 ip=${user_ip}/24,gw=172.16.1.1 qm set $vm_num --cipassword $password --ciuser $user sleep 5 diff --git a/scripts/install_pve.sh b/scripts/install_pve.sh index ddaf15d..268c1fc 100644 --- a/scripts/install_pve.sh +++ b/scripts/install_pve.sh @@ -1,7 +1,7 @@ #!/bin/bash # from # https://github.com/spiritLHLS/pve -# 2023.08.20 +# 2023.08.22 ########## 预设部分输出和部分中间变量 @@ -422,13 +422,12 @@ is_private_ipv6() { check_ipv6(){ IPV6=$(ip -6 addr show | grep global | awk '{print $2}' | cut -d '/' -f1 | head -n 1) - local response if is_private_ipv6 "$IPV6"; then # 由于是内网IPV6地址,需要通过API获取外网地址 IPV6="" - local API_NET=("ipv6.ip.sb" "https://ipget.net" "ipv6.ping0.cc" "https://api.my-ip.io/ip" "https://ipv6.icanhazip.com") + API_NET=("ipv6.ip.sb" "https://ipget.net" "ipv6.ping0.cc" "https://api.my-ip.io/ip" "https://ipv6.icanhazip.com") for p in "${API_NET[@]}"; do response=$(curl -sLk6m8 "$p" | tr -d '[:space:]') - if [ $? -eq 0 ] && ! echo "$response" | grep -q "error"; then + if [ $? -eq 0 ] && ! ( echo "$response" | grep -q "error" ); then IPV6="$response" break fi @@ -789,14 +788,14 @@ check_interface # fi # 检测IPV6相关的信息 -if [ ! -f /usr/local/bin/pve_check_ipv6 ]; then +if [ ! -f /usr/local/bin/pve_check_ipv6 ] || [ ! -s /usr/local/bin/pve_check_ipv6 ] || [ "$(sed -e '/^[[:space:]]*$/d' /usr/local/bin/pve_check_ipv6)" = "" ]; then check_ipv6 fi -if [ ! -f /usr/local/bin/pve_ipv6_prefixlen ]; then +if [ ! -f /usr/local/bin/pve_ipv6_prefixlen ] || [ ! -s /usr/local/bin/pve_ipv6_prefixlen ] || [ "$(sed -e '/^[[:space:]]*$/d' /usr/local/bin/pve_ipv6_prefixlen)" = "" ]; then ipv6_prefixlen=$(ifconfig ${interface} | grep -oP 'prefixlen \K\d+' | head -n 1) echo "$ipv6_prefixlen" > /usr/local/bin/pve_ipv6_prefixlen fi -if [ ! -f /usr/local/bin/pve_ipv6_gateway ]; then +if [ ! -f /usr/local/bin/pve_ipv6_gateway ] || [ ! -s /usr/local/bin/pve_ipv6_gateway ] || [ "$(sed -e '/^[[:space:]]*$/d' /usr/local/bin/pve_ipv6_gateway)" = "" ]; then ipv6_gateway=$(ip -6 route show | awk '/default via/{print $3}' | head -n1) # ip -6 route show | awk '/default via/{print $3}' | head -n1 # if is_private_ipv6 "$ipv6_gateway"; then # 由于是内网IPV6地址,不设置V6地址 @@ -1173,6 +1172,7 @@ iface vmbr0 inet6 auto bridge_ports $interface EOF else + ipv6_address_without_last_segment="${ipv6_address%:*}:" cat << EOF | sudo tee -a /etc/network/interfaces auto vmbr0 iface vmbr0 inet static @@ -1183,7 +1183,7 @@ iface vmbr0 inet static bridge_fd 0 iface vmbr0 inet6 static - address ${ipv6_address}/${ipv6_prefixlen} + address ${ipv6_address_without_last_segment}/128 gateway ${ipv6_gateway} EOF fi