Add custom DNS server on Linux
orphan
Add custom DNS server on Linux
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.
Assumption
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.
Non permanent solution
When you just want to try out to add a new DNS server without permanent settings, you should use this option.
[!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.
-
Open
/etc/resolv.confwith root or sudo privileges with your favourite editor on your host operating sustem:Terminal window host> sudo vi /etc/resolv.conf -
Add your new
nameserverdirective above all existing nameserver directives:Terminal window # Generated by NetworkManagersearch intranetnameserver 127.0.0.1nameserver 192.168.0.10 -
It will work instantly after saving the file
Network Manager
(This is a permanent solution and needs to be reverted when you don’t need it anymore)
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).
Add the following line to to the very beginning to
/etc/dhcp/dhclient.conf:
prepend domain-name-servers 127.0.0.1;When you do that for the first time, you need to restart the
network-manager service.
# Via service commandhost> sudo service network-manager restart
# Or the systemd wayhost> sudo systemctl restart network-managerThis 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.
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.
systemd-resolved
(This is a permanent solution and needs to be reverted when you don’t need it anymore)
In case you are using systemd-resolved instead of NetworkManager, add
the following line to the very beginning to /etc/resolv.conf.head:
nameserver 127.0.0.1Prevent 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
dns=noneAs a last step you will have to restart systemd-resolved.
host> sudo systemctl stop systemd-resolvedhost> sudo systemctl start systemd-resolvedOnce done, you can verify if the new DNS settings are effective:
host> systemd-resolve --statusdns archlinux wiki resolv conf