5

My ISP recently started providing IPv6. I have a Raspi with PiVPN at home and like to be able to reach my LAN when I am away. I have been using DuckDNS for years now and for IPv4 it worked great. However, because they are on AWS, it seems they are unable to resolve IPv6, so you have to provide it yourself to their update API. This API usually returns OK if everything was fine and KO if there was an issue.

This is the code I am using to update:

token='mytoken'
domain='mydomain'
ipv6=$(ip addr show dev "eth0" | sed -e's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d' | grep -v '^fd00' | grep -v '^fe80' | head -1)

echo url="https://www.duckdns.org/update?domains=$domain&token=$token&ip=&ip6v=$ipv6&clear=true&verbose=true" | curl -k -o ~/duckdns/duckdns.log -K -

I compared my "local" ipv6 and one I get from curling another server as described here, but there seems to be no difference so I am pretty sure I correctly get my IPv6.

It returns an OK but then says that I provided an invalid IP when I try to check it on the website.

Any ideas on how to add IPv6 to a duckdns domain?

jaaq
  • 390
  • 5
  • 18
  • Try escaping your IPv6 address before you put it into the URL. : is a reserved character. Replace all the : with `%3A`, e.g via `sed 's/:/%3A/g'` I can confirm that your method to get the ipv6 address seems to work. That said, I'd recommend grepping for 'scope global' - that will get your routable address and skip the link-local (fe80) and ULA (fd00) addresses. – Dan Pritts May 14 '21 at 15:57
  • @DanPritts Hi I just tried your solution. It results in an ipv6 like: `2a02%3A8388%3Axxxx%3Aae00%3Axxxx%3Aebff%3Axxxx%3A6c24`, so that seems okay. When I try to update duckdns, I get back `OK NOCHANGE` but on duckdns.org I still get the error: `error: invalid ipv6 address entered for MYDOMAIN.duckdns.org`. Did you get ipv6 updates to work on duckdns? – jaaq May 29 '21 at 10:13
  • No, i don't use duckdns - that's why i left it as a "try this". – Dan Pritts Jun 01 '21 at 21:27
  • I improved the `grep` pipe to also exclude `fc00::/7` addresses, and changed the sed marker from `/` to `!` for clearer visibility since there's an escaped `/` in the expression: ```ipv6=$(ip addr show dev "enp6s0" | sed -e 's!.*inet6 \([^ ]*\)\/.*$!\1!;t;d' | grep -v '^fc' | grep -v '^fd00' | grep -v '^fe80' | head -1)``` – wyphan Feb 28 '22 at 17:28

2 Answers2

5

So for some reason, the way to publish an IP as recommended by DuckDNS themselves under the install-tab doesn't work. If you change the line doing curl from parsing echo through stdout and setting an url variable to just constructing the string and curling that, it works:

curl -s "https://www.duckdns.org/update?domains=$domain&token=$token&ip=&ipv6=$ipv6addr" -o ~/duckdns/duckdns.log

This version will let DuckDNS figure out your IPv4 and set your IPv6 according to what your device configured itself to as shown in the question. Make sure to run the script regularly as your global IPv6 may change if a NDP finds a conflicting address or if you haven't set a static IPv6.

jaaq
  • 390
  • 5
  • 18
-1

Run this script periodically using crontab

duck.sh

#!/bin/bash
domain=mydomain
token=aaaabbbb-cccc-4444-8888-ddeeff001122
ipv6addr=$(curl -s https://api6.ipify.org)
ipv4addr=$(curl -s https://api.ipify.org)
echo "https://www.duckdns.org/update?domains=$domain&token=$token&ip=$ipv4addr&ipv6=$ipv6addr"
curl -s "https://www.duckdns.org/update?domains=$domain&token=$token&ip=$ipv4addr&ipv6=$ipv6addr" -o ~/duckdns/duckdns.log
Dojo
  • 119
  • 4
  • Why the unnecessary calls to another API? – jaaq Nov 30 '21 at 14:36
  • To get around NAT. Machines need not be aware of their Public IPs. – Dojo Dec 03 '21 at 07:40
  • That's only half-correct. For IPv6 there is no need for NAT, there's plenty of addresses. Some may do it to hide their machines, but that's enterprise intranet stuff and not something your ISP would do, as it's extra work for no benefit. And for IPv4 that would be correct, but duckdns.org will know your public IP anyway, otherwise it couldn't respond to your package. So if you leave that IPv4 field empty, duckdns will figure it out by itself, as described in the install docs. – jaaq Dec 04 '21 at 11:32