Help with ddns with fixed ipv6 suffix

I have a /64 ip, and I am unable to get Cloudflare ddns scripts to get it to work. I basically want it to have my ipv6_prefix_delegated::5 , where 5 is the fixed suffix.
How is this possible to achieve?
And what to set in lookup "hostname" and "domain" in luci-app-ddns?

Error in ddns log, redacted private info

141203       : Current IP '2776:7499:c3:0:1239:8877:9073:5fyh' detected on network 'wan6'
 141205       : {"success":false,"errors":[{"code":6003,"message":"Invalid request headers","error_chain":[{"code":6103,"message":"Invalid format for X-Auth-Key header"}]}],"messages":[],"result":null}
 141205 ERROR : IP update not accepted by DDNS Provider

You can probably use a custom script as your IP address source, this script should read ipv6-prefix.address from the interface and append the suffix you want.
Alternatively you could use another DDNS provider who has an option to update the prefix only.

See https://openwrt.org/docs/guide-user/services/ddns/client#web_interface_instructions1

I need some help with scripting. Will this script work? and where to place it?

#!/bin/sh

INTERFACE="br-lan"
SUFFIX="::5"

get_ipv6_prefix() {
    ip -6 addr show dev "$INTERFACE" scope global | \
    grep 'inet6' | awk '{print $2}' | cut -d'/' -f1 | cut -d':' -f1-4 | \
    head -n 1
}

PREFIX=$(get_ipv6_prefix)
if [ -z "$PREFIX" ]; then
    echo "ERROR: No global IPv6 prefix found on interface $INTERFACE."
    exit 1
else
    FULL_IPV6="${PREFIX}${SUFFIX}"
    echo "$FULL_IPV6"
fi

I suggest using ifstatus instead of ip to get the prefix details:

ifstatus lan | jsonfilter -e '@["ipv6-prefix-assignment"][0].address'

The script should output an address or nothing. You can test it by manually running from the shell before referring to it in DDNS client configuration.

1 Like

It's actually only the prefix?

I don't know how to use the proper jsonfilter syntax, but to not get only the prefix, but the address

# ifstatus vlan64 \
| jsonfilter -e '@["ipv6-prefix-assignment"][0]' \
| jsonfilter -e '@["local-address"].address'
2003:xx:xxxx:xx40::1

This is the error I get even before running the script:

 175527       : Detect registered/public IP
 175527       : #> /usr/bin/nslookup 1038854.xyz  >/var/run/ddns/myddns_ipv6.dat 2>/var/run/ddns/myddns_ipv6.err
 175527       : Registered IP '2466:7488:c4:8517::5' detected
 175527  info : Starting main loop at 2025-04-09 17:55
 175527       : Detect current IP on 'network'
 175527       : Current IP '2406:7400:c4:4ebf::99' detected on network 'lan'
 175527       : Update needed - L: '2406:7400:00c4:4ebf:0000:0000:0000:0099' <> R: '2406:7400:00c4:8517:0000:0000:0000:0005'
 175527       : parsing script '/usr/lib/ddns/update_cloudflare_com_v4.sh'
 175527       : #> /usr/bin/curl -RsS -o /var/run/ddns/myddns_ipv6.dat --stderr /var/run/ddns/myddns_ipv6.err --noproxy '*' --header 'X-Auth-Email: manishxmadan@gmail.com'  --header 'X-Auth-Key: ***PW***'  --header 'Content-Type: application/json'  --request GET 'https://api.cloudflare.com/client/v4/zones?name=1038854.xyz'
 175528  WARN : CloudFlare reported an error:
 175528       : {"success":false,"errors":[{"code":6003,"message":"Invalid request headers","error_chain":[{"code":6103,"message":"Invalid format for X-Auth-Key header"}]}],"messages":[],"result":null}
 175528 ERROR : IP update not accepted by DDNS Provider
 175528       : Waiting 300 seconds (Check Interval)

And my script is

#!/bin/sh

get_ipv6_prefix() {
    ifstatus lan | jsonfilter -e '@["ipv6-prefix-assignment"][0].address'
}

PREFIX=$(get_ipv6_prefix)
[ -n "$PREFIX" ] && echo "${PREFIX%::*}::5"

You already had this warning in the first post!

Yes, I need help trying to understand what this means.
I think instead of just 2406:7400:00c4:4ebf::99 its including all those 0's and Cloudflare is not accepting? I am not sure.
Actually, the IP with 0's are a lengthier version of the short form ip.

'2406:7400:00c4:4ebf:0000:0000:0000:0099' <> R: '2406:7400:00c4:8517:0000:0000:0000:0005'

No, I think your authentication fails like the message from cloudflare states....

Edit, they also provide you with an error code, you may should look that up in their documentation?

1 Like

The goal is to get the real prefix and append the user defined suffix. The local address is out of interest.

Jup, fair enough.

Code

#!/bin/sh

get_ipv6_prefix() {
    ifstatus lan | jsonfilter -e '@["ipv6-prefix-assignment"][0].address'
}

PREFIX=$(get_ipv6_prefix)
[ -n "$PREFIX" ] && echo "${PREFIX%::*}:0000:0000:0000:0005" | sed 's/::/:0000:0000:/g'
username Bearer
password [Your API token]

Thanks to @AndrewZ @_bernd

1 Like

You can substitute any continuous occurrence of 0 with ::, but only once.

What was wrong with

PREFIX=$(get_ipv6_prefix)
[ -n "$PREFIX" ] && echo "${PREFIX%::*}::5"

?

Cloudflare didn't accept the shortened version

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.