summaryrefslogtreecommitdiff
path: root/docs/configuration/service/dynamic-dns.md
blob: a828a7c3abc7899b296836d81a3382836d547ae2 (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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
---
myst:
  html_meta:
    description: |
      Dynamic DNS is a VyOS service that keeps a DNS record updated
      with the current IP address of an interface. It supports direct
      DNS updates via RFC 2136 and hosted updates via third-party
      dynamic DNS providers such as Cloudflare, DuckDNS, deSEC, and
      DynDNS.
    keywords: dynamic dns, ddns, rfc 2136, nsupdate, cloudflare, dyndns
---

(dynamic-dns)=

# Dynamic DNS

The dynamic DNS service updates the DNS record (an A record for IPv4 or
an AAAA record for IPv6) that maps your hostname to your device whenever
your IP address changes, so you can always reach your device by
hostname.

Two update mechanisms are available:

- Direct DNS update ([RFC 2136](https://datatracker.ietf.org/doc/html/rfc2136)):
  Updates the record by sending an RFC 2136 DNS UPDATE message to an
  authoritative DNS server. Use this option when you run your own DNS
  server.
- Hosted DNS update: Updates the record by sending an HTTP(S) update
  request to a third-party dynamic DNS provider (such as Cloudflare,
  DuckDNS, deSEC, or DynDNS). Use this option when relying on an
  external provider.

## Configuration

### Common commands

The following commands apply to both direct and hosted DNS updates.

```{cfgcmd} set service dns dynamic name \<service-name\> address interface \<interface\>

**Configure the interface whose IP address the dynamic DNS record
points to.**
```

```{note}
Mutually exclusive with `address web` within the same dynamic DNS
`<service-name>` configuration.
```

Example:

```none
set service dns dynamic name VyOS-DNS address interface eth0
```

```{cfgcmd} set service dns dynamic name \<service-name\> description \<text\>

**Configure a description for the dynamic DNS service configuration.**

Limited to 255 characters.
```

Example:

```none
set service dns dynamic name VyOS-DNS description 'RFC 2136 dynamic DNS service'
```

```{cfgcmd} set service dns dynamic name \<service-name\> host-name \<hostname\>

**Configure a hostname whose DNS record is kept updated with the current
IP address.**

Accepts a standard hostname, `@` for the zone apex, or `*` for a
wildcard record. Repeat the command to add several hostnames to the
same dynamic DNS `<service-name>` configuration.
```

Example:

```none
set service dns dynamic name VyOS-DNS host-name host.example.com
```

```{cfgcmd} set service dns dynamic name \<service-name\> protocol \<protocol\>

**Configure the protocol used to send updates.**

Use `nsupdate` for direct DNS updates, or a provider-specific protocol
such as `cloudflare`, `dyndns2`, or `duckdns` for hosted DNS updates.
Use CLI tab-completion to list the available protocols.
```

Example:

```none
set service dns dynamic name VyOS-DNS protocol nsupdate
```

```{cfgcmd} set service dns dynamic name \<service-name\> server \<server\>

**Configure the IP address or {abbr}`FQDN (Fully Qualified Domain Name)`
of the authoritative DNS server (direct DNS updates), or the provider's
endpoint (hosted DNS updates).**

Required for `nsupdate` and optional for HTTP(S)-based protocols.
```

Example:

```none
set service dns dynamic name VyOS-DNS server ns1.example.com
```

```{cfgcmd} set service dns dynamic name \<service-name\> zone \<zone\>

**Configure the DNS zone that contains the configured hostnames.**

The value must be an FQDN. Required for protocols `cloudflare`,
`digitalocean`, `godaddy`, `hetzner`, `gandi`, `nfsn`, and `nsupdate`.
Also accepted for `dnsexit2` and `zoneedit1`. Not supported for any
other protocol.
```

Example:

```none
set service dns dynamic name VyOS-DNS zone example.com
```

```{cfgcmd} set service dns dynamic name \<service-name\> ttl \<0-2147483647\>

**Configure the {abbr}`TTL (Time-To-Live)`, in seconds, of the updated
DNS records.**

The TTL sets how long DNS resolvers may cache the record before it must
be re-fetched. Supported only for protocols `cloudflare`, `dnsexit2`,
`gandi`, `godaddy`, `hetzner`, `nfsn`, and `nsupdate`. When unset, no
TTL is included in the update.
```

Example:

```none
set service dns dynamic name VyOS-DNS ttl 300
```

```{cfgcmd} set service dns dynamic name \<service-name\> ip-version \<ipv4 | ipv6 | both\>

**Configure which DNS record types are updated:**

- `ipv4`: Updates the A record only.
- `ipv6`: Updates the AAAA record only.
- `both`: Updates both the A and AAAA records.

The default is `ipv4`.

`both` is supported only for protocols `cloudflare`, `digitalocean`,
`dnsexit2`, `duckdns`, `dyndns2`, `easydns`, `freedns`, `hetzner`,
`infomaniak`, and `njalla`.
```

Example:

```none
set service dns dynamic name VyOS-DNS ip-version ipv6
```

```{cfgcmd} set service dns dynamic interval \<60-3600\>

**Configure the interval, in seconds, between updates of the configured
DNS records.**

The default is 300.
```

Example:

```none
set service dns dynamic interval 300
```

### Running behind NAT

By default, the IP address configured under `address interface` is what
gets registered. When VyOS is behind NAT, this is the internal address
that cannot be reached from the public Internet. Configure `address web`
instead so the DNS record points to the public IP address.

```{cfgcmd} set service dns dynamic name \<service-name\> address web url \<url\>

**Configure an HTTP(S) URL from which dynamic DNS obtains the IP address
for the DNS record.**
```

```{note}
Mutually exclusive with `address interface` within the same dynamic DNS
`<service-name>` configuration.
```

Example:

```none
set service dns dynamic name VyOS-DNS address web url https://ipv4.icanhazip.com
```

```{cfgcmd} set service dns dynamic name \<service-name\> address web skip \<pattern\>

**Configure dynamic DNS to ignore URL response text before the
specified pattern when extracting the public IP address.**
```

```{note}
Requires `address web url` to be set within the same dynamic DNS
`<service-name>` configuration.
```

Example:

```none
set service dns dynamic name VyOS-DNS address web skip 'Current IP Address:'
```

### Direct DNS update (RFC 2136)

```{cfgcmd} set service dns dynamic name \<service-name\> key \<filename\>

**Configure the file containing the {abbr}`TSIG (Transaction Signature)`
key used to authenticate direct DNS update messages.**

The file must be within the `/config/auth` directory. Required when
`protocol` is `nsupdate`; other protocols use `password` instead.
```

Example:

```none
set service dns dynamic name VyOS-DNS key /config/auth/my.key
```

### Hosted (provider-based) DNS update

```{cfgcmd} set service dns dynamic name \<service-name\> username \<username\>

**Configure the username presented in HTTP(S) update requests to the
dynamic DNS provider.**

Required for most protocols. Not required for `1984`, `cloudflare`,
`cloudns`, `digitalocean`, `dnsexit2`, `duckdns`, `freemyip`, `hetzner`,
`keysystems`, `njalla`, `nsupdate`, and `regfishde`.
```

Example:

```none
set service dns dynamic name dedyn username myusername
```

```{cfgcmd} set service dns dynamic name \<service-name\> password \<password\>

**Configure the password, or provider API token, presented in HTTP(S)
update requests to the dynamic DNS provider.**

Required for every protocol except `nsupdate`, which uses `key` instead.
```

Example:

```none
set service dns dynamic name dedyn password mypassword
```

## Examples

### Direct DNS update ([RFC 2136](https://datatracker.ietf.org/doc/html/rfc2136))

The following example registers the DNS record `example.vyos.io` on the
DNS server `ns1.vyos.io`, keeps it updated with the current IP address
of `eth0`, authenticates updates with the TSIG key at
`/config/auth/my.key`, and sets a TTL of 300 seconds.

```none
set service dns dynamic name VyOS-DNS address interface 'eth0'
set service dns dynamic name VyOS-DNS description 'RFC 2136 dynamic DNS service'
set service dns dynamic name VyOS-DNS key '/config/auth/my.key'
set service dns dynamic name VyOS-DNS server 'ns1.vyos.io'
set service dns dynamic name VyOS-DNS zone 'vyos.io'
set service dns dynamic name VyOS-DNS host-name 'example.vyos.io'
set service dns dynamic name VyOS-DNS protocol 'nsupdate'
set service dns dynamic name VyOS-DNS ttl '300'
```

Resulting configuration:

```none
vyos@vyos# show service dns dynamic
 name VyOS-DNS {
     address {
         interface eth0
     }
     description "RFC 2136 dynamic DNS service"
     host-name example.vyos.io
     key /config/auth/my.key
     protocol nsupdate
     server ns1.vyos.io
     ttl 300
     zone vyos.io
 }
```

```{note}
You can define multiple dynamic DNS `<service-name>` configurations,
each registering its own set of DNS records.
```

### Hosted (provider-based) DNS update

The following example registers the DNS record `myhostname.dedyn.io`
with deSEC via the `dyndns2` protocol, keeps it updated with the current
IP address of `eth0`, and authenticates updates with the configured
username and password.

```none
set service dns dynamic name dedyn description 'deSEC dynamic DNS service'
set service dns dynamic name dedyn username 'myusername'
set service dns dynamic name dedyn password 'mypassword'
set service dns dynamic name dedyn host-name 'myhostname.dedyn.io'
set service dns dynamic name dedyn protocol 'dyndns2'
set service dns dynamic name dedyn server 'update.dedyn.io'
set service dns dynamic name dedyn address interface 'eth0'
```

```{note}
You can define multiple dynamic DNS `<service-name>` configurations,
each registering its own set of DNS records.
```

The following example is the same as above, but restricted to IPv6: the
AAAA record for `myhostname.dedyn.io` is updated with the current IPv6
address of `eth0`, using deSEC's IPv6 update endpoint
`update6.dedyn.io`.

```none
set service dns dynamic name dedyn description 'deSEC IPv6 dynamic DNS service'
set service dns dynamic name dedyn username 'myusername'
set service dns dynamic name dedyn password 'mypassword'
set service dns dynamic name dedyn host-name 'myhostname.dedyn.io'
set service dns dynamic name dedyn protocol 'dyndns2'
set service dns dynamic name dedyn ip-version 'ipv6'
set service dns dynamic name dedyn server 'update6.dedyn.io'
set service dns dynamic name dedyn address interface 'eth0'
```