117 lines
5.8 KiB
Markdown
117 lines
5.8 KiB
Markdown
<p align="center"><img src="assets/logo.png" alt="Interweb" width="280"></p>
|
|
|
|
# Dynamic DNS for Interweb Mozambique
|
|
|
|
<!-- badges:start -->
|
|
[](https://git.interweb.co.mz/interweb-mz/ddns/releases) [](LICENSE)
|
|
<!-- badges:end -->
|
|
|
|
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 Interweb Mozambique API.
|
|
|
|
[Português](README-pt.md)
|
|
|
|
| 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
|
|
|
|
1. The domain must be active on your account, with DNS on.
|
|
2. Create an API key with the `dns:read` and `dns:write` permissions in the [API Center](https://www.meu.interweb.co.mz/api-center.php) of Meu Interweb. Do not give it an IP list: your IP is the thing that changes. Test first with a `sandbox_` key: the client runs normally and nothing changes in the zone.
|
|
3. Pick a name, such as `home`, for `home.example.co.mz`.
|
|
|
|
The address of the API is already in the client. You only give the key.
|
|
|
|
## Linux and Raspberry Pi (systemd)
|
|
|
|
```bash
|
|
sudo install -m 755 ddns.sh /usr/local/bin/interweb-mz-ddns
|
|
sudo install -m 600 ddns.conf.example /etc/interweb-mz-ddns.conf
|
|
sudo nano /etc/interweb-mz-ddns.conf # key, domain and name
|
|
sudo interweb-mz-ddns # first run, by hand
|
|
sudo install -m 644 systemd/ddns.service /etc/systemd/system/interweb-mz-ddns.service
|
|
sudo install -m 644 systemd/ddns.timer /etc/systemd/system/interweb-mz-ddns.timer
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable --now interweb-mz-ddns.timer
|
|
```
|
|
|
|
It checks every 5 minutes. See what it did with `journalctl -u interweb-mz-ddns`. Without systemd, use cron: `*/5 * * * * /usr/local/bin/interweb-mz-ddns -q`.
|
|
|
|
## OpenWrt
|
|
|
|
```sh
|
|
opkg update && opkg install curl ca-bundle
|
|
cp ddns.sh /usr/bin/interweb-mz-ddns && chmod 755 /usr/bin/interweb-mz-ddns
|
|
cp ddns.conf.example /etc/interweb-mz-ddns.conf && chmod 600 /etc/interweb-mz-ddns.conf
|
|
vi /etc/interweb-mz-ddns.conf
|
|
echo '*/5 * * * * /usr/bin/interweb-mz-ddns -q' >> /etc/crontabs/root && /etc/init.d/cron restart
|
|
cp openwrt/hotplug /etc/hotplug.d/iface/95-interweb-mz-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
|
|
|
|
```powershell
|
|
[Environment]::SetEnvironmentVariable('INTERWEB_API_KEY', 'prod_...', 'User')
|
|
.\ddns.ps1 -Domain example.co.mz -Name home -Type A
|
|
```
|
|
|
|
Every 5 minutes with Task Scheduler:
|
|
|
|
```powershell
|
|
$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -ExecutionPolicy Bypass -File C:\ddns\ddns.ps1 -Domain example.co.mz -Name home -Quiet'
|
|
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 5)
|
|
Register-ScheduledTask -TaskName 'Interweb Mozambique DDNS' -Action $action -Trigger $trigger
|
|
```
|
|
|
|
## Docker
|
|
|
|
```bash
|
|
docker build -t interweb-mz-ddns .
|
|
docker run -d --restart unless-stopped --name ddns \
|
|
-e INTERWEB_API_KEY=prod_... -e DDNS_DOMAIN=example.co.mz -e DDNS_NAME=home \
|
|
interweb-mz-ddns
|
|
```
|
|
|
|
For `AAAA` records, add `--network host` so the container has IPv6.
|
|
|
|
## Settings
|
|
|
|
| Setting | Default | What |
|
|
|---|---|---|
|
|
| `INTERWEB_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 Meu Interweb or with the API. More in the [DNS documentation](https://docs.interweb.co.mz/dns/).
|
|
|
|
Before it touches DNS, the client checks the key. It stops with exit code 3 when the API refuses the key, and 4 when the key lacks `dns:read` or `dns:write`.
|
|
|
|
## License
|
|
|
|
MIT. See [LICENSE](LICENSE).
|
|
|
|
---
|
|
|
|
Maintained by RLX Holdings.
|