]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
docs: polish network configuration bits
authorPetr Špaček <petr.spacek@nic.cz>
Thu, 18 Apr 2019 15:25:03 +0000 (17:25 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Thu, 18 Apr 2019 15:25:03 +0000 (17:25 +0200)
daemon/README.rst
daemon/bindings/net.rst
modules/http/README.rst

index 3d76095bd2a4dfc0cb99be9bec71a5e09bbc23ef..7d4343fd12397777fde33999f6716b84564d122c 100644 (file)
@@ -6,8 +6,8 @@ The server is in the `daemon` directory, it works out of the box without any con
 
 .. code-block:: bash
 
-   $ kresd -h # Get help
-   $ kresd -a ::1
+   $ kresd -v  # run with defaults in verbose mode
+   $ kresd -h  # Get help
 
 If you're using our packages, they also provide systemd integration. To start the resolver under systemd, you can use the ``kresd@1.service`` service. By default, the resolver only binds to local interfaces.
 
index 458683ef0eb7fd6eb571a71279078268bb202e8d..f9920bf23ef1684a72576c1d55117b808fad05f2 100644 (file)
@@ -3,15 +3,36 @@
 Network configuration
 ^^^^^^^^^^^^^^^^^^^^^
 
-For when listening on ``localhost`` just doesn't cut it.
+Modern Linux distributions use so-called *Systemd socket activation*, which
+effectivelly means that IP addresses and ports to listen on are configured
+in Systemd configuration files.
 
-**Systemd socket configuration**
+Older Linux systems and all non-Linux systems do not support this modern method
+and have to resort to old fashioned way of configuring things using
+``net.listen()`` configuration call.
+Most notable examples of such systems are CentOS 7 and macOS.
+
+.. warning:: On machines with multiple IP addresses avoid listening on wildcards
+        ``0.0.0.0`` or ``::``. Knot Resolver could answer from different IP
+        addresses if the network address ranges overlap,
+        and clients would probably refuse such a response.
+
+**Network configuration using systemd**
 
 If you're using our packages with systemd with sockets support (not supported
-on CentOS 7), network interfaces are configured using systemd drop-in files for
-``kresd.socket``, ``kresd-tls.socket`` and ``kresd-doh.socket``.
+on CentOS 7), network interfaces are configured using systemd drop-in files.
+Each protocol has its own configuration file:
+
+.. csv-table::
+  :header: "**Network protocol**", "**Socket file name**"
+
+  "DNS (UDP+TCP, :rfc:`1034`)","``kresd.socket``"
+  ":ref:`DNS-over-TLS (DoT) <tls-server-config>`","``kresd-tls.socket``"
+  ":ref:`mod-http-doh`","``kresd-doh.socket``"
+  ":ref:`Web management <mod-http-built-in-services>`","``kresd-webmgmt.socket``"
 
-To configure kresd to listen on public interface, create a drop-in file:
+To configure kresd to listen on public a interface using the original DNS protocol,
+create a drop-in file:
 
 .. code-block:: bash
 
@@ -20,13 +41,37 @@ To configure kresd to listen on public interface, create a drop-in file:
 .. code-block:: none
 
    # /etc/systemd/system/kresd.socket.d/override.conf
+   # always listen on UDP (datagram) and TCP (stream) as well
    [Socket]
    ListenDatagram=192.0.2.115:53
    ListenStream=192.0.2.115:53
 
+Configuration you provide is automatically merged with defaults from your
+distribution. It is also possible to check resulting configuration using
+``systemctl cat``:
+
+.. code-block:: bash
+
+   $ systemctl cat kresd.socket
+
+.. code-block:: none
+
+   # merged result: user configuration + distro defaults
+   [Socket]
+   FileDescriptorName=dns
+   FreeBind=true
+   BindIPv6Only=both
+   ListenDatagram=[::1]:53
+   ListenStream=[::1]:53
+   ListenDatagram=127.0.0.1:53
+   ListenStream=127.0.0.1:53
+   ListenDatagram=192.0.2.115:53
+   ListenStream=192.0.2.115:53
+
+
 .. _kresd-socket-override-port:
 
