This commit is contained in:
spiritlhl 2023-08-22 02:00:28 +00:00
parent 80b0fcdf64
commit 7f506c30fd
6 changed files with 14 additions and 14 deletions

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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