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