]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnsdistdist/docs/reference/config.rst
dnsdist: Add 'reloadAllCertificates()'
[thirdparty/pdns.git] / pdns / dnsdistdist / docs / reference / config.rst
1 .. highlight:: lua
2
3 Configuration Reference
4 =======================
5
6 This page lists all configuration options for dnsdist.
7
8 .. note::
9
10 When an IPv6 IP:PORT combination is needed, the bracketed syntax from :rfc:`RFC 3986 <3986#section-3.2.2>` should be used.
11 e.g. "[2001:DB8:14::C0FF:FEE]:5300".
12
13 Functions and Types
14 -------------------
15
16 Within dnsdist several core object types exist:
17
18 * :class:`Server`: generated with :func:`newServer`, represents a downstream server
19 * :class:`ComboAddress`: represents an IP address and port
20 * :class:`DNSName`: represents a domain name
21 * :class:`NetmaskGroup`: represents a group of netmasks
22 * :class:`QPSLimiter`: implements a QPS-based filter
23 * :class:`SuffixMatchNode`: represents a group of domain suffixes for rapid testing of membership
24 * :class:`DNSHeader`: represents the header of a DNS packet, see :ref:`DNSHeader`
25 * :class:`ClientState`: sometimes also called Bind or Frontend, represents the addresses and ports dnsdist is listening on
26
27 The existence of most of these objects can mostly be ignored, unless you plan to write your own hooks and policies, but it helps to understand an expressions like:
28
29 .. code-block:: lua
30
31 getServer(0).order=12 -- set order of server 0 to 12
32 getServer(0):addPool("abuse") -- add this server to the abuse pool
33
34 The ``.`` means ``order`` is a data member, while the ``:`` means ``addPool`` is a member function.
35
36 Global configuration
37 --------------------
38
39 .. function:: includeDirectory(path)
40
41 Include configuration files from ``path``.
42
43 :param str path: The directory to load configuration files from. Each file must end in ``.conf``.
44
45 .. function:: reloadAllCertificates()
46
47 .. versionadded:: 1.4.0
48
49 Reload all DNSCrypt and TLS certificates, along with their associated keys.
50
51 Listen Sockets
52 ~~~~~~~~~~~~~~
53
54 .. function:: addLocal(address[, options])
55
56 .. versionadded:: 1.2.0
57
58 .. versionchanged:: 1.3.0
59 Added ``cpus`` to the options.
60
61 Add to the list of listen addresses.
62
63 :param str address: The IP Address with an optional port to listen on.
64 The default port is 53.
65 :param table options: A table with key: value pairs with listen options.
66
67 Options:
68
69 * ``doTCP=true``: bool - Also bind on TCP on ``address``.
70 * ``reusePort=false``: bool - Set the ``SO_REUSEPORT`` socket option.
71 * ``tcpFastOpenSize=0``: int - Set the TCP Fast Open queue size, enabling TCP Fast Open when available and the value is larger than 0.
72 * ``interface=""``: str - Set the network interface to use.
73 * ``cpus={}``: table - Set the CPU affinity for this listener thread, asking the scheduler to run it on a single CPU id, or a set of CPU ids. This parameter is only available if the OS provides the pthread_setaffinity_np() function.
74
75 .. code-block:: lua
76
77 addLocal('0.0.0.0:5300', { doTCP=true, reusePort=true })
78
79 This will bind to both UDP and TCP on port 5300 with SO_REUSEPORT enabled.
80
81 .. function:: addLocal(address[[[,do_tcp], so_reuseport], tcp_fast_open_qsize])
82
83 .. deprecated:: 1.2.0
84
85 Add to the list of addresses listened on.
86
87 :param str address: The IP Address with an optional port to listen on.
88 The default port is 53.
89 :param bool do_tcp: Also bind a TCP port on ``address``, defaults to true.
90 :param bool so_reuseport: Use ``SO_REUSEPORT`` if it is available, defaults to false
91 :param int tcp_fast_open_qsize: The size of the TCP Fast Open queue. Set to a number
92 higher than 0 to enable TCP Fast Open when available.
93 Default is 0.
94
95 .. function:: addTLSLocal(address, certFile(s), keyFile(s) [, options])
96
97 .. versionadded:: 1.3.0
98 .. versionchanged:: 1.3.1
99 ``certFile(s)`` and ``keyFile(s)`` parameters accept a list of files.
100 ``sessionTickets`` option added.
101 .. versionchanged:: 1.3.3
102 ``numberOfStoredSessions`` option added.
103
104 Listen on the specified address and TCP port for incoming DNS over TLS connections, presenting the specified X.509 certificate.
105
106 :param str address: The IP Address with an optional port to listen on.
107 The default port is 853.
108 :param str certFile(s): The path to a X.509 certificate file in PEM format, or a list of paths to such files.
109 :param str keyFile(s): The path to the private key file corresponding to the certificate, or a list of paths to such files, whose order should match the certFile(s) ones.
110 :param table options: A table with key: value pairs with listen options.
111
112 Options:
113
114 * ``reusePort=false``: bool - Set the ``SO_REUSEPORT`` socket option.
115 * ``tcpFastOpenSize=0``: int - Set the TCP Fast Open queue size, enabling TCP Fast Open when available and the value is larger than 0.
116 * ``interface=""``: str - Set the network interface to use.
117 * ``cpus={}``: table - Set the CPU affinity for this listener thread, asking the scheduler to run it on a single CPU id, or a set of CPU ids. This parameter is only available if the OS provides the pthread_setaffinity_np() function.
118 * ``provider``: str - The TLS library to use between GnuTLS and OpenSSL, if they were available and enabled at compilation time.
119 * ``ciphers``: str - The TLS ciphers to use. The exact format depends on the provider used.
120 * ``numberOfTicketsKeys``: int - The maximum number of tickets keys to keep in memory at the same time, if the provider supports it (GnuTLS doesn't, OpenSSL does). Only one key is marked as active and used to encrypt new tickets while the remaining ones can still be used to decrypt existing tickets after a rotation. Default to 5.
121 * ``ticketKeyFile``: str - The path to a file from where TLS tickets keys should be loaded, to support RFC 5077. These keys should be rotated often and never written to persistent storage to preserve forward secrecy. The default is to generate a random key. The OpenSSL provider supports several tickets keys to be able to decrypt existing sessions after the rotation, while the GnuTLS provider only supports one key.
122 * ``ticketsKeysRotationDelay``: int - Set the delay before the TLS tickets key is rotated, in seconds. Default is 43200 (12h).
123 * ``sessionTickets``: bool - Whether session resumption via session tickets is enabled. Default is true, meaning tickets are enabled.
124 * ``numberOfStoredSessions``: int - The maximum number of sessions kept in memory at the same time. At this time this is only supported by the OpenSSL provider, as stored sessions are not supported with the GnuTLS one. Default is 20480. Setting this value to 0 disables stored session entirely.
125
126 .. function:: setLocal(address[, options])
127
128 .. versionadded:: 1.2.0
129
130 Remove the list of listen addresses and add a new one.
131
132 :param str address: The IP Address with an optional port to listen on.
133 The default port is 53.
134 :param table options: A table with key: value pairs with listen options.
135
136 The options that can be set are the same as :func:`addLocal`.
137
138 .. function:: setLocal(address[[[,do_tcp], so_reuseport], tcp_fast_open_qsize])
139
140 .. deprecated:: 1.2.0
141
142 Remove the list of listen addresses and add a new one.
143
144 :param str address: The IP Address with an optional port to listen on.
145 The default port is 53.
146 :param bool do_tcp: Also bind a TCP port on ``address``, defaults to true.
147 :param bool so_reuseport: Use ``SO_REUSEPORT`` if it is available, defaults to false
148 :param int tcp_fast_open_qsize: The size of the TCP Fast Open queue. Set to a number
149 higher than 0 to enable TCP Fast Open when available.
150 Default is 0.
151
152 Control Socket, Console and Webserver
153 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
154
155 .. function:: addConsoleACL(netmask)
156
157 .. versionadded:: 1.3.0
158
159 Add a netmask to the existing console ACL, allowing remote clients to connect to the console. Please make sure that encryption
160 has been enabled with :func:`setKey` before doing so. The default is to only allow 127.0.0.1/8 and ::1/128.
161
162 :param str netmask: A CIDR netmask, e.g. ``"192.0.2.0/24"``. Without a subnetmask, only the specific address is allowed.
163
164 .. function:: controlSocket(address)
165
166 Bind to ``addr`` and listen for a connection for the console. Since 1.3.0 only connections from local users are allowed
167 by default, :func:`addConsoleACL` and :func:`setConsoleACL` can be used to enable remote connections. Please make sure
168 that encryption has been enabled with :func:`setKey` before doing so. Enabling encryption is also strongly advised for
169 local connections, since not enabling it allows any local user to connect to the console.
170
171 :param str address: An IP address with optional port. By default, the port is 5199.
172
173 .. function:: inClientStartup()
174
175 Returns true while the console client is parsing the configuration.
176
177 .. function:: makeKey()
178
179 Generate and print an encryption key.
180
181 .. function:: setConsoleConnectionsLogging(enabled)
182
183 .. versionadded:: 1.2.0
184
185 Whether to log the opening and closing of console connections.
186
187 :param bool enabled: Default to true.
188
189 .. function:: setKey(key)
190
191 Use ``key`` as shared secret between the client and the server
192
193 :param str key: An encoded key, as generated by :func:`makeKey`
194
195 .. function:: setConsoleACL(netmasks)
196
197 .. versionadded:: 1.3.0
198
199 Remove the existing console ACL and add the netmasks from the table, allowing remote clients to connect to the console. Please make sure that encryption
200 has been enabled with :func:`setKey` before doing so.
201
202 :param {str} netmasks: A table of CIDR netmask, e.g. ``{"192.0.2.0/24", "2001:DB8:14::/56"}``. Without a subnetmask, only the specific address is allowed.
203
204 .. function:: showConsoleACL()
205
206 Print a list of all netmasks allowed to connect to the console.
207
208 .. function:: testCrypto()
209
210 Test the crypto code, will report errors when something is not ok.
211
212 .. function:: setConsoleOutputMaxMsgSize(size)
213
214 .. versionadded:: 1.3.3
215
216 Set the maximum size in bytes of a single console message, default set to 10 MB.
217
218 :param int size: The new maximum size.
219
220 Webserver configuration
221 ~~~~~~~~~~~~~~~~~~~~~~~
222
223 .. function:: webserver(listen_address, password[, apikey[, custom_headers]])
224
225 Launch the :doc:`../guides/webserver` with statistics and the API.
226
227 :param str listen_address: The IP address and Port to listen on
228 :param str password: The password required to access the webserver
229 :param str apikey: The key required to access the API
230 :param {[str]=str,...} custom_headers: Allows setting custom headers and removing the defaults
231
232 .. function:: setAPIWritable(allow [,dir])
233
234 Allow modifications via the API.
235 Optionally saving these changes to disk.
236 Modifications done via the API will not be written to the configuration by default and will not persist after a reload
237
238 :param bool allow: Set to true to allow modification through the API
239 :param str dir: A valid directory where the configuration files will be written by the API.
240
241 .. function:: setWebserverConfig(options)
242
243 .. versionadded:: 1.3.3
244
245 Setup webserver configuration. See :func:`webserver`.
246
247 :param table options: A table with key: value pairs with webserver options.
248
249 Options:
250
251 * ``password=newPassword``: string - Changes the API password
252 * ``apikey=newKey``: string - Changes the API Key (set to an empty string do disable it)
253 * ``custom_headers={[str]=str,...}``: map of string - Allows setting custom headers and removing the defaults.
254
255 Access Control Lists
256 ~~~~~~~~~~~~~~~~~~~~
257
258 .. function:: addACL(netmask)
259
260 Add a netmask to the existing ACL controlling which clients can send UDP and TCP queries. See :ref:`ACL` for more information.
261
262 :param str netmask: A CIDR netmask, e.g. ``"192.0.2.0/24"``. Without a subnetmask, only the specific address is allowed.
263
264 .. function:: setACL(netmasks)
265
266 Remove the existing ACL and add the netmasks from the table of those allowed to send UDP and TCP queries. See :ref:`ACL` for more information.
267
268 :param {str} netmasks: A table of CIDR netmask, e.g. ``{"192.0.2.0/24", "2001:DB8:14::/56"}``. Without a subnetmask, only the specific address is allowed.
269
270 .. function:: showACL()
271
272 Print a list of all netmasks allowed to send queries over UDP and TCP. See :ref:`ACL` for more information.
273
274 EDNS Client Subnet
275 ~~~~~~~~~~~~~~~~~~
276
277 .. function:: setECSSourcePrefixV4(prefix)
278
279 When ``useClientSubnet`` in :func:`newServer` is set and dnsdist adds an EDNS Client Subnet Client option to the query, truncate the requestors IPv4 address to ``prefix`` bits
280
281 :param int prefix: The prefix length
282
283 .. function:: setECSSourcePrefixV6(prefix)
284
285 When ``useClientSubnet`` in :func:`newServer` is set and dnsdist adds an EDNS Client Subnet Client option to the query, truncate the requestor's IPv6 address to bits
286
287 :param int prefix: The prefix length
288
289 Ringbuffers
290 ~~~~~~~~~~~
291
292 .. function:: setRingBuffersLockRetries(num)
293
294 .. versionadded:: 1.3.0
295
296 Set the number of shards to attempt to lock without blocking before giving up and simply blocking while waiting for the next shard to be available
297
298 :param int num: The maximum number of attempts. Defaults to 5 if there is more than one shard, 0 otherwise.
299
300 .. function:: setRingBuffersSize(num [, numberOfShards])
301
302 .. versionchanged:: 1.3.0
303 ``numberOfShards`` optional parameter added.
304
305 Set the capacity of the ringbuffers used for live traffic inspection to ``num``, and the number of shards to ``numberOfShards`` if specified.
306
307 :param int num: The maximum amount of queries to keep in the ringbuffer. Defaults to 10000
308 :param int numberOfShards: the number of shards to use to limit lock contention. Defaults to 1
309
310 Servers
311 -------
312
313 .. function:: newServer(server_string)
314 newServer(server_table)
315
316 .. versionchanged:: 1.3.0
317 Added ``checkClass``, ``sockets`` and ``checkFunction`` to server_table.
318
319 .. versionchanged:: 1.3.4
320 Added ``checkTimeout`` and ``rise`` to server_table.
321
322 Add a new backend server. Call this function with either a string::
323
324 newServer(
325 "IP:PORT" -- IP and PORT of the backend server
326 )
327
328 or a table::
329
330 newServer({
331 address="IP:PORT", -- IP and PORT of the backend server (mandatory)
332 id=STRING, -- Use a pre-defined UUID instead of a random one
333 qps=NUM, -- Limit the number of queries per second to NUM, when using the `firstAvailable` policy
334 order=NUM, -- The order of this server, used by the `leastOustanding` and `firstAvailable` policies
335 weight=NUM, -- The weight of this server, used by the `wrandom`, `whashed` and `chashed` policies, default: 1
336 -- Supported values are a minimum of 1, and a maximum of 2147483647.
337 pool=STRING|{STRING}, -- The pools this server belongs to (unset or empty string means default pool) as a string or table of strings
338 retries=NUM, -- The number of TCP connection attempts to the backend, for a given query
339 tcpConnectTimeout=NUM, -- The timeout (in seconds) of a TCP connection attempt
340 tcpSendTimeout=NUM, -- The timeout (in seconds) of a TCP write attempt
341 tcpRecvTimeout=NUM, -- The timeout (in seconds) of a TCP read attempt
342 tcpFastOpen=BOOL, -- Whether to enable TCP Fast Open
343 ipBindAddrNoPort=BOOL, -- Whether to enable IP_BIND_ADDRESS_NO_PORT if available, default: true
344 name=STRING, -- The name associated to this backend, for display purpose
345 checkClass=NUM, -- Use NUM as QCLASS in the health-check query, default: DNSClass.IN
346 checkName=STRING, -- Use STRING as QNAME in the health-check query, default: "a.root-servers.net."
347 checkType=STRING, -- Use STRING as QTYPE in the health-check query, default: "A"
348 checkFunction=FUNCTION,-- Use this function to dynamically set the QNAME, QTYPE and QCLASS to use in the health-check query (see :ref:`Healthcheck`)
349 checkTimeout=NUM, -- The timeout (in milliseconds) of a health-check query, default: 1000 (1s)
350 setCD=BOOL, -- Set the CD (Checking Disabled) flag in the health-check query, default: false
351 maxCheckFailures=NUM, -- Allow NUM check failures before declaring the backend down, default: 1
352 checkInterval=NUM -- The time in seconds between health checks
353 mustResolve=BOOL, -- Set to true when the health check MUST return a NOERROR RCODE and an answer
354 useClientSubnet=BOOL, -- Add the client's IP address in the EDNS Client Subnet option when forwarding the query to this backend
355 source=STRING, -- The source address or interface to use for queries to this backend, by default this is left to the kernel's address selection
356 -- The following formats are supported:
357 -- "address", e.g. "192.0.2.2"
358 -- "interface name", e.g. "eth0"
359 -- "address@interface", e.g. "192.0.2.2@eth0"
360 addXPF=NUM, -- Add the client's IP address and port to the query, along with the original destination address and port,
361 -- using the experimental XPF record from `draft-bellis-dnsop-xpf <https://datatracker.ietf.org/doc/draft-bellis-dnsop-xpf/>`_ and the specified option code. Default is disabled (0)
362 sockets=NUM, -- Number of sockets (and thus source ports) used toward the backend server, defaults to a single one
363 disableZeroScope=BOOL, -- Disable the EDNS Client Subnet 'zero scope' feature, which does a cache lookup for an answer valid for all subnets (ECS scope of 0) before adding ECS information to the query and doing the regular lookup
364 rise=NUM -- Require NUM consecutive successful checks before declaring the backend up, default: 1
365 })
366
367 :param str server_string: A simple IP:PORT string.
368 :param table server_table: A table with at least a 'name' key
369
370 .. function:: getServer(index) -> Server
371
372 Get a :class:`Server`
373
374 :param int index: The number of the server (as seen in :func:`showServers`).
375 :returns: The :class:`Server` object or nil
376
377 .. function:: getServers()
378
379 Returns a table with all defined servers.
380
381 .. function:: rmServer(index)
382 rmServer(server)
383
384 Remove a backend server.
385
386 :param int index: The number of the server (as seen in :func:`showServers`).
387 :param Server server: A :class:`Server` object as returned by e.g. :func:`getServer`.
388
389 Server Functions
390 ~~~~~~~~~~~~~~~~
391 A server object returned by :func:`getServer` can be manipulated with these functions.
392
393 .. class:: Server
394
395 This object represents a backend server. It has several methods.
396
397 .. method:: Server:addPool(pool)
398
399 Add this server to a pool.
400
401 :param str pool: The pool to add the server to
402
403 .. method:: Server:getName() -> string
404
405 Get the name of this server.
406
407 :returns: The name of the server, or an empty string if it does not have one
408
409 .. method:: Server:getNameWithAddr() -> string
410
411 Get the name plus IP address and port of the server
412
413 :returns: A string containing the server name if any plus the server address and port
414
415 .. method:: Server:getOutstanding() -> int
416
417 Get the number of outstanding queries for this server.
418
419 :returns: The number of outstanding queries
420
421 .. method:: Server:isUp() -> bool
422
423 Returns the up status of the server
424
425 :returns: true when the server is up, false otherwise
426
427 .. method:: Server:rmPool(pool)
428
429 Removes the server from the named pool
430
431 :param str pool: The pool to remove the server from
432
433 .. method:: Server:setAuto([status])
434
435 .. versionchanged:: 1.3.0
436 ``status`` optional parameter added.
437
438 Set the server in the default auto state.
439 This will enable health check queries that will set the server ``up`` and ``down`` appropriately.
440
441 :param bool status: Set the initial status of the server to ``up`` (true) or ``down`` (false) instead of using the last known status
442
443 .. method:: Server:setQPS(limit)
444
445 Limit the queries per second for this server.
446
447 :param int limit: The maximum number of queries per second
448
449 .. method:: Server:setDown()
450
451 Set the server in an ``DOWN`` state.
452 The server will not receive queries and the health checks are disabled
453
454 .. method:: Server:setUp()
455
456 Set the server in an ``UP`` state.
457 This server will still receive queries and health checks are disabled
458
459 Apart from the functions, a :class:`Server` object has these attributes:
460
461 .. attribute:: Server.name
462
463 The name of the server
464
465 .. attribute:: Server.upStatus
466
467 Whether or not this server is up or down
468
469 .. attribute:: Server.order
470
471 The order of the server
472
473 .. attribute:: Server.weight
474
475 The weight of the server
476
477 Pools
478 -----
479
480 :class:`Server`\ s can be part of any number of pools.
481 Pools are automatically created when a server is added to a pool (with :func:`newServer`), or can be manually created with :func:`addPool`.
482
483 .. function:: addPool(name) -> ServerPool
484
485 Returns a :class:`ServerPool`.
486
487 :param string name: The name of the pool to create
488
489 .. function:: getPool(name) -> ServerPool
490
491 Returns a :class:`ServerPool` or nil.
492
493 :param string name: The name of the pool
494
495 .. function:: getPoolServers(name) -> [ Server ]
496
497 Returns a list of :class:`Server`\ s or nil.
498
499 :param string name: The name of the pool
500
501 .. function:: showPools()
502
503 Display the name, associated cache, server policy and associated servers for every pool.
504
505 .. class:: ServerPool
506
507 This represents the pool where zero or more servers are part of.
508
509 .. method:: ServerPool:getCache() -> PacketCache
510
511 Returns the :class:`PacketCache` for this pool or nil.
512
513 .. method:: ServerPool:getECS()
514
515 .. versionadded:: 1.3.0
516
517 Whether dnsdist will add EDNS Client Subnet information to the query before looking up into the cache,
518 when all servers from this pool are down. For more information see :meth:`ServerPool:setECS`.
519
520 .. method:: ServerPool:setCache(cache)
521
522 Adds ``cache`` as the pool's cache.
523
524 :param PacketCache cache: The new cache to add to the pool
525
526 .. method:: ServerPool:unsetCache()
527
528 Removes the cache from this pool.
529
530 .. method:: ServerPool:setECS()
531
532 .. versionadded:: 1.3.0
533
534 Set to true if dnsdist should add EDNS Client Subnet information to the query before looking up into the cache,
535 when all servers from this pool are down. If at least one server is up, the preference of the
536 selected server is used, this parameter is only useful if all the backends in this pool are down
537 and have EDNS Client Subnet enabled, since the queries in the cache will have been inserted with
538 ECS information. Default is false.
539
540 PacketCache
541 ~~~~~~~~~~~
542
543 A Pool can have a packet cache to answer queries directly in stead of going to the backend.
544 See :doc:`../guides/cache` for a how to.
545
546 .. function:: newPacketCache(maxEntries[, maxTTL=86400[, minTTL=0[, temporaryFailureTTL=60[, staleTTL=60[, dontAge=false[, numberOfShards=1[, deferrableInsertLock=true[, maxNegativeTTL=3600[, parseECS=false [,options]]]]]]]]) -> PacketCache
547
548 .. versionchanged:: 1.3.0
549 ``numberOfShards`` and ``deferrableInsertLock`` parameters added.
550
551 .. versionchanged:: 1.3.1
552 ``maxNegativeTTL`` and ``parseECS`` parameters added.
553
554 .. versionchanged:: 1.3.4
555 ``options`` parameter added.
556
557 Creates a new :class:`PacketCache` with the settings specified.
558 Starting with 1.3.4, all parameters can be specified in the ``options`` table, overriding the value from the existing parameters if any.
559
560 :param int maxEntries: The maximum number of entries in this cache
561 :param int maxTTL: Cap the TTL for records to his number
562 :param int minTTL: Don't cache entries with a TTL lower than this
563 :param int temporaryFailureTTL: On a SERVFAIL or REFUSED from the backend, cache for this amount of seconds
564 :param int staleTTL: When the backend servers are not reachable, and global configuration ``setStaleCacheEntriesTTL`` is set appropriately, TTL that will be used when a stale cache entry is returned
565 :param bool dontAge: Don't reduce TTLs when serving from the cache. Use this when :program:`dnsdist` fronts a cluster of authoritative servers
566 :param int numberOfShards: Number of shards to divide the cache into, to reduce lock contention
567 :param bool deferrableInsertLock: Whether the cache should give up insertion if the lock is held by another thread, or simply wait to get the lock
568 :param int maxNegativeTTL: Cache a NXDomain or NoData answer from the backend for at most this amount of seconds, even if the TTL of the SOA record is higher
569 :param bool parseECS: Whether any EDNS Client Subnet option present in the query should be extracted and stored to be able to detect hash collisions involving queries with the same qname, qtype and qclass but a different incoming ECS value. Enabling this option adds a parsing cost and only makes sense if at least one backend might send different responses based on the ECS value, so it's disabled by default
570 :param table options: A table with key: value pairs with the options listed below:
571
572 Options:
573
574 * ``deferrableInsertLock=true``: bool - Whether the cache should give up insertion if the lock is held by another thread, or simply wait to get the lock.
575 * ``dontAge=false``: bool - Don't reduce TTLs when serving from the cache. Use this when :program:`dnsdist` fronts a cluster of authoritative servers.
576 * ``keepStaleData=false``: bool - Whether to suspend the removal of expired entries from the cache when there is no backend available in at least one of the pools using this cache.
577 * ``maxEntries``: int - The maximum number of entries in this cache.
578 * ``maxNegativeTTL=3600``: int - Cache a NXDomain or NoData answer from the backend for at most this amount of seconds, even if the TTL of the SOA record is higher.
579 * ``maxTTL=86400``: int - Cap the TTL for records to his number.
580 * ``minTTL=0``: int - Don't cache entries with a TTL lower than this.
581 * ``numberOfShards=1``: int - Number of shards to divide the cache into, to reduce lock contention.
582 * ``parseECS=false``: bool - Whether any EDNS Client Subnet option present in the query should be extracted and stored to be able to detect hash collisions involving queries with the same qname, qtype and qclass but a different incoming ECS value. Enabling this option adds a parsing cost and only makes sense if at least one backend might send different responses based on the ECS value, so it's disabled by default.
583 * ``staleTTL=60``: int - When the backend servers are not reachable, and global configuration ``setStaleCacheEntriesTTL`` is set appropriately, TTL that will be used when a stale cache entry is returned.
584 * ``temporaryFailureTTL=60``: int - On a SERVFAIL or REFUSED from the backend, cache for this amount of seconds..
585
586 .. class:: PacketCache
587
588 Represents a cache that can be part of :class:`ServerPool`.
589
590 .. method:: PacketCache:dump(fname)
591
592 .. versionadded:: 1.3.1
593
594 Dump a summary of the cache entries to a file.
595
596 :param str fname: The path to a file where the cache summary should be dumped. Note that if the target file already exists, it will not be overwritten.
597
598 .. method:: PacketCache:expunge(n)
599
600 Remove entries from the cache, leaving at most ``n`` entries
601
602 :param int n: Number of entries to keep
603
604 .. method:: PacketCache:expungeByName(name [, qtype=dnsdist.ANY[, suffixMatch=false]])
605
606 .. versionchanged:: 1.2.0
607 ``suffixMatch`` parameter added.
608
609 Remove entries matching ``name`` and type from the cache.
610
611 :param DNSName name: The name to expunge
612 :param int qtype: The type to expunge
613 :param bool suffixMatch: When set to true, remove al entries under ``name``
614
615 .. method:: PacketCache:getStats()
616
617 .. versionadded:: 1.3.4
618
619 Return the cache stats (number of entries, hits, misses, deferred lookups, deferred inserts, lookup collisions, insert collisions and TTL too shorts) as a Lua table.
620
621 .. method:: PacketCache:isFull() -> bool
622
623 Return true if the cache has reached the maximum number of entries.
624
625 .. method:: PacketCache:printStats()
626
627 Print the cache stats (number of entries, hits, misses, deferred lookups, deferred inserts, lookup collisions, insert collisions and TTL too shorts).
628
629 .. method:: PacketCache:purgeExpired(n)
630
631 Remove expired entries from the cache until there is at most ``n`` entries remaining in the cache.
632
633 :param int n: Number of entries to keep
634
635 .. method:: PacketCache:toString() -> string
636
637 Return the number of entries in the Packet Cache, and the maximum number of entries
638
639 Client State
640 ------------
641
642 Also called frontend or bind, the Client State object returned by :func:`getBind` and listed with :func:`showBinds` represents an address and port dnsdist is listening on.
643
644 .. function:: getBind(index) -> ClientState
645
646 Return a :class:`ClientState` object.
647
648 :param int index: The object index
649
650 ClientState functions
651 ~~~~~~~~~~~~~~~~~~~~~
652
653 .. class:: ClientState
654
655 This object represents an address and port dnsdist is listening on. When ``reuseport`` is in use, several ClientState objects can be present for the same address and port.
656
657 .. method:: ClientState:attachFilter(filter)
658
659 Attach a BPF filter to this frontend.
660
661 :param BPFFilter filter: The filter to attach to this frontend
662
663 .. method:: ClientState:detachFilter()
664
665 Remove the BPF filter associated to this frontend, if any.
666
667 .. method:: ClientState:toString() -> string
668
669 Return the address and port this frontend is listening on.
670
671 :returns: The address and port this frontend is listening on
672
673 .. attribute:: ClientState.muted
674
675 If set to true, queries received on this frontend will be normally processed and sent to a backend if needed, but no response will be ever be sent to the client over UDP. TCP queries are processed normally and responses sent to the client.
676
677 Status, Statistics and More
678 ---------------------------
679
680 .. function:: dumpStats()
681
682 Print all statistics dnsdist gathers
683
684 .. function:: getTLSContext(idx)
685
686 .. versionadded:: 1.3.0
687
688 Return the TLSContext object for the context of index ``idx``.
689
690 .. function:: getTLSFrontend(idx)
691
692 .. versionadded:: 1.3.1
693
694 Return the TLSFrontend object for the TLS bind of index ``idx``.
695
696 .. function:: grepq(selector[, num])
697 grepq(selectors[, num])
698
699 Prints the last ``num`` queries matching ``selector`` or ``selectors``.
700
701 The selector can be:
702
703 * a netmask (e.g. '192.0.2.0/24')
704 * a DNS name (e.g. 'dnsdist.org')
705 * a response time (e.g. '100ms')
706
707 :param str selector: Select queries based on this property.
708 :param {str} selectors: A lua table of selectors. Only queries matching all selectors are shown
709 :param int num: Show a maximum of ``num`` recent queries, default is 10.
710
711 .. function:: setVerboseHealthChecks(verbose)
712
713 Set whether health check errors should be logged. This is turned off by default.
714
715 :param bool verbose: Set to true if you want to enable health check errors logging
716
717 .. function:: showBinds()
718
719 Print a list of all the current addresses and ports dnsdist is listening on, also called ``frontends``
720
721 .. function:: showResponseLatency()
722
723 Show a plot of the response time latency distribution
724
725 .. function:: showServers([options])
726
727 .. versionchanged:: 1.3.4
728 ``options`` optional parameter added
729
730 This function shows all backend servers currently configured and some statistics.
731 These statics have the following fields:
732
733 * ``#`` - The number of the server, can be used as the argument for :func:`getServer`
734 * ``UUID`` - The UUID of the backend. Can be set with the ``id`` option of :func:`newServer`
735 * ``Address`` - The IP address and port of the server
736 * ``State`` - The current state of the server
737 * ``Qps`` - Current number of queries per second
738 * ``Qlim`` - Configured maximum number of queries per second
739 * ``Ord`` - The order number of the server
740 * ``Wt`` - The weight of the server
741 * ``Queries`` - Total amount of queries sent to this server
742 * ``Drops`` - Number of queries that were dropped by this server
743 * ``Drate`` - Number of queries dropped per second by this server
744 * ``Lat`` - The latency of this server in milliseconds
745 * ``Pools`` - The pools this server belongs to
746
747 :param table options: A table with key: value pairs with display options.
748
749 Options:
750
751 * ``showUUIDs=false``: bool - Whether to display the UUIDs, defaults to false.
752
753 .. function:: showTCPStats()
754
755 Show some statistics regarding TCP
756
757 .. function:: showTLSContexts()
758
759 .. versionadded:: 1.3.0
760
761 Print the list of all availables DNS over TLS contexts.
762
763 .. function:: showVersion()
764
765 Print the version of dnsdist
766
767 .. function:: topBandwidth([num])
768
769 Print the top ``num`` clients that consume the most bandwidth.
770
771 :param int num: Number to show, defaults to 10.
772
773 .. function:: topClients([num])
774
775 Print the top ``num`` clients sending the most queries over length of ringbuffer
776
777 :param int num: Number to show, defaults to 10.
778
779 .. function:: topQueries([num[, labels]])
780
781 Print the ``num`` most popular QNAMEs from queries.
782 Optionally grouped by the rightmost ``labels`` DNS labels.
783
784 :param int num: Number to show, defaults to 10
785 :param int label: Number of labels to cut down to
786
787 .. function:: topResponses([num[, rcode[, labels]]])
788
789 Print the ``num`` most seen responses with an RCODE of ``rcode``.
790 Optionally grouped by the rightmost ``labels`` DNS labels.
791
792 :param int num: Number to show, defaults to 10
793 :param int rcode: :ref:`Response code <DNSRCode>`, defaults to 0 (No Error)
794 :param int label: Number of labels to cut down to
795
796 .. function:: topSlow([num[, limit[, labels]]])
797
798 Print the ``num`` slowest queries that are slower than ``limit`` milliseconds.
799 Optionally grouped by the rightmost ``labels`` DNS labels.
800
801 :param int num: Number to show, defaults to 10
802 :param int limit: Show queries slower than this amount of milliseconds, defaults to 2000
803 :param int label: Number of labels to cut down to
804
805 .. _dynblocksref:
806
807 Dynamic Blocks
808 --------------
809
810 .. function:: addDynBlocks(addresses, message[, seconds=10[, action]])
811
812 .. versionchanged:: 1.2.0
813 ``action`` parameter added.
814
815 Block a set of addresses with ``message`` for (optionally) a number of seconds.
816 The default number of seconds to block for is 10.
817
818 :param addresses: set of Addresses as returned by an exceed function
819 :param string message: The message to show next to the blocks
820 :param int seconds: The number of seconds this block to expire
821 :param int action: The action to take when the dynamic block matches, see :ref:`here <DNSAction>`. (default to DNSAction.None, meaning the one set with :func:`setDynBlocksAction` is used)
822
823 Please see the documentation for :func:`setDynBlocksAction` to confirm which actions are supported by the action paramater.
824
825 .. function:: clearDynBlocks()
826
827 Remove all current dynamic blocks.
828
829 .. function:: showDynBlocks()
830
831 List all dynamic blocks in effect.
832
833 .. function:: setDynBlocksAction(action)
834
835 .. versionchanged:: 1.3.3
836 ``DNSAction.NXDomain`` action added.
837
838 Set which action is performed when a query is blocked.
839 Only DNSAction.Drop (the default), DNSAction.NoOp, DNSAction.NXDomain, DNSAction.Refused, DNSAction.Truncate and DNSAction.NoRecurse are supported.
840
841 .. _exceedfuncs:
842
843 Getting addresses that exceeded parameters
844 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
845
846 .. function:: exceedServFails(rate, seconds)
847
848 Get set of addresses that exceed ``rate`` servfails/s over ``seconds`` seconds
849
850 :param int rate: Number of Servfails per second to exceed
851 :param int seconds: Number of seconds the rate has been exceeded
852
853 .. function:: exceedNXDOMAINs(rate, seconds)
854
855 get set of addresses that exceed ``rate`` NXDOMAIN/s over ``seconds`` seconds
856
857 :param int rate: Number of NXDOMAIN per second to exceed
858 :param int seconds: Number of seconds the rate has been exceeded
859
860 .. function:: exceedRespByterate(rate, seconds)
861
862 get set of addresses that exceeded ``rate`` bytes/s answers over ``seconds`` seconds
863
864 :param int rate: Number of bytes per second to exceed
865 :param int seconds: Number of seconds the rate has been exceeded
866
867 .. function:: exceedQRate(rate, seconds)
868
869 Get set of address that exceed ``rate`` queries/s over ``seconds`` seconds
870
871 :param int rate: Number of queries per second to exceed
872 :param int seconds: Number of seconds the rate has been exceeded
873
874 .. function:: exceedQTypeRate(type, rate, seconds)
875
876 Get set of address that exceed ``rate`` queries/s for queries of QType ``type`` over ``seconds`` seconds
877
878 :param int type: QType
879 :param int rate: Number of QType queries per second to exceed
880 :param int seconds: Number of seconds the rate has been exceeded
881
882 DynBlockRulesGroup
883 ~~~~~~~~~~~~~~~~~~
884
885 Instead of using several `exceed*()` lines, dnsdist 1.3.0 introduced a new `DynBlockRulesGroup` object
886 which can be used to group dynamic block rules.
887
888 See :doc:`../guides/dynblocks` for more information about the case where using a `DynBlockRulesGroup` might be
889 faster than the existing rules.
890
891 .. function:: dynBlockRulesGroup() -> DynBlockRulesGroup
892
893 .. versionadded:: 1.3.0
894
895 Creates a new :class:`DynBlockRulesGroup` object.
896
897 .. class:: DynBlockRulesGroup
898
899 Represents a group of dynamic block rules.
900
901 .. method:: DynBlockRulesGroup:setQueryRate(rate, seconds, reason, blockingTime [, action [, warningRate]])
902
903 .. versionchanged:: 1.3.3
904 ``warningRate`` parameter added.
905
906 Adds a query rate-limiting rule, equivalent to:
907 ```
908 addDynBlocks(exceedQRate(rate, seconds), reason, blockingTime, action)
909 ```
910
911 :param int rate: Number of queries per second to exceed
912 :param int seconds: Number of seconds the rate has been exceeded
913 :param string reason: The message to show next to the blocks
914 :param int blockingTime: The number of seconds this block to expire
915 :param int action: The action to take when the dynamic block matches, see :ref:`here <DNSAction>`. (default to the one set with :func:`setDynBlocksAction`)
916 :param int warningRate: If set to a non-zero value, the rate above which a warning message will be issued and a no-op block inserted
917
918 .. method:: DynBlockRulesGroup:setRCodeRate(rcode, rate, seconds, reason, blockingTime [, action [, warningRate]])
919
920 .. versionchanged:: 1.3.3
921 ``warningRate`` parameter added.
922
923 Adds a rate-limiting rule for responses of code ``rcode``, equivalent to:
924 ```
925 addDynBlocks(exceedServfails(rcode, rate, seconds), reason, blockingTime, action)
926 ```
927
928 :param int rcode: The response code
929 :param int rate: Number of responses per second to exceed
930 :param int seconds: Number of seconds the rate has been exceeded
931 :param string reason: The message to show next to the blocks
932 :param int blockingTime: The number of seconds this block to expire
933 :param int action: The action to take when the dynamic block matches, see :ref:`here <DNSAction>`. (default to the one set with :func:`setDynBlocksAction`)
934 :param int warningRate: If set to a non-zero value, the rate above which a warning message will be issued and a no-op block inserted
935
936 .. method:: DynBlockRulesGroup:setQTypeRate(qtype, rate, seconds, reason, blockingTime [, action [, warningRate]])
937
938 .. versionchanged:: 1.3.3
939 ``warningRate`` parameter added.
940
941 Adds a rate-limiting rule for queries of type ``qtype``, equivalent to:
942 ```
943 addDynBlocks(exceedQTypeRate(type, rate, seconds), reason, blockingTime, action)
944 ```
945
946 :param int qtype: The qtype
947 :param int rate: Number of queries per second to exceed
948 :param int seconds: Number of seconds the rate has been exceeded
949 :param string reason: The message to show next to the blocks
950 :param int blockingTime: The number of seconds this block to expire
951 :param int action: The action to take when the dynamic block matches, see :ref:`here <DNSAction>`. (default to the one set with :func:`setDynBlocksAction`)
952 :param int warningRate: If set to a non-zero value, the rate above which a warning message will be issued and a no-op block inserted
953
954 .. method:: DynBlockRulesGroup:setResponseByteRate(rate, seconds, reason, blockingTime [, action [, warningRate]])
955
956 .. versionchanged:: 1.3.3
957 ``warningRate`` parameter added.
958
959 Adds a bandwidth rate-limiting rule for responses, equivalent to:
960 ```
961 addDynBlocks(exceedRespByterate(rate, seconds), reason, blockingTime, action)
962 ```
963
964 :param int rate: Number of bytes per second to exceed
965 :param int seconds: Number of seconds the rate has been exceeded
966 :param string reason: The message to show next to the blocks
967 :param int blockingTime: The number of seconds this block to expire
968 :param int action: The action to take when the dynamic block matches, see :ref:`here <DNSAction>`. (default to the one set with :func:`setDynBlocksAction`)
969 :param int warningRate: If set to a non-zero value, the rate above which a warning message will be issued and a no-op block inserted
970
971 .. method:: DynBlockRulesGroup:apply()
972
973 Walk the in-memory query and response ring buffers and apply the configured rate-limiting rules, adding dynamic blocks when the limits have been exceeded.
974
975 .. method:: DynBlockRulesGroup:excludeRange(netmasks)
976
977 .. versionadded:: 1.3.1
978
979 Exclude this range, or list of ranges, meaning that no dynamic block will ever be inserted for clients in that range. Default to empty, meaning rules are applied to all ranges. When used in combination with :meth:`DynBlockRulesGroup:includeRange`, the more specific entry wins.
980
981 :param int netmasks: A netmask, or list of netmasks, as strings, like for example "192.0.2.1/24"
982
983 .. method:: DynBlockRulesGroup:includeRange(netmasks)
984
985 .. versionadded:: 1.3.1
986
987 Include this range, or list of ranges, meaning that rules will be applied to this range. When used in combination with :meth:`DynBlockRulesGroup:excludeRange`, the more specific entry wins.
988
989 :param int netmasks: A netmask, or list of netmasks, as strings, like for example "192.0.2.1/24"
990
991 .. method:: DynBlockRulesGroup:toString()
992
993 .. versionadded:: 1.3.1
994
995 Return a string describing the rules and range exclusions of this DynBlockRulesGroup.
996
997 Other functions
998 ---------------
999
1000 .. function:: maintenance()
1001
1002 If this function exists, it is called every second to so regular tasks.
1003 This can be used for e.g. :doc:`Dynamic Blocks <../guides/dynblocks>`.
1004
1005 .. function: setAllowEmptyResponse()
1006
1007 .. versionadded:: 1.4.0
1008
1009 Set to true (defaults to false) to allow empty responses (qdcount=0) with a NoError or NXDomain rcode (default) from backends. dnsdist drops these responses by default because it can't match them against the initial query since they don't contain the qname, qtype and qclass, and therefore the risk of collision is much higher than with regular responses.
1010
1011 TLSContext
1012 ~~~~~~~~~~
1013
1014 .. class:: TLSContext
1015
1016 .. versionadded:: 1.3.0
1017
1018 This object represents an address and port dnsdist is listening on for DNS over TLS queries.
1019
1020 .. method:: TLSContext:rotateTicketsKey()
1021
1022 Replace the current TLS tickets key by a new random one.
1023
1024 .. method:: TLSContext:loadTicketsKeys(ticketsKeysFile)
1025
1026 Load new tickets keys from the selected file, replacing the existing ones. These keys should be rotated often and never written to persistent storage to preserve forward secrecy. The default is to generate a random key. The OpenSSL provider supports several tickets keys to be able to decrypt existing sessions after the rotation, while the GnuTLS provider only supports one key.
1027
1028 :param str ticketsKeysFile: The path to a file from where TLS tickets keys should be loaded.
1029
1030 TLSFrontend
1031 ~~~~~~~~~~~
1032
1033 .. class:: TLSFrontend
1034
1035 .. versionadded:: 1.3.1
1036
1037 This object represents the configuration of a listening frontend for DNS over TLS queries. To each frontend is associated a TLSContext.
1038
1039 .. method:: TLSContext:loadNewCertificatesAndKeys(certFile(s), keyFile(s))
1040
1041 Create and switch to a new TLS context using the same options than were passed to the corresponding `addTLSLocal()` directive, but loading new certificates and keys from the selected files, replacing the existing ones.
1042
1043 :param str certFile(s): The path to a X.509 certificate file in PEM format, or a list of paths to such files.
1044 :param str keyFile(s): The path to the private key file corresponding to the certificate, or a list of paths to such files, whose order should match the certFile(s) ones.
1045
1046 EDNS on Self-generated answers
1047 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1048
1049 There are several mechanisms in dnsdist that turn an existing query into an answer right away,
1050 without reaching out to the backend, including :func:`SpoofAction`, :func:`RCodeAction`, :func:`TCAction`
1051 and returning a response from ``Lua``. Those responses should, according to :rfc:`6891`, contain an ``OPT``
1052 record if the received request had one, which is the case by default and can be disabled using
1053 :func:`setAddEDNSToSelfGeneratedResponses`.
1054
1055 We must, however, provide a responder's maximum payload size in this record, and we can't easily know the
1056 maximum payload size of the actual backend so we need to provide one. The default value is 1500 and can be
1057 overriden using :func:`setPayloadSizeOnSelfGeneratedAnswers`.
1058
1059 .. function:: setAddEDNSToSelfGeneratedResponses(add)
1060
1061 .. versionadded:: 1.3.3
1062
1063 Whether to add EDNS to self-generated responses, provided that the initial query had EDNS.
1064
1065 :param bool add: Whether to add EDNS, default is true.
1066
1067 .. function:: setPayloadSizeOnSelfGeneratedAnswers(payloadSize)
1068
1069 .. versionadded:: 1.3.3
1070
1071 Set the UDP payload size advertised via EDNS on self-generated responses. In accordance with
1072 :rfc:`RFC 6891 <6891#section-6.2.5>`, values lower than 512 will be treated as equal to 512.
1073
1074 :param int payloadSize: The responder's maximum UDP payload size, in bytes. Default is 1500.
1075
1076 Security Polling
1077 ~~~~~~~~~~~~~~~~
1078
1079 PowerDNS products can poll the security status of their respective versions. This polling, naturally,
1080 happens over DNS. If the result is that a given version has a security problem, the software will
1081 report this at level ‘Error’ during startup, and repeatedly during operations, every
1082 :func:`setSecurityPollInterval` seconds.
1083
1084 By default, security polling happens on the domain ‘secpoll.powerdns.com’, but this can be changed with
1085 the :func:`setSecurityPollSuffix` function. If this setting is made empty, no polling will take place.
1086 Organizations wanting to host their own security zones can do so by changing this setting to a domain name
1087 under their control.
1088
1089 To enable distributors of PowerDNS to signal that they have backported versions, the PACKAGEVERSION
1090 compilation-time macro can be used to set a distributor suffix.
1091
1092 .. function:: setSecurityPollInterval(interval)
1093
1094 .. versionadded:: 1.3.3
1095
1096 Set the interval, in seconds, between two security pollings.
1097
1098 :param int interval: The interval, in seconds, between two pollings. Default is 3600.
1099
1100 .. function:: setSecurityPollSuffix(suffix)
1101
1102 .. versionadded:: 1.3.3
1103
1104 Domain name from which to query security update notifications. Setting this to an empty string disables secpoll.
1105
1106 :param string suffix: The suffix to use, default is 'secpoll.powerdns.com.'.