From 0dafe12f69b767784b0065055d6335d621d352ad Mon Sep 17 00:00:00 2001 From: spiritlhl <103393591+spiritLHLS@users.noreply.github.com> Date: Wed, 9 Aug 2023 14:32:23 +0000 Subject: [PATCH] 2023.08.09 --- CHANGELOG.md | 7 +++++++ README.md | 8 +++----- extra_scripts/check-dns.sh | 11 ++++++++--- scripts/buildct.sh | 3 ++- scripts/buildvm.sh | 6 ++++-- scripts/buildvm_extraip.sh | 6 ++++-- scripts/buildvm_manual_ip.sh | 6 ++++-- scripts/install_pve.sh | 13 ++++++++++--- 8 files changed, 42 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98bc483..afd4f6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # 更新日志 +2023.08.04 + +- 开设独立IPV4地址的虚拟机时,尝试增加自动附加IPV6地址的功能 +- 增加一键开设纯IPV6虚拟机、纯IPV6容器的脚本 +- 修复可能的dns-nameservers存在多行导致网络异常的问题 +- 特殊处理没有ifupdown的宿主机 + 2023.08.03 - 尝试增加了IPV6的支持,暂时只是支持了IPV6网关的设置,暂时未适配一键开设,明日适配 diff --git a/README.md b/README.md index 9720584..2790df2 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,10 @@ ## 更新 -2023.08.04 +2023.08.09 -- 开设独立IPV4地址的虚拟机时,尝试增加自动附加IPV6地址的功能 -- 增加一键开设纯IPV6虚拟机、纯IPV6容器的脚本 -- 修复可能的dns-nameservers存在多行导致网络异常的问题 -- 特殊处理没有ifupdown的宿主机 +- 判断是否有IPV6网络,如果没有则宿主机就不添加对应的V6的DNS +- 判断是否有IPV6网络,如果没有则开设的虚拟机和容器就不添加对应的V6的DNS [更新日志](CHANGELOG.md) diff --git a/extra_scripts/check-dns.sh b/extra_scripts/check-dns.sh index d1eb4b6..54ce8c7 100644 --- a/extra_scripts/check-dns.sh +++ b/extra_scripts/check-dns.sh @@ -4,12 +4,17 @@ DNS_SERVER="8.8.8.8" RESOLV_CONF="/etc/resolv.conf" - +ipv6_address=$(cat /usr/local/bin/pve_check_ipv6) +ipv6_prefixlen=$(cat /usr/local/bin/pve_ipv6_prefixlen) +ipv6_gateway=$(cat /usr/local/bin/pve_ipv6_gateway) grep -q "^nameserver ${DNS_SERVER}$" ${RESOLV_CONF} - if [ $? -eq 0 ]; then echo "DNS server ${DNS_SERVER} already exists in ${RESOLV_CONF}." else echo "Adding DNS server ${DNS_SERVER} to ${RESOLV_CONF}..." - echo -e "nameserver 1.1.1.1\nnameserver 8.8.8.8\nnameserver 8.8.4.4\nnameserver 2606:4700:4700::1111\nnameserver 2001:4860:4860::8888\nnameserver 2001:4860:4860::8844" >> ${RESOLV_CONF} + if [ -z "$ipv6_address" ] || [ -z "$ipv6_prefixlen" ] || [ -z "$ipv6_gateway" ]; then + echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4\n" >> ${RESOLV_CONF} + else + echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4\nnameserver 2606:4700:4700::1111\nnameserver 2001:4860:4860::8888\nnameserver 2001:4860:4860::8844" >> ${RESOLV_CONF} + fi fi diff --git a/scripts/buildct.sh b/scripts/buildct.sh index 3606530..53bb65a 100644 --- a/scripts/buildct.sh +++ b/scripts/buildct.sh @@ -228,10 +228,11 @@ pct start $CTID pct set $CTID --hostname $CTID if [ -z "$ipv6_address" ] || [ -z "$ipv6_prefixlen" ] || [ -z "$ipv6_gateway" ] || [ "$ipv6_prefixlen" -gt 112 ]; then pct set $CTID --net0 name=eth0,ip=${user_ip}/24,bridge=vmbr1,gw=172.16.1.1 + pct set $CTID --nameserver 8.8.8.8 --nameserver 8.8.4.4 else pct set $CTID --net0 name=eth0,ip=${user_ip}/24,bridge=vmbr1,gw=172.16.1.1,ip6=${ipv6_address}/${ipv6_prefixlen},gw6=${ipv6_gateway} + pct set $CTID --nameserver 8.8.8.8,2001:4860:4860::8888 --nameserver 8.8.4.4,2001:4860:4860::8844 fi -pct set $CTID --nameserver 8.8.8.8,2001:4860:4860::8888 --nameserver 8.8.4.4,2001:4860:4860::8844 sleep 3 if echo "$system" | grep -qiE "centos|almalinux|rockylinux"; then pct exec $CTID -- yum update -y diff --git a/scripts/buildvm.sh b/scripts/buildvm.sh index 03bc4fd..f8973bc 100644 --- a/scripts/buildvm.sh +++ b/scripts/buildvm.sh @@ -245,14 +245,16 @@ qm set $vm_num --boot order=scsi0 qm set $vm_num --memory $memory # --swap 256 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 ip=${user_ip}/24,gw=172.16.1.1 if [ -z "$ipv6_address" ] || [ -z "$ipv6_prefixlen" ] || [ -z "$ipv6_gateway" ] || [ "$ipv6_prefixlen" -gt 112 ]; then qm set $vm_num --ipconfig0 ip=${user_ip}/24,gw=172.16.1.1 + qm set $vm_num --nameserver 8.8.8.8 + qm set $vm_num --searchdomain 8.8.4.4 else qm set $vm_num --ipconfig0 ip=${user_ip}/24,gw=172.16.1.1,ip6=${ipv6_address}/${ipv6_prefixlen},gw6=${ipv6_gateway} + 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 fi qm set $vm_num --cipassword $password --ciuser $user sleep 5 diff --git a/scripts/buildvm_extraip.sh b/scripts/buildvm_extraip.sh index eca1951..455b27b 100644 --- a/scripts/buildvm_extraip.sh +++ b/scripts/buildvm_extraip.sh @@ -290,12 +290,14 @@ qm set $vm_num --boot order=scsi0 qm set $vm_num --memory $memory # --swap 256 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 if [ -z "$ipv6_address" ] || [ -z "$ipv6_prefixlen" ] || [ -z "$ipv6_gateway" ] || [ "$ipv6_prefixlen" -gt 112 ] || [ "$open_ipv6" = "N" ]; then qm set $vm_num --ipconfig0 ip=${user_ip}/${user_ip_range},gw=${gateway} + qm set $vm_num --nameserver 8.8.8.8 + qm set $vm_num --searchdomain 8.8.4.4 else qm set $vm_num --ipconfig0 ip=${user_ip}/${user_ip_range},gw=${gateway},ip6=${ipv6_address}/${ipv6_prefixlen},gw6=${ipv6_gateway} + 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 fi qm set $vm_num --cipassword $password --ciuser $user sleep 5 diff --git a/scripts/buildvm_manual_ip.sh b/scripts/buildvm_manual_ip.sh index 8335e20..df7061c 100644 --- a/scripts/buildvm_manual_ip.sh +++ b/scripts/buildvm_manual_ip.sh @@ -295,12 +295,14 @@ qm set $vm_num --boot order=scsi0 qm set $vm_num --memory $memory # --swap 256 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 if [ -z "$ipv6_address" ] || [ -z "$ipv6_prefixlen" ] || [ -z "$ipv6_gateway" ] || [ "$ipv6_prefixlen" -gt 112 ] || [ "$open_ipv6" = "N" ]; then qm set $vm_num --ipconfig0 ip=${user_ip}/${user_ip_range},gw=${gateway} + qm set $vm_num --nameserver 8.8.8.8 + qm set $vm_num --searchdomain 8.8.4.4 else qm set $vm_num --ipconfig0 ip=${user_ip}/${user_ip_range},gw=${gateway},ip6=${ipv6_address}/${ipv6_prefixlen},gw6=${ipv6_gateway} + 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 fi qm set $vm_num --cipassword $password --ciuser $user sleep 5 diff --git a/scripts/install_pve.sh b/scripts/install_pve.sh index 748a06b..2e553c9 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.04 +# 2023.08.09 ########## 预设部分输出和部分中间变量 @@ -1229,9 +1229,16 @@ if [ ! -s "/etc/resolv.conf" ] then cp /etc/resolv.conf /etc/resolv.conf.bak if [[ "${CN}" == true ]]; then - echo -e "nameserver 8.8.8.8\nnameserver 223.5.5.5\nnameserver 2001:4860:4860::8888\nnameserver 2001:4860:4860::8844" > /etc/resolv.conf + if [ -z "$ipv6_address" ] || [ -z "$ipv6_prefixlen" ] || [ -z "$ipv6_gateway" ]; then + echo -e "nameserver 8.8.8.8\nnameserver 223.5.5.5\n" > /etc/resolv.conf + else + echo -e "nameserver 8.8.8.8\nnameserver 223.5.5.5\nnameserver 2001:4860:4860::8888\nnameserver 2001:4860:4860::8844" > /etc/resolv.conf else - echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4\nnameserver 2001:4860:4860::8888\nnameserver 2001:4860:4860::8844" > /etc/resolv.conf + if [ -z "$ipv6_address" ] || [ -z "$ipv6_prefixlen" ] || [ -z "$ipv6_gateway" ]; then + echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4\n" > /etc/resolv.conf + else + echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4\nnameserver 2001:4860:4860::8888\nnameserver 2001:4860:4860::8844" > /etc/resolv.conf + fi fi fi