aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: f168a188d0d3ed2bfd89502a4255e641679ff591 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# DDNS-Utils
A collection of scripts to manage various aspects of using dynamic DNS,
usually to cope with dynamic IP addressing

## he-dyndns
A Python-based script to update dynamic DNS records when using the
Hurricane Electric DNS service at `dns.he.net`. It uses only Python 3's
standard library.

Unless an address is supplied with `--addr4` or `--addr6`, the script asks
`https://ip.mfamily.org/` for its public address over the selected IP family.
It compares that address with local state and contacts HE only when the address
has changed. IPv4 is selected by default; use `--v6` for IPv6.

State defaults to `/var/lib/he-dyndns/state.json`. The file contains entries
for multiple records and both address families. Updates are locked and written
atomically, so separate IPv4 and IPv6 cron jobs can share it. State is recorded
only after HE returns `good` or `nochg`. Both address discovery and HE updates
use certificate-validated HTTPS.

Explicit addresses retain unconditional update behavior and do not read or
write the state file:

```
he-dyndns --addr4 192.0.2.10 home.example.com
he-dyndns --addr6 2001:db8::10 home.example.com
```

## ddns-update-rfc2136 
A Python-based script to update DNS records in a master server
that is RFC2136-compliant and supports TSIG-based updates.
This script is a wrapper around nsupdate(1). Properly configured
TSIG keys are needed.

## RouterOS Script for Address List Updates (ros-ddns-addrlist)
A small RouterOS script for Mikrotik RouterOS to query a DNS
name and put that IP address into an AddressLis. Note that the
``:resolve`` function doesn't support RR types. If there's an A you 
get that. If there's no A, you get AAAA. If there's neither, the script
will bomb.

# he-dyndns Installation / Use
Copy `he-dyndns` somewhere useful such as `/usr/local/bin`. No third-party
Python modules are required. If it runs as a non-root service account, create
the state directory for that account first, or select a writable path with
`--state-file`.

## Configuration
Unless using the `--key` argument, keys for the dynamic record
are read from `/etc/he-dyndns.conf` or from an alternative
location specified by `--keyfile`. The configuration file
format is one section [keys] with record = key pairs. For example:

```
[keys]
dynamic.example.com = 123412341234
```

Other configuration sections will be ignored.

## Usage
```
usage: he-dyndns [-h] [--v4 | --v6] [--addr4 ADDR4 | --addr6 ADDR6]
                 [--check-url CHECK_URL] [--state-file STATE_FILE]
                 [--keyfile KEYFILE] [--key KEY] [--timeout TIMEOUT] [--debug]
                 record

Update Hurricane Electric DNS dynamic record

positional arguments:
  record             DNS record to update

options:
  -h, --help         show this help message and exit
  --v4               Update IPv4 A record (default)
  --v6               Update IPv6 AAAA record
  --addr4 ADDR4      Use this IPv4 address; bypass discovery/state comparison
  --addr6 ADDR6      Use this IPv6 address; bypass discovery/state comparison
  --check-url URL    Public address service (default https://ip.mfamily.org/)
  --state-file FILE  Local comparison state (default /var/lib/he-dyndns/state.json)
  --keyfile KEYFILE  Key config file (default /etc/he-dyndns.conf)
  --key KEY          HE DDNS key for record; overrides --keyfile
  --timeout SECONDS  Network timeout in seconds (default 10)
  --debug            Enable debug logging

```

## Return Values
Returns 0 on success (successful change or no change) or 1 on failure. 
Failures also include a single line error message.

For example, two cron entries can check both families while sharing the state
file:

```
*/5 * * * * /usr/local/bin/he-dyndns home.example.com
*/5 * * * * /usr/local/bin/he-dyndns --v6 home.example.com
```

# ip.mfamily.org address service

`ip-echo-daemon` is the backend for the dual-stack public address check. It
binds to `127.0.0.1:8080` by default and trusts `X-Real-IP` only when the
connection comes from loopback. The included nginx configuration overwrites
that header with nginx's actual peer address.

The hostname must have both an A record and an AAAA record pointing to the
VPS, and nginx must have a valid certificate for it. The included paths assume
a Let's Encrypt certificate. On the VPS:

```
install -m 0755 ip-echo-daemon /usr/local/bin/ip-echo-daemon
install -m 0644 deploy/ip-echo-daemon.service /etc/systemd/system/ip-echo-daemon.service
install -m 0644 deploy/ip.mfamily.org.nginx /etc/nginx/sites-available/ip.mfamily.org
ln -s /etc/nginx/sites-available/ip.mfamily.org /etc/nginx/sites-enabled/ip.mfamily.org
systemctl daemon-reload
systemctl enable --now ip-echo-daemon.service
nginx -t
systemctl reload nginx
```

The nginx server block redirects HTTP to HTTPS, listens on IPv4 and IPv6, and
proxies only `/`:

```
server {
    listen 80;
    listen [::]:80;
    server_name ip.mfamily.org;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name ip.mfamily.org;

    ssl_certificate /etc/letsencrypt/live/ip.mfamily.org/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/ip.mfamily.org/privkey.pem;

    location = / {
        proxy_pass http://127.0.0.1:8080/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass_request_body off;
        proxy_set_header Content-Length "";
    }

    location / {
        return 404;
    }
}
```

Verify both paths from another dual-stack system:

```
curl -4 https://ip.mfamily.org/
curl -6 https://ip.mfamily.org/
```

# ddns-update-rfc2136 Installation/Use
This script relies on the `netifaces` and `subprocess` libraries
that are not always installed by default in Python3. Install those
modules from `apt`, `dnf`, or `pip` as appropriate for your
system. 

Copy `ddns-update-rfc2136` somewhere useful such as `/usr/local/bin`.

## Configuration
The script expects there to be a file `/etc/ddns-RECORD.key` for every `record`
being updated containing *only* the TSIG key for that record. For example, 
updating the record `foo.example.com` should have a file named 
`/etc/ddns-foo.example.com.key` available with that RR's key. It's possible
to specify `--keyfile` to select an alternate location. Make sure that the key
file is properly protected so only authorized users can view the contents.

## General Use
This script finds the appropriate IP address from the interface specified
in the `interface` position and then updates the record `record` in the
zone `zone` on server `server`.

For IPv4, each address is on a unique sub interface - e.g. eth0 vs eth0:0. 
To use the IP address other than the main interface's, specify the sub
interface as show by `ifconfig` or `ip addr list` (see global secondary 
addresses)

For IPv6, the script will take the numerically first address assigned
to the interface. If there is no IPv6 address other than a link-scope
address (i.e. an fe80:: address), then it will use the link-scope
address - however that's probably not what's really desired.

The script defaults to IPv6 addresses because that's what the original issue
it was written for was solved to address and it's long past time the
Internet has a v6-first attitude. It is not necessary to use the `--v6`
flag, but it's included for pretty completeness.

## Example Usage
To 
/usr/local/bin/ddns-update-rfc2136 enp1s0 foo.example.com example.com 192.0.2.2

## Usage
```
usage: ddns-update-rfc2136 [-h] [--v4] [--v6] [--addr4 ADDR4] [--addr6 ADDR6] [--ttl TTL] [--keyfile KEYFILE] [--debug]
                           interface record zone server

Update dynamic DNS records using RFC2136

positional arguments:
  interface          interface to obtain IP from (for IPv6, takes the numerically first global address on the interface)
  record             DNS record to update
  zone               Zone name to update (e.g. example.com)
  server             Server to update (IP or FQDN)

optional arguments:
  -h, --help         show this help message and exit
  --v4               Update IPv4 A record
  --v6               Update IPv6 AAAA record (default)
  --addr4 ADDR4      Update A record with provided IP rather than detected IP (causes 'interface' to be ignored)
  --addr6 ADDR6      Update AAAA record with provided IP rather than detected IP (causes 'interface' to be ignored)
  --ttl TTL          TTL to assign to record (default 300)
  --keyfile KEYFILE  Alternate location for key config file (default /etc/ddns-RECORD.key where RECORD is the record name provided
                     as the argument)
  --debug            Enable debug logging

```