NOTE - The latest version of Unifi Network Application 9.1.92 now supports Cloudflare as a Dynamic DNS provider so this is no longer required.
UnFi OS has in-built support for DDNS for WAN connections but Cloudflare is not supported OOTB. This Cloudflare Worker is designed to provide the intermediary support required to allow UnFi OS to update Cloudflare using the OOTB options.
This Cloudflare Worker accepts parameters specified under Settings > Internet > WAN > Dynamic DNS > custom which UniFi OS uses to call whenever an IP change is detected. The Cloudflare Worker then calls Cloudflare DNS API to update the specified DNS A record with the new IP address.
Based on the implementation from - https://github.com/willswire/unifi-ddns - Thanks!
Updated 22-08-2024 - Added Telegram Notifications
You need to be using Cloudflare for you domain which means using Cloudflare nameservers and managing your domains DNS within Cloudflare.
- Deploy the Worker using the Cloudflare dashboard
- In the Cloudflare Workers dashboard - note the
\*.workers.devURL - Create a Cloudflare API token to update DNS records -
https://dash.cloudflare.com/profile/api-tokens- Click
Create token, selectCreate custom token - Choose
Zone > DNS > Editfor permissions, and include your zone underZone Resources - Copy the API Key which will be used later
- Clone or download this project
- Ensure you have
Cloudflare [Wrangler CLI](https://developers.cloudflare.com/workers/wrangler/install-and-update/)installed - Log in with Cloudlfare Wrangler and run
wrangler deploy - Note the
\*.workers.devURL after creation - Create an API token mentioned above
The latest update includes support for Telegram notifications. Two environment variables are required for this to work.
telegramBotTokentelegramChatId
These need to be created as environment variables on the Cloudflare Worker.
https://unifi.ui.com/- Click
Settings > Internet > WAN > Dynamic DNS - Click
Create New Dynamic DNSand enter the following parameters -Service: ChoosecustomHostname: DNS record to update insubdomain.domain.comformat to update (example -subdomain.domain.comordomain.comfor root)Username: Domain name (exampledomain.com)Password: Cloudflare API Token as created aboveServer: Cloudflare Worker URL<worker-name>.<worker-subdomain>.workers.dev/update?ip=%i&hostname=%h
Test the setup and force a manual update on a UDM-Pro -
- SSH into your the UDM-Pro device
- Run
ps aux | grep inadyn - Note the configuration file path which looks similar to
/run/ddns-eth4-inadyn.conf - Run
inadyn -n -1 --force -f <config-path>(example -inadyn -n -1 --force -f /run/ddns-eth4-inadyn.conf) - Check the response and Cloudlare DNS or Cloudflare Worker logs
/var/log/messagescan also be checked error messages
- For subdomains (example -
subdomain.domain.com) - create an A record manually in Cloudflare DNS first. - For errors with hostname resolution (
inadyn[2173778]: Failed resolving hostname https: Name or service not known), removehttps://from theServerfield - If a second domain is required -
Create New Dynamic DNSin UniFi OS and use the servicedyndnswith the same setup as above