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