-The default locahost interface/port can also be removed/overriden by using an
+The default localhost interface/port can also be removed/overriden by using an
 empty ``ListenDatagram=`` or ``ListenStream=`` directive. This can be used when
 you want to configure kresd to listen on all IPv4/IPv6 network interfaces (if
 you've disabled IPv6 support in kernel, use ``0.0.0.0`` instead of ``[::]`` ).
@@ -45,9 +90,10 @@ you've disabled IPv6 support in kernel, use ``0.0.0.0`` instead of ``[::]`` ).
    possible workarounds, see
    https://gitlab.labs.nic.cz/knot/knot-resolver/issues/445
 
-It can also be useful if you want to use the Knot DNS with the `dnsproxy
-module`_ to have both resolver and authoritative server running on the same
-machine.
+It can also be useful if you want to use the Knot DNS authoritative server
+with the `dnsproxy module`_ to have both resolver and authoritative server
+running on the same machine. This is not recommended configuration but it can
+be done like this:
 
 .. code-block:: none
 
@@ -63,7 +109,7 @@ machine.
 .. _kresd-tls-socket-override-port:
 
 The ``kresd-tls.socket`` can also be configured in the same way to listen for
-TLS connections.
+DNS-over-TLS connections (:rfc:`7858`).
 
 .. code-block:: bash
 
@@ -72,18 +118,24 @@ TLS connections.
 .. code-block:: none
 
    # /etc/systemd/system/kresd-tls.socket.d/override.conf
+   # specify only TCP (stream), DTLS is not supported
    [Socket]
    ListenStream=192.0.2.115:853
 
-To configure socket for DNS-over-HTTPS, make sure you have
-``kresd-doh.socket`` installed (it might be part of a separate
-``knot-resolver-module-http`` package).  Then, you can configure its network
-interfaces as above. Also, don't forget to load http module in configuration
-file, otherwise the socket won't have any function.
+When configuring sockets for :ref:`mod-http-doh`, make sure you have
+``kresd-doh.socket`` installed, it might be part of a separate
+``knot-resolver-module-http`` package.
+
+.. warning:: Make sure you read section :ref:`mod-http-doh` before exposing
+             the DoH protocol to outside.
 
 For example, to remove the default localhost:44353 and listen on all interfaces
 on port 443, create the following drop-in file for ``kresd-doh.socket``:
 
+.. code-block:: bash
+
+   $ systemctl edit kresd-doh.socket
+
 .. code-block:: bash
 
    # /etc/systemd/system/kresd-doh.socket.d/override.conf
@@ -93,67 +145,71 @@ on port 443, create the following drop-in file for ``kresd-doh.socket``:
 
 Make sure no other service is using port 443, as that will result in
 unpredictable behaviour. Alternately, you can use port 44353 where a collision
-is unlikely. Also, don't forget to load http module in configuration file.
-
-**Daemon network configuration**
-
-If you don't use systemd with sockets to run kresd, network interfaces are
-configured in the config file.
-
-.. tip:: Use declarative interface for network.
-
-         .. code-block:: lua
-
-            net = { '127.0.0.1', net.eth0, net.eth1.addr[1] }
-            net.ipv4 = false
-
-.. warning:: On machines with multiple IP addresses avoid binding to wildcard ``0.0.0.0`` or ``::`` (see example below). Knot Resolver could answer from different IP in case the ranges overlap and client will probably refuse such a response.
-
-         .. code-block:: lua
-
-            net = { '0.0.0.0' }
-
-
-.. envvar:: net.ipv6 = true|false
-
-   :return: boolean (default: true)
-
-   Enable/disable using IPv6 for contacting upstream nameservers.
+is unlikely.
 
-.. envvar:: net.ipv4 = true|false
+Also, don't forget to :ref:`load http module in configuration <mod-http-example>`
+file, otherwise the socket won't work.
 
-   :return: boolean (default: true)
+**Legacy network configuration using configuration file**
 
-   Enable/disable using IPv4 for contacting upstream nameservers.
+If you don't use systemd with sockets to run kresd, addresses and ports to listen
+on are configured in the config file.
 
 .. function:: net.listen(addresses, [port = 53, { kind = 'dns' }])
 
    :return: boolean
 
    Listen on addresses; port and flags are optional.
-   The addresses can be specified as a string or device,
-   or a list of addresses (recursively).
+   The addresses can be specified as a string or device.
    The command can be given multiple times,
    but repeating an address-port combination is an error.
+   Port 853 implies ``kind = 'tls'`` but it is always better to be explicit.
 
-   If you specify port 853, ``kind = 'tls'`` by default.
+.. csv-table::
+  :header: "**Network protocol**", "**Configuration command**"
 
-   Examples:
+  "DNS (UDP+TCP, :rfc:`1034`)","``net.listen('192.0.2.123', 53)``"
+  ":ref:`DNS-over-TLS (DoT) <tls-server-config>`","``net.listen('192.0.2.123', 853, { kind = 'tls' })``"
+  ":ref:`mod-http-doh`","``net.listen('192.0.2.123', 443, { kind = 'doh' })``"
+  ":ref:`Web management <mod-http-built-in-services>`","``net.listen('192.0.2.123', 8453, { kind = 'webmgmt' })``"
+
+
+Examples:
 
    .. code-block:: lua
 
        net.listen('::1')
-       net.listen(net.lo, 5353)
-       net.listen({net.eth0, '127.0.0.1'}, 53853, { kind = 'tls' })
+       net.listen(net.lo, 53)
+       net.listen(net.eth0, 853, { kind = 'tls' })
        net.listen('::', 443, { kind = 'doh' }) -- see http module
        net.listen('::', 8453, { kind = 'webmgmt' }) -- see http module
 
+.. warning:: Make sure you read section :ref:`mod-http-doh` before exposing
+             the DNS-over-HTTP protocol to outside.
+
 .. function:: net.close(address, [port])
 
    :return: boolean (at least one endpoint closed)
 
    Close all endpoints listening on the specified address, optionally restricted by port as well.
 
+
+**Additional network configuration options**
+
+Following commands are useful in special situations and can be usef with and without systemd socket activation:
+
+.. envvar:: net.ipv6 = true|false
+
+   :return: boolean (default: true)
+
+   Enable/disable using IPv6 for contacting upstream nameservers.
+
+.. envvar:: net.ipv4 = true|false
+
+   :return: boolean (default: true)
+
+   Enable/disable using IPv4 for contacting upstream nameservers.
+
 .. function:: net.list()
 
    :return: Table of bound interfaces.
@@ -250,21 +306,13 @@ configured in the config file.
 
 TLS server configuration
 ^^^^^^^^^^^^^^^^^^^^^^^^
-.. note:: Installations using systemd should be configured using systemd-specific procedures
-          described in manual page ``kresd.systemd(7)``.
-
-DNS-over-TLS server (:rfc:`7858`) can be enabled using ``{tls = true}`` parameter
-in :c:func:`net.listen()` function call. For example:
-
-.. code-block:: lua
-
-      > net.listen("::", 53)  -- plain UDP+TCP on port 53 (standard DNS)
-      > net.listen("::", 853, {tls = true})  -- DNS-over-TLS on port 853 (standard DoT)
-      > net.listen("::", 443, {tls = true})  -- DNS-over-TLS on port 443 (non-standard)
+DNS-over-TLS server (:rfc:`7858`) is enabled by default on loopback interface port 853.
+Information how to configure listening on specific IP addresses is in previous sections
+:ref:`network-configuration`.
 
-By default an self-signed certificate will be generated. For serious deployments
-it is strongly recommended to provide TLS certificates signed by a trusted CA
-using :c:func:`net.tls()`.
+By default a self-signed certificate is generated. For serious deployments
+it is strongly recommended to configure your own TLS certificates signed
+by a trusted CA. This is done using function :c:func:`net.tls()`.
 
 .. function:: net.tls([cert_path], [key_path])
 
index 4c50232eb19c1e69f85667ed0cbe435c9adcba50..e567689191c75a072ec8248ca89880613acc73af 100644 (file)
@@ -24,8 +24,7 @@ and unlimited number of "used-defined kinds" can be added in configuration.
 Each network address and port combination can be configured to expose
 one kind of endpoint. This is done using the same mechanisms as
 network configuration for plain DNS and DNS-over-TLS,
-see chapter :ref:`network configuration <kresd-tls-socket-override-port>`
-for more details.
+see chapter :ref:`network-configuration` for more details.
 
 .. warning:: Management endpoint (``webmgmt``) must not be directly exposed
              to untrusted parties. Use `reverse-proxy`_ like Apache_
@@ -40,20 +39,9 @@ This can be changed using ``http.config()`` configuration call explained below.
 Example configuration
 ^^^^^^^^^^^^^^^^^^^^^
 
-Here we show how to configure web management API on loopback interface
-on port 8453, and how to expose :ref:`mod-http-doh` endpoint on public IP addresses.
-
-For network configuration when using systemd socket activation, refer to
-:ref:`network-configuration`. Please note ``kresd-webmgmt.socket`` is
-configured to listen on loopack interface on port 8453 by default and requires
-no further configurtion.
-
-If your distribution isn't using systemd socket activation (e.g. CentOS 7 or
-macOS), use ``net.listen()`` and use kind ``doh`` for DNS-over-HTTPS and
-``webmgmt`` for web management API.
-
-.. warning:: Make sure you read section :ref:`mod-http-doh`
-             before copy&pasting this snippet.
+This section shows how to configure HTTP module itself. For information how
+to configure HTTP server's IP addresses and ports please see chapter
+:ref:`network-configuration`.
 
 .. code-block:: lua
 
@@ -120,6 +108,7 @@ for authentication to API etc.
 Safari doesn't allow WebSockets over HTTPS with a self-signed certificate.
 Major drawback is that current browsers won't do HTTP/2 over insecure connection.)
 
+.. _mod-http-built-in-services:
 
 Built-in services
 ^^^^^^^^^^^^^^^^^