本帖最后由 ifreeswan 于 2025-3-9 15:55 编辑
pve 上 haos ,用 addon duckdns 不能更新 ipv6,没有什么办法。最后,把 duckdns 安装到 pve 上,比 addon 方便,。
删除了 hoas 上的 duckdns ,保留 Nginx Proxy Manager 。
用 ai 写的脚本 在 pve 中 获取 haos 的 ipv6 ,更新 duckdns
#!/bin/bash
set -e
LOG_FILE="/var/log/ipv6_change.log"
INTERFACE="vmbr0"
DOMAIN="homeassistant.local"
get_if_ipv6_address() {
local interface="$1"
echo $(ip -6 addr show dev $interface scope global -deprecated | awk '
/inet6/ {
address = $2;
getline;
match($0, /valid_lft ([0-9]+)sec/, arr);
valid_lft = arr[1];
print valid_lft " " address;
}
' | sort -s -n -k 1,1 | tail -n 1 | awk '{print $2}'
)
}
get_domain_ipv6_address() {
local domain="$1"
# dig "$domain" AAAA +short | awk '/^$IF_IPV6_PREFIX/ {print $1}'
while IFS= read -r ipv6; do
ipv6_prefix=$(ipcalc "$ipv6/$IF_IPV6_PREFIX_LENGTH" | grep "Prefix:" | awk '{print $2}')
if [ "$IF_IPV6_PREFIX" = "$ipv6_prefix" ] ; then echo $ipv6 ; fi
done < <(dig "$domain" AAAA +short | grep -v '^fe80::')
}
log_change() {
TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
printf "$TIMESTAMP : %24s : %s\n" "$1" "$2" >> "$LOG_FILE"
}
IF_IPV6_PREV=""
DOMAIN_IPV6_PREV=""
while true; do
IF_IPV6ALL=$(get_if_ipv6_address "$INTERFACE")
IF_IPV6_CURR=${IF_IPV6ALL%/*}
IF_IPV6_PREFIX_LENGTH=${IF_IPV6ALL#*/}
IF_IPV6_PREFIX=$(ipcalc "$IF_IPV6ALL" | grep "Prefix:" | awk '{print $2}')
DOMAIN_IPV6_CURR=$(get_domain_ipv6_address "$DOMAIN")
if [ "$IF_IPV6_CURR" != "$IF_IPV6_PREV" ]; then
log_change "$INTERFACE" "$IF_IPV6ALL"
IF_IPV6_PREV="$IF_IPV6_CURR"
fi
if [ "$DOMAIN_IPV6_CURR" != "$DOMAIN_IPV6_PREV" ]; then
log_change "$DOMAIN" "$DOMAIN_IPV6_CURR"
DOMAIN_IPV6_PREV="$DOMAIN_IPV6_CURR"
URL="https://www.duckdns.org/update?domains=haos&token=${token}&verbose=true&ipv6=$DOMAIN_IPV6_CURR"
curl -k "$URL" >> "$LOG_FILE"
fi
sleep 600
done
|