Setting up a permanent DNS address server on Ubuntu and Debian Linux

Setting up a permanent DNS address server on Ubuntu and Debian Linux

In this tutorial, we will look at how to install and use the resolvconf program to set a permanent DNS address server in the /etc/resolv.conf file on Debian and Ubuntu Linux distributions. Stay with us.

/etc/resolv.conf is the main configuration file for the DNS name resolver library. A resolver is actually a set of functions in the C library that provides access to the Internet’s Domain Naming System , or DNS. These functions are set to check the entries in the /etc/hosts file or some DNS name servers or to use the network information database service or NIC.

On modern Linux-based systems that use the system management tool and systemd service, DNS or name resolution services are provided to help local applications using the systemd-resolved service. By default, this service has four different modes to manage domain name analysis. Also, by default, the systemd DNS stub file at /run/systemd/resolve/stub-resolv.conf is used.

The file contains the local address 127.0.0.53 as the only DNS server. This address refers to the /etc/resolv.conf file, which is used by the system to add server titles.

If you run the following ls command for /etc/resolv.conf, you will see that this file is a symlink to the /run/systemd/resolve/stub-resolv.conf file.

1
$ ls -l /etc/resolv.conf
1
lrwxrwxrwx 1 root root 39 Feb 15  2019 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf

Of course, considering that /etc/resolv.conf is indirectly managed by the systemd-resolved service and in some cases is under the control of the network service (by initscripts or NetworkManager), any manual changes by the user cannot be permanent. or stored for a certain period of time.

Why should we edit the /etc/resolv.conf file?

The main reason for this is that the system’s DNS settings are usually not set correctly. You may also prefer to use your own server titles. The following cat command will show the default server address in the /etc/resolv.conf file on the sample Ubuntu system.

1
$ cat /etc/resolv.conf

Check DNS name servers

Here, when local applications such as the APT package management tool try to access FQDNs on the local network, the result will contain the error message “Temporary failure in name resolution” as shown in the image below.

Temporary problem in DNS server title parsing

The same thing happens when using the ping command.

1
$ ping google.com

Temporary problem in name parsing

Therefore, when a user tries to manually configure DNS address servers, these changes will not be permanent. In fact, these settings will be lost after a single system restart. To overcome this problem, you can install the reolvconf tool so that you can apply the changes permanently.

In order to install the resolvconf package, you must first manually configure all DNS address servers in the /etc/resolv.conf file. This way you can access FQDMs of Ubuntu source servers on the Internet.

1
2
3
nameserver 8.8.4.4
nameserver 8.8.8.8

Installing resolvconf on Ubuntu and Debian

First, we update the system software packages. Then we will install resolvconf from official sources using the following commands.

1
2
3
$ sudo apt update
$ sudo apt install resolvconf

When the resolvconf tool installation is finished, systemd will automatically run and enable resolvconf.service. You can use the following command to check the status of this service.

1
$ sudo systemctl status resolvconf.service

If this service does not start and is not activated automatically for any reason, you can run and activate it using the following commands.

1
2
3
4
5
$ sudo systemctl start resolvconf.service
$ sudo systemctl enable resolvconf.service
$ sudo systemctl status resolvconf.service

Checking the service status of the resolvconf tool

Setting permanent DNS server address in Ubuntu and Debian

Then it’s time to set the configuration file /etc/resolvconf/resolv.conf.d/head.

1
$ sudo nano /etc/resolvconf/resolv.conf.d/head

Add the following in it.

1
2
3
nameserver 8.8.8.8
nameserver 8.8.4.4

Setting permanent DNS address server in Resolvconf

Now save the changes and restart the resolvconf.service. You can also reboot the system.

1
$ sudo systemctl start resolvconf.service

Now by checking the /etc/resolv.conf file you will notice that the imported title servers are permanently stored in it. From now on, there will be no problem in resolving the DNS server name in your system.

Permanent DNS address servers

We hope that this article about setting up a permanent DNS address server in Ubuntu and Debian has been of interest to you. Be sure to follow the future contents of hosting100’s blog in this field

support hosting100