Skip to content

Instantly share code, notes, and snippets.

@CyBiS
Last active November 13, 2022 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save CyBiS/60a11d6995e5055010bb45cc95e0c9a9 to your computer and use it in GitHub Desktop.
Save CyBiS/60a11d6995e5055010bb45cc95e0c9a9 to your computer and use it in GitHub Desktop.
Synology router configuration files for adding dynv6.com DDNS provider.
# add following lines to /etc.defaults/ddns_provider.conf
[dynv6.com]
modulepath=/usr/syno/bin/ddns/dynv6.php
queryurl=http://dynv6.com
#!/usr/bin/php -d open_basedir=/usr/syno/bin/ddns
<?php
$script = (string)$argv[0];
$ret = 'badagent';
if($argc !== 5)
{
echo $ret;
syslog(LOG_CRIT, $script.':'.__LINE__.' '.$ret);
exit();
}
$token = (string)$argv[1];
$hostname = (string)$argv[3];
$ip = (string)$argv[4];
// check the hostname contains '.'
if(strpos($hostname, '.') === false)
{
echo $ret;
syslog(LOG_CRIT, $script.':'.__LINE__.' '.$ret);
exit();
}
// only for IPv4 format
if(!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))
{
echo $ret;
syslog(LOG_CRIT, $script.':'.__LINE__.' '.$ret);
exit();
}
$url = 'https://dynv6.com/api/update?hostname='.$hostname.'&ipv4='.$ip.'&token='.$token;
// syslog(LOG_CRIT, $script.':'.__LINE__.' REQUEST '.$url);
$req = curl_init();
curl_setopt($req, CURLOPT_URL, $url);
curl_setopt($req, CURLOPT_RETURNTRANSFER, TRUE);
$res = curl_exec($req);
curl_close($req);
// syslog(LOG_CRIT, $script.':'.__LINE__.' RESPONSE '.$res);
switch(trim($res))
{
case 'addresses updated':
$ret = 'good';
break;
case "addresses unchanged":
$ret = 'nochg';
break;
case 'hostname not found':
$ret = 'nohost';
break;
default:
$ret = trim($res);
}
echo $ret;
syslog(LOG_CRIT, $script.':'.__LINE__.' '.$ret);
@fredlcore
Copy link

Thanks for this script, but this only updates the IPv4 address, right? I search for a solution that updates the IPv6 address in case my provider changes the prefix (which happens every few weeks).

@CyBiS
Copy link
Author

CyBiS commented Nov 12, 2022

As I switched to pfSense and RFC 2136 dynamic DNS updates, I don't use that script anymore.

But you might want to try if(!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) in line 27 and $url = 'https://dynv6.com/api/update?hostname='.$hostname.'&ipv6='.$ip.'&token='.$token; in line 34.

You can find the dynv6 update API at https://dynv6.com/docs/apis#update in case you need further modifications of the update URL.

@fredlcore
Copy link

Thanks for the quick reply! Unfortunately, it does not work as the configuration always seems to choose the IPv4 address:
Bildschirmfoto 2022-11-12 um 12 26 06
So in this case, it tries to send the 185.68.78.255 (which is probably my unusable DSLite IPv4 address).

@CyBiS
Copy link
Author

CyBiS commented Nov 12, 2022

So the problem is that the Synolgoy WebUI provides the IPv4 instead of the IPv6 address. Either you can somehow change that in the UI or you get the IPv6 address in the php script similar to the approach here.

@fredlcore
Copy link

Thanks, that could work - the only problem is that I have two IPv6 addresses listed when executing ip addr - one that is labeled as deprecated but is actually the one with the recently provider-updated prefix (which works when directly accessing it), and the other one that is considered active but has actually the old prefix before the new assignment (which no longer works). But I guess that is a different problem...

@CyBiS
Copy link
Author

CyBiS commented Nov 12, 2022

Yes, seems to be an IPv6 specific assignment topic. As I'm still on IPv4, can't be of any assistance here, sorry.

@fredlcore
Copy link

No worries, your suggestions already helped me a lot, thank you for that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment