1. 服务器/VPS/主机用户Telegram电报群: https://t.me/openos
    黑群晖 Synology Telegram电报群: https://t.me/nasfan
    排除公告

求助:DDNS动态解析到阿里时,如何选择群晖第二个IPV6地址

本帖由 cn20002022-08-08 发布。版面名称:群晖 Synology DSM

  1. cn2000

    cn2000 New Member

    注册:
    2021-07-10
    帖子:
    18
    各位大大,大家好,现时我用群友发出的ssh脚本计划任务来动态解析到阿里云域名,成功影射,但默认是三个IPV6地址中的第二个地址,请问如何设定是影射如图中的蓝色箭头IPV6地址,我是代码白痴,麻烦可以帮忙解决。谢谢。

    [​IMG]

    附使用的脚本内容:

    aliddnsipv6_ak="LTAI5****************************"
    aliddnsipv6_sk="qwuC**************************"
    aliddnsipv6_name1='***********'
    aliddnsipv6_domain='***********'
    aliddnsipv6_ttl="600"

    if [ "$aliddnsipv6_name1" = "@" ]
    then
    aliddnsipv6_name=$aliddnsipv6_domain
    else
    aliddnsipv6_name=$aliddnsipv6_name1.$aliddnsipv6_domain
    fi

    now=`date`

    die () {
    echo $1
    }

    ipv6s=`ip addr show eth0 | grep "inet6.*global" | awk '{print $2}' | awk -F"/" '{print $1}'` || die "$ipv6"

    for ipv6 in $ipv6s
    do
    #ipv6 = $ipv6
    break
    done

    echo $ipv6

    current_ipv6=`nslookup -query=AAAA $aliddnsipv6_name 2>&1`
    #echo $current_ipv6

    current_ipv6=`echo "$current_ipv6" | grep 'Address: ' | tail -n1 | awk '{print $NF}'`
    echo $current_ipv6

    if [ "$?" -eq "0" ]
    then
    current_ipv6=`echo "$current_ipv6" | grep 'Address: ' | tail -n1 | awk '{print $NF}'`
    echo $current_ipv6

    if [ "$ipv6" = "$current_ipv6" ]
    then
    echo "skipping"
    fi
    # fix when A record removed by manual dns is always update error
    else
    unset aliddnsipv6_record_id
    fi


    timestamp=`date -u "+%Y-%m-%dT%H%%3A%M%%3A%SZ"`


    urlencode() {
    # urlencode <string>
    out=""
    while read -n1 c
    do
    case $c in
    [a-zA-Z0-9._-]) out="$out$c" ;;
    *) out="$out`printf '%%%02X' "'$c"`" ;;
    esac
    done
    echo -n $out
    }

    enc() {
    echo -n "$1" | urlencode
    }

    send_request() {
    local args="AccessKeyId=$aliddnsipv6_ak&Action=$1&Format=json&$2&Version=2015-01-09"
    local hash=$(echo -n "GET&%2F&$(enc "$args")" | openssl dgst -sha1 -hmac "$aliddnsipv6_sk&" -binary | openssl base64)
    curl -s "http://alidns.aliyuncs.com/?$args&Signature=$(enc "$hash")"
    }

    get_recordid() {
    grep -Eo '"RecordId":"[0-9]+"' | cut -d':' -f2 | tr -d '"'
    }

    query_recordid() {
    send_request "DescribeSubDomainRecords" "SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&SubDomain=$aliddnsipv6_name&Timestamp=$timestamp&Type=AAAA"
    }

    update_record() {
    send_request "UpdateDomainRecord" "RR=$aliddnsipv6_name1&RecordId=$1&SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&TTL=$aliddnsipv6_ttl&Timestamp=$timestamp&Type=AAAA&Value=$(enc $ipv6)"
    }

    add_record() {
    send_request "AddDomainRecord&DomainName=$aliddnsipv6_domain" "RR=$aliddnsipv6_name1&SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&TTL=$aliddnsipv6_ttl&Timestamp=$timestamp&Type=AAAA&Value=$(enc $ipv6)"
    }

    #add support */%2A and @/%40 record


    if [ "$aliddnsipv6_record_id" = "" ]
    then
    aliddnsipv6_record_id=`query_recordid | get_recordid`
    #echo '-----------------' $aliddnsipv6_record_id
    fi
    if [ "$aliddnsipv6_record_id" = "" ]
    then
    aliddnsipv6_record_id=`add_record | get_recordid`
    echo "added record $aliddnsipv6_record_id"
    else
    update_record $aliddnsipv6_record_id
    echo "updated record $aliddnsipv6_record_id"
    fi


    另外请教大家,群晖应用市场里docker安装的DDNS-GO中要选择第二个ipv6地址要求填写的匹配正则表达式如何填。如何可以就直接使用DDNS-GO。


    [​IMG]
     
  2. 寻千与千寻

    寻千与千寻 Member

    注册:
    2020-07-29
    帖子:
    131
    没有ipv6地址。。帮不了你。。。
     
  3. KunGeek

    KunGeek New Member

    注册:
    2022-04-10
    帖子:
    4
    大部分情况下IPv6后64位是不变的,那么就可以使用后64位(16进制的后4段)来匹配你要的地址,比如:2408:aaaa:bbbb:cccc:dddd:eeee:ffff:aaaa,就可以这样写正则表达式:
    dddd:eeee:ffff:aaaa$
    但我的黑群晖docker的host网络里只识别到一个地址
     
    已获得 zzddagdcafuliaojiyuea236752252 的点赞。
  4. cn2000

    cn2000 New Member

    注册:
    2021-07-10
    帖子:
    18
    谢谢回复,我试试看。
     
  5. a236752252

    a236752252 Member

    注册:
    2019-11-17
    帖子:
    35
    ip addr show eth0
    看一下地址那行长什么样
    然后
    grep后面的引号里写正则表达式,写的有唯一性就行了,只要匹配到你需要的行即可。
    比如
    inet6 2408:xxxxxxxxx/64 scope global mngtmpaddr dynamic

    ip addr show eth0 | grep "inet6.*global.*dynamic"
     
  6. Da.lei

    Da.lei New Member

    注册:
    2021-11-27
    帖子:
    12
    通过接口获取,,都不需要折腾,直接就可以使用了。
     
  7. xc1940625

    xc1940625 New Member

    注册:
    2019-11-09
    帖子:
    22
    ipv6s=`ip addr show eth0 | grep "inet6.*a785" 我是这样改的,可以用。A785是IPV6地址最后一个
     
  8. xc1940625

    xc1940625 New Member

    注册:
    2019-11-09
    帖子:
    22
    我的也是有2个地址
     
  9. xc1940625

    xc1940625 New Member

    注册:
    2019-11-09
    帖子:
    22
    *global改成3456