devilbox/docs/howto/dns/add-custom-dns-server-on-linux.rst

127 lines
3.6 KiB
ReStructuredText
Raw Normal View History

2018-07-08 07:26:52 +00:00
:orphan:
.. _howto_add_custom_dns_server_on_linux:
******************************
Add custom DNS server on Linux
******************************
2018-07-08 10:23:57 +00:00
On Linux the DNS settings can be controlled by various different methods. Two of them are via
Network Manager and systemd-resolved. Choose on of the methods depending on your local setup.
2018-07-08 07:26:52 +00:00
**Table of Contents**
.. contents:: :local:
Assumption
==========
2018-07-08 10:23:57 +00:00
This tutorial is using ``127.0.0.1`` as the DNS server IP address, as it is the method to setup
Auto DNS for your local Devilbox.
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
Non permanent solution
=======================
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
When you just want to try out to add a new DNS server without permanent settings, you should use
this option.
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
.. note::
Non permanent means, the settings will be gone when your DHCP release will be renewed,
reconnecting to the network, restarting the network service, logging out or
rebooting your machine.
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
1. Open ``/etc/resolv.conf`` with root or sudo privileges with your favourite editor on your
host operating sustem:
2018-07-08 07:26:52 +00:00
.. code-block:: bash
2018-07-08 10:23:57 +00:00
host> sudo vi /etc/resolv.conf
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
2. Add your new ``nameserver`` directive **above** all existing nameserver directives:
2018-07-08 07:26:52 +00:00
.. code-block:: bash
2018-07-08 10:23:57 +00:00
:caption: /etc/resolv.conf
:emphasize-lines: 3
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
# Generated by NetworkManager
search intranet
nameserver 127.0.0.1
nameserver 192.168.0.10
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
3. It will work instantly after saving the file
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
Network Manager
===============
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
*(This is a permanent solution and needs to be reverted when you don't need it anymore)*
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
Edit ``/etc/dhcp/dhclient.conf`` with root or sudo privileges and add an instruction, which tells
your local DHCP client that whenever any of your DNS servers are changed, you always want to have
an additional entry, which is the one from the Devilbox (``127.0.0.1``).
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
Add the following line to to the very beginning to ``/etc/dhcp/dhclient.conf``:
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
.. code-block:: bash
:caption: /etc/dhcp/dhclient.conf
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
prepend domain-name-servers 127.0.0.1;
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
When you do that for the first time, you need to restart the ``network-manager`` service.
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
.. code-block:: bash
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
# Via service command
host> sudo service network-manager restart
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
# Or the systemd way
host> sudo systemctl restart network-manager
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
This will make sure that whenever your /etc/resolv.conf is deployed, you will have ``127.0.0.1``
as the first entry and also make use of any other DNS server which are deployed via the LAN's DHCP
server.
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
If the Devilbox DNS server is not running, it does not affect the name resolution, because you will
still have other entries in ``/etc/resolv.conf``.
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
systemd-resolved
================
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
*(This is a permanent solution and needs to be reverted when you don't need it anymore)*
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
In case you are using systemd-resolved instead of NetworkManager, add the following line to
the very beginning to ``/etc/resolv.conf.head``:
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
.. code-block:: bash
:caption: /etc/resolv.conf.head
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
nameserver 127.0.0.1
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
Prevent NetworkManager from modifying ``/etc/resolv.conf`` and leave everything to
systemd-resolved by adding the following line under the ``[main]`` section of
``/etc/NetworkManager/NetworkManager.conf``
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
.. code-block:: bash
:caption: /etc/NetworkManager/NetworkManager.conf
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
dns=none
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
As a last step you will have to restart ``systemd-resolved``.
.. code-block:: bash
host> sudo systemctl stop systemd-resolved
host> sudo systemctl start systemd-resolved
Once done, you can verify if the new DNS settings are effective:
.. code-block:: bash
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
host> systemd-resolve --status
2018-07-08 07:26:52 +00:00
2018-07-08 10:23:57 +00:00
.. seealso:: `Archlinux Wiki: resolv.conf <https://wiki.archlinux.org/index.php/Dhcpcd#resolv.conf>`_