]> git.ipfire.org Git - thirdparty/pdns.git/blob - docs/modes-of-operation.rst
Merge pull request #10874 from rgacogne/ddist-fix-healthcheck-exception
[thirdparty/pdns.git] / docs / modes-of-operation.rst
1 DNS Modes of Operation
2 ======================
3
4 PowerDNS offers full master and slave semantics for replicating domain
5 information. Furthermore, PowerDNS can benefit from native database
6 replication.
7
8 .. _native-operation:
9
10 Native replication
11 ------------------
12
13 Native replication is the default, unless other operation is
14 specifically configured. Native replication basically means that
15 PowerDNS will not send out DNS update notifications, nor will it react
16 to them. PowerDNS assumes that the backend is taking care of
17 replication unaided.
18
19 MySQL replication has proven to be very robust and well suited, even
20 over transatlantic connections between badly peering ISPs.
21
22 To use native replication, configure your backend storage to do the
23 replication and do not configure PowerDNS to do so.
24
25 Typically, a database slave will be configured as read-only as
26 uni-directional database replication is usually sufficient. A PowerDNS
27 server only requires database write access if it is participating as a
28 master or slave in zone transfers, or has a frontend attached for
29 managing records etc.
30
31 .. _master-operation:
32 .. _primary-operation:
33
34 Primary operation
35 -----------------
36
37 When operating as a master, PowerDNS sends out notifications of changes
38 to slaves, which react to these notifications by querying PowerDNS to
39 see if the zone changed, and transferring its contents if it has.
40 Notifications are a way to promptly propagate zone changes to slaves, as
41 described in :rfc:`1996`. Since
42 version 4.0.0, the NOTIFY messages have a TSIG record added (transaction
43 signature) if zone has been configured to use TSIG and feature has been
44 enabled.
45
46 .. warning::
47 Master support is OFF by default, turn it on by adding
48 :ref:`setting-master` to the configuration.
49
50 .. warning::
51 If you have DNSSEC-signed zones and non-PowerDNS slaves,
52 please check your :ref:`metadata-soa-edit`
53 settings.
54
55 .. warning::
56 Notifications are only sent for domains with type MASTER in
57 your backend unless :ref:`setting-slave-renotify` is enabled.
58
59 Left open by :rfc:`1996` is who is to be notified - which is harder to
60 figure out than it sounds. All slaves for this domain must receive a
61 notification but the nameserver only knows the names of the slaves - not
62 the IP addresses, which is where the problem lies. The nameserver itself
63 might be authoritative for the name of its secondary, but not have the
64 data available.
65
66 To resolve this issue, PowerDNS tries multiple tactics to figure out the
67 IP addresses of the slaves, and notifies everybody. In contrived
68 configurations this may lead to duplicate notifications being sent out,
69 which shouldn't hurt.
70
71 Some backends may be able to detect zone changes, others may chose to
72 let the operator indicate which zones have changed and which haven't.
73 Consult the documentation for your backend to see how it processes
74 changes in zones.
75
76 To help deal with slaves that may have missed notifications, or have
77 failed to respond to them, several override commands are available via
78 the :ref:`pdns_control <running-pdnscontrol>` tool:
79
80 - ``pdns_control notify <domain>`` This instructs PowerDNS to notify
81 all IP addresses it considers to be slaves of this domain.
82
83 - ``pdns_control notify-host <domain> <ip-address>`` This is truly an
84 override and sends a notification to an arbitrary IP address. Can be
85 used in :ref:`setting-also-notify` situations or
86 when PowerDNS has trouble figuring out who to notify - which may
87 happen in contrived configurations.
88
89 .. _slave-operation:
90 .. _secondary-operation:
91
92 Secondary operation
93 -------------------
94
95 On launch, PowerDNS requests from all backends a list of domains which
96 have not been checked recently for changes. This should happen every
97 '**refresh**' seconds, as specified in the SOA record. All domains that
98 are unfresh are then checked for changes over at their master. If the
99 :ref:`types-SOA` serial number there is higher, the domain is
100 retrieved and inserted into the database. In any case, after the check
101 the domain is declared 'fresh', and will only be checked again after
102 '**refresh**' seconds have passed.
103
104 When the freshness of a domain cannot be checked, e.g. because the
105 master is offline, PowerDNS will retry the domain after
106 :ref:`setting-xfr-cycle-interval` seconds.
107 Every time the domain fails it's freshness check, PowerDNS will hold
108 back on checking the domain for
109 ``amount of failures * xfr-cycle-interval`` seconds, with a maximum of
110 :ref:`setting-soa-retry-default` seconds
111 between checks. With default settings, this means that PowerDNS will
112 back off for 1, then 2, then 3 etc. minutes, to a maximum of 60 minutes
113 between checks. The same hold back algorithm is also applied if the zone
114 transfer fails due to problems on the master, i.e. if zone transfer is
115 not allowed.
116
117 Receiving a NOTIFY immediately clears the back off period for the
118 respective domain to allow immediately freshness checks for this domain.
119
120 .. warning::
121 Slave support is OFF by default, turn it on by adding
122 :ref:`setting-slave` to the configuration.
123
124 .. note::
125 When running PowerDNS via the provided systemd service file,
126 `ProtectSystem <http://www.freedesktop.org/software/systemd/man/systemd.exec.html#ProtectSystem=>`_
127 is set to ``full``, this means PowerDNS is unable to write to e.g.
128 ``/etc`` and ``/home``, possibly being unable to write AXFR's zones.
129
130 PowerDNS also reacts to notifies by immediately checking if the zone has
131 updated and if so, retransfering it.
132
133 All backends which implement this feature must make sure that they can
134 handle transactions so as to not leave the zone in a half updated state.
135 MySQL configured with either BerkeleyDB or InnoDB meets this
136 requirement, as do PostgreSQL. The BIND backend implements
137 transaction semantics by renaming files if and only if they have been
138 retrieved completely and parsed correctly.
139
140 Slave operation can also be programmed using several
141 :ref:`running-pdnscontrol` commands. The ``retrieve``
142 command is especially useful as it triggers an immediate retrieval of
143 the zone from the configured master.
144
145 Since 4.5.0, zone transfers are added to a queue and processed according to priority
146 and order of addition. Order levels are (from high to low): pdns control,
147 api, notify, serial changed during refresh and signatures changed during
148 refresh. High priority zone transfers are always processed first, in a
149 first in first out order.
150
151 PowerDNS supports multiple masters. For the BIND backend, the native
152 BIND configuration language suffices to specify multiple masters, for
153 SQL based backends, list all master servers separated by commas in the
154 'master' field of the domains table.
155
156 Since version 4.0.0, PowerDNS requires that masters sign their
157 notifications. During transition and interoperation with other
158 nameservers, you can use options :ref:`setting-allow-unsigned-notify` to permit
159 unsigned notifications. For 4.0.0 this is turned on by default, but it
160 might be turned off permanently in future releases.
161
162 Master/Slave Setup Requirements
163 -------------------------------
164
165 Generally to enable a Master/Slave setup you have to take care of
166 following properties.
167
168 * The :ref:`setting-master`/:ref:`setting-slave` state has to be enabled in the respective ``/etc/powerdns/pdns.conf`` config files.
169 * The nameservers have to be set up correctly as NS domain records i.e. defining a NS and A record for each slave.
170 * Master/Slave state has to be configured on a per domain basis in the ``domains`` table. Namely the ``type`` column has to be either ``MASTER`` or ``SLAVE`` respectively and the slave needs a comma separated list of master node IP addresses in the ``master`` column in the ``domains`` table. :doc:`more to this topic <backends/generic-sql>`.
171
172 IXFR: incremental zone transfers
173 --------------------------------
174
175 If the 'IXFR' zone metadata item is set to 1 for a zone, PowerDNS will
176 attempt to retrieve zone updates via IXFR.
177
178 .. warning::
179 If a slave zone changes from non-DNSSEC to DNSSEC, an IXFR
180 update will not set the PRESIGNED flag. In addition, a change in NSEC3
181 mode will also not be picked up.
182
183 In such cases, make sure to delete the zone contents to force a fresh
184 retrieval.
185
186 Finally, IXFR updates that "plug" Empty Non Terminals do not yet remove
187 ENT records. A 'pdnsutil rectify-zone' may be required.
188
189 PowerDNS itself is currently only able to retrieve updates via IXFR. It
190 can not serve IXFR updates.
191
192 .. _supermaster-operation:
193 .. _autoprimary-operation:
194
195 Autoprimary: automatic provisioning of secondaries
196 --------------------------------------------------
197
198 .. versionchanged:: 4.5.0
199 Before version 4.5.0, this feature was called 'supermaster'
200
201 PowerDNS can recognize so called 'autoprimaries'. An autoprimary is a host
202 which is primary for domains and for which we are to be a secondary. When a
203 primary (re)loads a domain, it sends out a notification to its secondaries.
204 Normally, such a notification is only accepted if PowerDNS already knows
205 that it is a secondary for a domain.
206
207 However, a notification from an autoprimary carries more persuasion. When
208 PowerDNS determines that a notification comes from a autoprimary and it
209 is bonafide, it can provision the domain automatically, and configure
210 itself as a secondary for that zone.
211
212 Before an autoprimary notification succeeds, the following conditions
213 must be met:
214
215 - :ref:`setting-autosecondary` support must be enabled
216 - The autoprimary must carry a SOA record for the notified domain
217 - The autoprimary IP must be present in the ``supermasters`` table in the database on the secondary, along with any name that is in the NS set.
218 - The set of NS records for the domain, as retrieved by the secondary from the autoprimary, must include the name that goes with the IP address in the ``supermasters`` table
219 - If your primary sends signed NOTIFY it will mark that TSIG key as the TSIG key used for retrieval as well
220 - If you turn off :ref:`setting-allow-unsigned-autoprimary`, then your autoprimaries are required to sign their notifications.
221
222 .. warning::
223 If you use another PowerDNS server as primary and have
224 DNSSEC enabled on that server please don't forget to rectify the domains
225 after every change. If you don't do this there is no SOA record
226 available and one requirement will fail.
227
228 So, to benefit from this feature, a backend needs to know about the IP
229 address of the autoprimary, and how PowerDNS will be listed in the set
230 of NS records remotely, and the 'account' name of your autoprimary.
231 There is no need to fill the account name out but it does help keep
232 track of where a domain comes from.
233 Additionally, if a secondary selects multiple autoprimaries for a zone based on the name of the primary, it also checks that the ``account`` field is the same for all.
234 Adding a autoprimary can be done either directly in the database,
235 or by using the 'pdnsutil add-supermaster' command.
236
237 .. note::
238 Removal of zones provisioned using the autoprimary must be
239 done on the secondaries themselves, as there is no way to signal this removal
240 from the primary to the secondary.
241
242 .. _modes-of-operation-axfrfilter:
243
244 Modifying a slave zone using a script
245 -------------------------------------
246
247 The PowerDNS Authoritative Server can invoke a Lua script on an incoming
248 AXFR zone transfer. The user-defined function ``axfrfilter`` within your
249 script is invoked for each resource record read during the transfer, and
250 the outcome of the function defines what PowerDNS does with the records.
251
252 What you can accomplish using a Lua script: - Ensure consistent values
253 on SOA - Change incoming SOA serial number to a YYYYMMDDnn format -
254 Ensure consistent NS RRset - Timestamp the zone transfer with a TXT
255 record
256
257 This script can be enabled like this::
258
259 pdnsutil set-meta example.com LUA-AXFR-SCRIPT /path/to/lua/script.lua
260
261 .. warning::
262 The Lua script must both exist and be syntactically
263 correct; if not, the zone transfer is not performed.
264
265 Your Lua functions have access to the query codes through a pre-defined
266 Lua table called ``pdns``. For example if you want to check for a CNAME
267 record you can either compare ``qtype`` to the numeric constant 5 or the
268 value ``pdns.CNAME`` -- they are equivalent.
269
270 If your function decides to handle a resource record it must return a
271 result code of 0 together with a Lua table containing one or more
272 replacement records to be stored in the back-end database (if the table
273 is empty, no record is added). If you want your record(s) to be appended
274 after the matching record, return 1 and table of record(s). If, on the
275 other hand, your function decides not to modify a record, it must return
276 -1 and an empty table indicating that PowerDNS should handle the
277 incoming record as normal.
278
279 Consider the following simple example:
280
281 .. code-block:: lua
282
283 function axfrfilter(remoteip, zone, record)
284
285 -- Replace each HINFO records with this TXT
286 if record:qtype() == pdns.HINFO then
287 resp = {}
288 resp[1] = {
289 qname = record:qname():toString(),
290 qtype = pdns.TXT,
291 ttl = 99,
292 content = "Hello Ahu!"
293 }
294 return 0, resp
295 end
296
297 -- Grab each _tstamp TXT record and add a time stamp
298 if record:qtype() == pdns.TXT and string.starts(record:qname():toString(), "_tstamp.") then
299 resp = {}
300 resp[1] = {
301 qname = record:qname():toString(),
302 qtype = record:qtype(),
303 ttl = record:ttl(),
304 content = os.date("Ver %Y%m%d-%H:%M")
305 }
306 return 0, resp
307 end
308
309 -- Append A records with this TXT
310 if record:qtype() == pdns.A then
311 resp = {}
312 resp[1] = {
313 qname = record:qname():toString(),
314 qtype = pdns.TXT,
315 ttl = 99,
316 content = "Hello Ahu, again!"
317 }
318 return 1, resp
319 end
320
321 resp = {}
322 return -1, resp
323 end
324
325 function string.starts(s, start)
326 return s.sub(s, 1, s.len(start)) == start
327 end
328
329 Upon an incoming AXFR, PowerDNS calls our ``axfrfilter`` function for
330 each record. All HINFO records are replaced by a TXT record with a TTL
331 of 99 seconds and the specified string. TXT Records with names starting
332 with ``_tstamp.`` get their value (rdata) set to the current time stamp.
333 A records are appended with a TXT record. All other records are
334 unhandled.