How to set DNS servers on Debian

You can set your DNS server on Debian using only a few commands or by using your computer’s interface, or GUI. A third way to do this is to make the changes via your internet router.

How to set your DNS server on Debian in the network settings

If you want to set the DNS server without the command prompt, you can do it directly through the settings.

Step 1: Go to the network settings and click on the symbol for further settings (the cogwheel).

Step 2: You can enter a new DNS server under the IPv4 and IPv6 tabs. If you wish to use multiple server alternatives, separate them by a comma.

debian-dns-server-network-settings.png
With Debian’s GUI, you can easily add the DNS servers of your choice in the DNS field.

How to set your DNS server using the configuration file

You can also set the DNS server in Debian via the command-line. To do this, open the terminal.

Step 1: If you are not already logged in as root, you need to get root privileges first:

su
bash

Step 2: The nameserver entries are located in the resolv.conf file. Technically this is where new DNS servers can be inserted. However, this file is managed by the system and gets overwritten regularly. To prevent these rewrites from happening, you must install the resolvconf program. Otherwise, the system will continue being updated as usual:

apt update
apt upgrade
apt install resolvconf
bash

Step 3: Check if the program has already started:

systemctl status resolvconf.service
bash

The status of the program should be displayed as “active”. If this is not the case, you can activate the service with the following commands:

systemctl start resolvconf.service
systemctl enable resolvconf.service
systemctl status resolvconf.service
bash

Step 4: Next you’ll customize the head document of this service. First, open the file, for example, with the nano editor:

nano /etc/resolvconf/resolv.conf.d/head
bash

Now, enter the DNS server(s) you want into this file. For example, many people like to use the public DNS servers offered by Google. To use them, you need to enter the following IP addresses:

nameserver 8.8.8.8
nameserver 8.8.4.4
bash
debian-dns-server-resolvconf-head-document.png
Enter the data for the nameservers you would like to use.

Save and close the file.

Step 5: Lastly, you just need to update the resolv.conf file. To do this, use the following command:

resolvconf --enable-updates
resolvconf -u
bash

Now when you open the resolv.conf file, these two services should be inserted:

nano /etc/resolv.conf
bash

Now you have successfully changed the DNS server on Debian.

How to set DNS servers using your router

Alternatively, you can change the DNS server directly in your router. The advantage of this method is that it’ll allow all devices in your network to use the same DNS server(s), without you having to configure each device separately.

You can usually access the configuration settings of your router via a URL, which can be found in the router’s manual. The manual also contains the login credentials to access the settings. For example, with a Fritz!Box router, you can access the configuration interface by going to “http://fritz.box/”. The DNS settings can be found under “Account Information” in the internet settings section.

debian-dns-server-router-settings.png
In this router model of Fritz!Box, the settings for configuring DNS servers can be found under “Account Information” in the internet setting section

Check your internet router provider’s manual or website for how to set DNS on Debian as this can vary per manufacturer.

Why should you set another DNS server on Debian?

The Domain Name System, or DNS, makes it possible to use domain names instead of IP addresses when navigating the web. Using this system, DNS servers provide your computer (or any other device) with the information it needs to surf the web. Many users rely on a default DNS server given to them by their internet provider, but there are good reasons to change DNS servers:

  • Overloading: If you receive the error message that your DNS server is not responding, the server you are using might be temporarily offline.
  • Bypass censorship: Some countries use the DNS servers assigned by internet providers to censor information.
  • Speed: Some DNS servers can provide a faster internet connection.
Was this article helpful?
We use cookies on our website to provide you with the best possible user experience. By continuing to use our website or services, you agree to their use. More Information.
Page top