Dynamic DNS client: keep a domain pointed at a changing IP on OpenWrt, Raspberry Pi, Linux, Windows and Docker

API & DocumentationInfrastructure & DevOps·· 117 views· 4 min read

This client lets you reach your home, office or camera by name, even when the internet provider changes your IP. It checks the public IP of your network and, when it changes, updates an A (IPv4) and/or AAAA (IPv6) record of your domain through the MozOut API. If the idea is new to you, read what dynamic DNS is first.

What it does

There is a version for each place: ddns.sh (POSIX sh and curl) for OpenWrt routers, Raspberry Pi, Linux and macOS; ddns.ps1 for Windows (PowerShell 5.1 or 7); systemd/ddns.service and systemd/ddns.timer for systemd; openwrt/hotplug so OpenWrt updates as soon as the WAN comes up; and a Dockerfile.

It remembers the last IP it sent and only calls the API when the IP changes, or once every DDNS_FORCE_HOURS. Then it reads the zone, changes the record if the value is different, or creates it if there is none.

What you need

A domain that is active on your account, with DNS on, and an API key created in the API Center of My MozOut. Pick a name too, such as home, for home.example.com. The API address is already in the client: you only give the key.

Installing, step by step

1 Download the source of the latest release and unzip it.
2 On Linux or a Raspberry Pi with systemd, run the commands below. In /etc/mozout-ddns.conf, put your key, domain and name.
3 The first time, run sudo mozout-ddns by hand. After that the timer checks every 5 minutes.
4 See what it did with journalctl -u mozout-ddns.

sudo install -m 755 ddns.sh /usr/local/bin/mozout-ddns
sudo install -m 600 ddns.conf.example /etc/mozout-ddns.conf
sudo nano /etc/mozout-ddns.conf
sudo mozout-ddns
sudo install -m 644 systemd/ddns.service /etc/systemd/system/mozout-ddns.service
sudo install -m 644 systemd/ddns.timer /etc/systemd/system/mozout-ddns.timer
sudo systemctl daemon-reload
sudo systemctl enable --now mozout-ddns.timer

Without systemd: use cron, with */5 * * * * /usr/local/bin/mozout-ddns -q.

OpenWrt: start with opkg update && opkg install curl ca-bundle. The other commands are in the README. The Dynamic DNS menu built into routers cannot be used, because the API has no dyndns2 update address: run this client on the router instead. If the WAN interface of the router has the public IP, set DDNS_IFACE=wan and the client reads it from there.

Windows: set the key and run the script. The README shows how to run it every 5 minutes with Task Scheduler.

[Environment]::SetEnvironmentVariable('MOZOUT_API_KEY', 'prod_...', 'User')
.\ddns.ps1 -Domain example.com -Name home -Type A

Docker:

docker build -t mozout-ddns .
docker run -d --restart unless-stopped --name ddns \
-e MOZOUT_API_KEY=prod_... -e DDNS_DOMAIN=example.com -e DDNS_NAME=home \
mozout-ddns

For AAAA records, add --network host so the container has IPv6.

The API key and its permissions

The key needs dns:read and dns:write. Do not give it an IP list: your IP is the thing that changes. Before it touches DNS, the client checks the key. It stops with exit code 3 when the API refuses the key, and 4 when one of the two permissions is missing.

Testing without spending

Test first with a sandbox_ key: the client runs normally and nothing changes in the zone. ddns.sh also has a --dry-run option.

Good to know

Where the IP comes from: the API has no operation that tells you your own IP, so the client asks an address service (by default api.ipify.org, then icanhazip.com), reads it from an interface, or uses the value you give.

The key stays hidden: it is never printed, and it reaches curl through standard input, so it does not show in the process list.

Going back: a copy of the zone is kept before each change. You can go back to it in My MozOut or through the API.

IPv4 and IPv6: DDNS_TYPE takes A, AAAA or both. The full list of settings is in the README.

Help

If the record does not change and you cannot tell why, open a support ticket and tell us the exit code and the message you see. The code is in the client repository, under the MIT license.

Ready to give your network a fixed name?

Download the latest release

SEE ALSO

Dynamic DNS: a fixed name for an address that keeps changing

DNS through the API

Creating an API key

The repository on MozOut Git

SDKs and integrations, in the API documentation

RECOMMENDED PRODUCT

VPS server with root access

Resources of your own, the OS you choose, reinstall whenever you like. from ₦12,600.00/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.