2023.12.03

This commit is contained in:
spiritlhl 2023-12-03 05:16:30 +00:00
parent aa3a923242
commit aedc88dada
3 changed files with 22 additions and 4 deletions

View file

@ -1,5 +1,9 @@
# 更新日志
2023.11.27
- 完善IPV6检测机制尽量保证识别出准确的IPV6子网掩码和子网前缀且尽量保证ndp可用
2023.11.26
- 重新计算IPV6子网的前缀适配宿主机虽然给了子网但默认的IPV6地址是随机给的非```::1```或```::a```结尾的情况

View file

@ -13,9 +13,9 @@
## 更新
2023.11.27
2023.12.03
- 完善IPV6检测机制尽量保证识别出准确的IPV6子网掩码和子网前缀且尽量保证ndp可用
- 修复可能的hostname的自动修改导致网络不通的问题尝试解决默认V4为内网V4的情况
[更新日志](CHANGELOG.md)

View file

@ -1,7 +1,7 @@
#!/bin/bash
# from
# https://github.com/spiritLHLS/pve
# 2023.11.26
# 2023.12.03
########## 预设部分输出和部分中间变量
@ -52,6 +52,11 @@ if [ -f "/etc/cloud/cloud.cfg" ]; then
cp /etc/cloud/cloud.cfg /etc/cloud/cloud.cfg.bak
fi
fi
if [ -f "/etc/hostname" ]; then
if [ ! -f /etc/hostname.bak ]; then
cp /etc/hostname /etc/hostname.bak
fi
fi
if [ -f "/etc/hosts" ]; then
if [ ! -f /etc/hosts.bak ]; then
cp /etc/hosts /etc/hosts.bak
@ -839,6 +844,11 @@ _yellow "正在检测系统信息大概会停留在该页面最多1~2分钟"
# 检测主IPV4相关信息
if [ ! -f /usr/local/bin/pve_main_ipv4 ]; then
main_ipv4=$(ip -4 addr show | grep global | awk '{print $2}' | cut -d '/' -f1 | head -n 1)
if is_private_ipv4 "$main_ipv4"; then
# 查询公网IPV4
check_ipv4
main_ipv4="$IPV4"
fi
echo "$main_ipv4" >/usr/local/bin/pve_main_ipv4
fi
# 提取主IPV4地址
@ -1101,7 +1111,11 @@ if [ "${hostname}" != "pve" ]; then
sed -i '/^127\.0\.1\.1/s/^/#/' /etc/hosts
echo "Commented out lines starting with 127.0.1.1 in /etc/hosts"
fi
if ! grep -q "^127\.0\.0\.1 localhost\.localdomain localhost$" /etc/hosts; then
hostname_bak=$(cat /etc/hostname.bak)
if grep -q "^127\.0\.0\.1 ${hostname_bak}\.localdomain ${hostname_bak}$" /etc/hosts; then
sed -i "s/^127\.0\.0\.1 ${hostname_bak}\.localdomain ${hostname_bak}$/&\n${main_ipv4} ${hostname}.localdomain ${hostname}/" /etc/hosts
echo "Replaced the line for ${hostname_bak} in /etc/hosts"
elif ! grep -q "^127\.0\.0\.1 localhost\.localdomain localhost$" /etc/hosts; then
# 127.0.1.1
echo "${main_ipv4} ${hostname}.localdomain ${hostname}" >>/etc/hosts
echo "Added ${main_ipv4} ${hostname}.localdomain ${hostname} to /etc/hosts"