各位大大,大家好,现时我用群友发出的ssh脚本计划任务来动态解析到阿里云域名,成功影射,但默认是三个IPV6地址中的第二个地址,请问如何设定是影射如图中的蓝色箭头IPV6地址,我是代码白痴,麻烦可以帮忙解决。谢谢。 附使用的脚本内容: 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。
大部分情况下IPv6后64位是不变的,那么就可以使用后64位(16进制的后4段)来匹配你要的地址,比如:2408:aaaa:bbbb:cccc:dddd:eeee:ffff:aaaa,就可以这样写正则表达式: dddd:eeee:ffff:aaaa$ 但我的黑群晖docker的host网络里只识别到一个地址
ip addr show eth0 看一下地址那行长什么样 然后 grep后面的引号里写正则表达式,写的有唯一性就行了,只要匹配到你需要的行即可。 比如 inet6 2408:xxxxxxxxx/64 scope global mngtmpaddr dynamic ip addr show eth0 | grep "inet6.*global.*dynamic"