Skip to content

Instantly share code, notes, and snippets.

@xezpeleta
Created January 22, 2019 12:11
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xezpeleta/cf0a982419581415c29340051c0537d2 to your computer and use it in GitHub Desktop.
Save xezpeleta/cf0a982419581415c29340051c0537d2 to your computer and use it in GitHub Desktop.
Dynamic DNS on the Ubiquiti EdgeRouter X

Ubiquiti EdgeRouter X: custom dynamic DNS

ssh ubnt@<your-ip>
configure

Obtain your public IP address behind a NAT: using ipinfo.io

set service dns dynamic interface eth0 web https://ipinfo.io/json
set service dns dynamic interface eth0 web-skip "ip: "

Dynamic DNS with your custom domain: using Cloudflare

First of all, create the subdomain in the Cloudflare zone.

set service dns dynamic interface eth0 service custom-cloudflare host-name <hostname.yourdomain.org>
set service dns dynamic interface eth0 service custom-cloudflare login <user@domain.com>
set service dns dynamic interface eth0 service custom-cloudflare password <CloudFlare API key>
set service dns dynamic interface eth0 service custom-cloudflare protocol cloudflare
set service dns dynamic interface eth0 service custom-cloudflare options zone=<yourdomain.com>

Commit and save

commit
save

https://help.ubnt.com/hc/en-us/articles/204976324-EdgeRouter-Custom-Dynamic-DNS

@looselyrigorous
Copy link

Why not use https://ipinfo.io/ip instead? It returns just the IP, so you don't need the web-skip option (which feels really hacky).

@xezpeleta
Copy link
Author

Didn't know that! 😢

@giovanni-d
Copy link

giovanni-d commented Oct 2, 2021

If you want to set multiple options you have to use double quotes. Example:

set service dns dynamic interface eth0 service custom-cloudflare options "zone=yourdomain.com use=web ssl=yes ttl=1"

@kule
Copy link

kule commented Feb 1, 2022

Incase this helps someone with debugging...

Make sure you change the interface above to the correct one e.g. if you are in the UK you could well be on a provider like BT that still uses pppoe - so you'll probably want the pppoe0 interface instead of eth0.

Cloudflare issues: the current version of ddclient is v3.8.3 (for Edge Router 4 with v2.0.9 firmware). This old version of ddclient doesn't work with the new cloudflare api tokens, so you must use the old global api key token instead.

v3.9.x versions of ddclient should work with the newer api tokens so have a check to see what the ddclient version your firmware is using is:

/usr/sbin/ddclient --version

For me I was having unhelpful errors in tail /var/log/messages like this:

Feb  1 20:39:24 ubnt ddclient[1234]: WARNING:  file /var/cache/ddclient/ddclient_eth0.cache, line 3: Invalid Value for keyword 'ip' = ''

and show dns dynamic status was giving noconnect e.g.

interface    : eth0
ip address   : 
host-name    : dns.example.com
last update  : Tue Feb  1 01:02:03 2022
update-status: noconnect

You can find out which part of the process is failing by calling ddclient directly. To get some debug output use the following (change the conf filename to match the interface you are using e.g. eth0 or pppoe0 etc):

sudo /usr/sbin/ddclient -daemon=0 -debug -verbose -noquiet -file /etc/ddclient/ddclient_eth0.conf

You can edit your ddclient.conf with for example (change the file name to eth0 to pppoe0 or whatever interface you are using):

sudo vi /etc/ddclient/ddclient_eth0.conf

This'll make it easy to try different settings and fix your issue. If it's not using your new config try removing the cache file e.g. sudo rm /var/cache/ddclient/ddclient_eth0.cache (remember to change the filename to match your interface again).

Once you've got it working, update your setup with update dns dynamic interface eth0.

A working setup will give show dns dynamic status with:

interface    : eth0
ip address   : 1.2.3.4
host-name    : dns.example.com
last update  : Tue Feb  1 01:02:03 2022
update-status: good

@jradwan
Copy link

jradwan commented Jan 26, 2024

Thank you @kule! I was struggling getting dynamic DNS to work on my ER-X running EdgeOS v1.10.11 and your comment helped me figure it out. Had to switch to the Global API key and also use "api.cloudflare.com/client/v4" for the server instead of "www.cloudflare.com" like I had seen on other write-ups.

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