Skip to content

Cloudflare DDNS (Dynamic DNS) support for UniFi OS

Notifications You must be signed in to change notification settings

slynn1324/unifi-cloudflare-ddns

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloudflare DDNS for UniFi OS

A Cloudflare Worker script that exposes a UniFi-compatible DDNS API to dynamically update the IP address of a DNS A record.

Why?

I have a UniFi Dream Machine Pro (UDM-Pro), and I want to update my Cloudflare domain name DNS records when my public IP address changes. Unfortunately, UniFi does not come pre-configured to support Cloudflare as one of its DDNS providers.

Configuring Cloudflare

  1. Create a new Cloudflare Worker
  2. 'Quick Edit' the worker within your browser.
  3. Copy and paste the contents of index.js into the code editor for your worker. Ensure that you are replacing any boilerplate/code that is currently there.
  4. Once you have created the worker, take note of it's *.workers.dev route. More on routes for Cloudflare Workers here.
  5. Create an API token so the Worker can update your DNS records. Go to https://dash.cloudflare.com/profile/api-tokens and select "Create custom token". Enable permissions for both Zone:Read and DNS:Edit. Copy your API Key - you will need it later when configuring your UniFi OS Controller.
  6. Update the 'KEYS' map at the top of the worker javascript code. Each key must be exactly 8 characters, and the value should be the allowed hostname value for that key. You will prepend the 8-character key to the password (token) in the configuration below.

Configuring UniFi OS

  1. Log on to your UniFi OS Controller
  2. Navigate to Settings > Internet > WAN and scroll down to Dynamic DNS.
  3. Click Create New Dynamic DNS and enter the following information:
  • Service: choose dyndns
  • Hostname: the full subdomain and hostname of the record you want to update (e.g. subdomain.mydomain.com, mydomain.com for root domain)
  • Username: the domain name containing the record (e.g. mydomain.com)
  • Password: Concatenate the appropriate KEY and the Cloudflare API Token you created earlier. e.g., . The Key must be exactly 8 characters.
  • Server: the Cloudflare Worker route <worker-name>.<worker-subdomain>.workers.dev
    • as of Unifi Network 7.0.25 this needs to be <worker-name>.<worker-subdomain>.workers.dev/nic/update?hostname=%h&myip=%i.

Acknowledgements

About

Cloudflare DDNS (Dynamic DNS) support for UniFi OS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%