USG 3-P UniFi Script for pulling the IPv6-Address from DynDNS and insert it into a IPv6-Group that is created on the WebUI of the UniFi Controller
Thanks to:
The script from above was only for IPv4 so I modified it a bit.
How To:
-
Create a new IPv6-Address Group on your UniFi Controller via WebUI (you can insert a random IPv6-Address)
-
SSH into your USG3-P
-
sudo su root
-
show configuration
-
Now look for the group that you created previously on the WebUI and copy the ID .
Example:
ipv6-address-group (614a0a974e56af19bf2c4ec8) <- this is the group ID
After this quit the output and:
- vi ipv6-dyndns.sh
- Copy the code from below
#/bin/bash
run=/opt/vyatta/bin/vyatta-op-cmd-wrapper
white_list=$($run show firewall group AlphaPiDDNS_IPv6 | grep -A5 Members |grep -v Members | awk '{ print $1 }' )
resolved_ips=$(getent hosts example.dyndv6.net | awk '{ print $1 }')
resolved_ips="$resolved_ips"
iparray=( `echo "$resolved_ips"`)
if [ "$white_list" = "$resolved_ips" ]; then
:
else
#if addresses have changed, remove address-group "614a0a974e56af19bf2c4ec8" and recreate it with the new addresses
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper begin
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper delete firewall group ipv6-address-group 614a0a974e56af19bf2c4ec8
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper set firewall group ipv6-address-group 614a0a974e56af19bf2c4ec8 ipv6-address "${iparray[0]}"
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper commit
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper save
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper end
fi
Replace example.dyndv6.net
with your dyndns.
Replace at:
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper delete firewall group ipv6-address-group 614a0a974e56af19bf2c4ec8
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper set firewall group ipv6-address-group 614a0a974e56af19bf2c4ec8 ipv6-address "
with your group ID
And that's it.
don't forget chmod+x ipv6-dyndns.sh
If you want you can create an cronjob with cronjob -e and run it for example every minute.