- Shell 53%
- PowerShell 44.6%
- Dockerfile 2.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .github | ||
| openwrt | ||
| systemd | ||
| CHANGELOG.md | ||
| ddns.conf.example | ||
| ddns.ps1 | ||
| ddns.sh | ||
| Dockerfile | ||
| LICENSE | ||
| README.md | ||
| README.pt.md | ||
| repo.json | ||
Dynamic DNS for MozOut
Reach your home, office or camera by name, even when the internet provider changes your IP. This client 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.
| What | File |
|---|---|
| OpenWrt routers, Raspberry Pi, Linux, macOS | ddns.sh (POSIX sh and curl) |
| Windows | ddns.ps1 (PowerShell 5.1 or 7) |
| systemd | systemd/ddns.service and systemd/ddns.timer |
| OpenWrt, update as soon as the WAN comes up | openwrt/hotplug |
| Docker | Dockerfile |
Before you start
- The domain must be active on your account, with DNS on.
- Create an API key with the
dns:readanddns:writepermissions in the API Center of My MozOut. Do not give it an IP list: your IP is the thing that changes. Test first with asandbox_key: the client runs normally and nothing changes in the zone. - Pick a name, such as
home, forhome.example.com.
The address of the API is already in the client. You only give the key.
Linux and Raspberry Pi (systemd)
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 # key, domain and name
sudo mozout-ddns # first run, by hand
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
It checks every 5 minutes. See what it did with journalctl -u mozout-ddns. Without systemd, use cron: */5 * * * * /usr/local/bin/mozout-ddns -q.
OpenWrt
opkg update && opkg install curl ca-bundle
cp ddns.sh /usr/bin/mozout-ddns && chmod 755 /usr/bin/mozout-ddns
cp ddns.conf.example /etc/mozout-ddns.conf && chmod 600 /etc/mozout-ddns.conf
vi /etc/mozout-ddns.conf
echo '*/5 * * * * /usr/bin/mozout-ddns -q' >> /etc/crontabs/root && /etc/init.d/cron restart
cp openwrt/hotplug /etc/hotplug.d/iface/95-mozout-ddns
If the WAN interface of the router has the public IP, set DDNS_IFACE=wan and the client reads it from there, without asking anyone. Set DDNS_SYSLOG=yes to see changes in logread. If the address is private (10.x, 192.168.x, 100.64.x), the router is behind another one: keep the default address service.
The API has no dyndns2 update address, so the Dynamic DNS menu built into routers cannot be used with it. Run this client on the router instead.
Windows
[Environment]::SetEnvironmentVariable('MOZOUT_API_KEY', 'prod_...', 'User')
.\ddns.ps1 -Domain example.com -Name home -Type A
Every 5 minutes with Task Scheduler:
$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -ExecutionPolicy Bypass -File C:\ddns\ddns.ps1 -Domain example.com -Name home -Quiet'
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 5)
Register-ScheduledTask -TaskName 'MozOut DDNS' -Action $action -Trigger $trigger
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.
Settings
| Setting | Default | What |
|---|---|---|
MOZOUT_API_KEY |
The API key. Or DDNS_API_KEY_FILE with the path of a file holding it. |
|
DDNS_DOMAIN |
Your domain. | |
DDNS_NAME |
@ |
Names to update, separated by spaces. @ is the domain itself. |
DDNS_TYPE |
A |
A, AAAA or both. |
DDNS_TTL |
300 |
Seconds, from 60. |
DDNS_IP4_URL, DDNS_IP6_URL |
ipify, icanhazip | Address services, tried in order. |
DDNS_IFACE, DDNS_IFACE6 |
Read the IP from this interface instead. | |
DDNS_IP4, DDNS_IP6 |
A fixed address. | |
DDNS_FORCE_HOURS |
24 |
Check the zone again after this many hours even without a change. |
DDNS_DELETE_EXTRA |
no |
yes deletes other records with the same name and type. |
DDNS_INTERVAL |
300 |
Seconds between checks with --loop. |
Options of ddns.sh: --force, --dry-run, --loop, -q, -c FILE. The PowerShell script takes the same settings as parameters (-Domain, -Name, -Type, -Ttl, -Force, -DryRun, -DeleteExtra, -Quiet) or the same environment variables.
How it works
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. 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. The key is never printed, and it reaches curl through standard input, so it does not show in the process list.
A copy of the zone is kept before each change: you can go back in My MozOut or with the API. More in the DNS documentation.
License
MIT. See LICENSE.
Maintained by RLX Holdings.