What is the main configuration file for DNS in Ubuntu?

The /etc/resolv.conf is the main configuration file for the DNS name resolver library. The resolver is a set of functions in the C library that provide access to the Internet Domain Name System (DNS). The functions are configured to check entries in the /etc/hosts file, or several DNS name servers, or to use the host’s database of Network Information Service (NIS).

On modern Linux systems that use systemd (system and service manager), the DNS or name resolution services are provided to local applications via the systemd-resolved service. By default, this service has four different modes for handling the Domain name resolution and uses the systemd DNS stub file (/run/systemd/resolve/stub-resolv.conf) in the default mode of operation.

The DNS stub file contains the local stub 127.0.0.53 as the only DNS server, and it is redirected to the /etc/resolv.conf file which was used to add the name servers used by the system.

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

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

Unfortunately, because the /etc/resolv.conf is indirectly managed by the systemd-resolved service, and in some cases by the network service (by using initscripts or NetworkManager), any changes made manually by a user can not be saved permanently or only last for a while.

In this article, we will show how to install and use the resolvconf program to set permanent DNS name servers in /etc/resolv.conf file under Debian and Ubuntu Linux distributions.

Why Would You Want to Edit /etc/resolv.conf File?

The main reason could be because the system’s DNS settings are misconfigured or you prefer to use specific name servers or your own. The following cat command shows the default name server in the /etc/resolv.conf file on my Ubuntu system.

$ cat /etc/resolv.conf
What is the main configuration file for DNS in Ubuntu?
Check DNS Name Servers

In this case, when local applications such as the APT package manager try to access FQDNs (Fully Qualified Domain Names) on the local network, the result is a “Temporary failure in name resolution” error as shown in the next screenshot.

What is the main configuration file for DNS in Ubuntu?
Temporary Failure Resolving

The same happens when you run a ping command.

$ ping google.com
What is the main configuration file for DNS in Ubuntu?
Temporary Failure in Name Resolution

So when a user tries to manually set the name servers, the changes do not last for long or are revoked after a reboot. To resolve this, you can install and use the reolvconf utility to make the changes permanent.

To install the resolvconf package as shown in the next section, you need to first manually set the following name servers in the /etc/resolv.conf file, so that you access the FQDMs of Ubuntu repository servers on the internet.

nameserver 8.8.4.4 nameserver 8.8.8.8

Read Also: How to Setup Local DNS Using /etc/hosts File in Linux

Installing resolvconf in Ubuntu and Debian

First, update the system software packages and then install resolvconf from the official repositories by running the following commands.

$ sudo apt update $ sudo apt install resolvconf

Once the resolvconf installation is complete, the systemd will trigger the resolvconf.service to be automatically started and enabled. To check if it is up and running issues the following command.

$ sudo systemctl status resolvconf.service

If the service is not started and enabled automatically for any reason, you can start and enable it as follows.

$ sudo systemctl start resolvconf.service $ sudo systemctl enable resolvconf.service $ sudo systemctl status resolvconf.service
What is the main configuration file for DNS in Ubuntu?
Check Resolvconf Service Status

Set Permanent DNS Nameservers in Ubuntu and Debian

Next, open the /etc/resolvconf/resolv.conf.d/head configuration file.

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

and add the following lines in it:

nameserver 8.8.8.8 nameserver 8.8.4.4
What is the main configuration file for DNS in Ubuntu?
Set Permanent DNS Name Servers in Resolvconf

Save the changes and restart the resolvconf.service and systemd-resolved or reboot the system.

$ sudo systemctl restart resolvconf.service $ sudo systemctl restart systemd-resolved.service

Now when you check the /etc/resolv.conf file, the name server entries should be stored there permanently. Henceforth, you will not face any issues concerning name resolution on your system.

What is the main configuration file for DNS in Ubuntu?
Permanent DNS Name Servers

I hope this quick article helped you in setting the permanent DNS nameservers in your Ubuntu and Debian systems. If you have any queries or suggestions, do share them with us in the comments section below.

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

What is the main configuration file for DNS in Ubuntu?

We are thankful for your never ending support.

Domain Name System (DNS) is a system that associates human-readable domain names with IP addresses, allowing users to easily navigate the Internet or their own private network. DNS is important in private networks as it allows devices on the network to communicate with each other using names instead of IP addresses.

Setting up a proper Domain Name System (DNS) is an important part of managing server configuration and infrastructure, as it allows you to easily lookup network interfaces and IP addresses by name.

Configuring your network with fully qualified domain names instead of IP addresses makes it easier to set up and manage your services and applications. Setting up your own DNS server can make your network management even more efficient.

This article will help you install and configure your own DNS server on Ubuntu. The guide is applicable to older versions of Ubuntu and many other Linux distro based on Ubuntu, such as Linux Mint or Pop! OS.

Install DNS Server Software

BIND (Berkeley Internet Name Domain) is a comprehensive software suite that includes the world’s most widely used DNS (Domain Name System) server software. The most recent major version, BIND 9, was initially released in 2000 and is regularly maintained by the Internet Systems Consortium.

Bind9 is the package name for the DNS server on Ubuntu and is available in the base repository. Installing bind9 is one of the first thing you need to do in order to create your own DNS server. Run the following command to install bind9 and its dependencies.

sudo apt install -y bind9 bind9utils bind9-doc dnsutils

Configure DNS Server on Ubuntu

Bind9 stores its configuration files and zone lookup settings in /etc/bind/ directory. You should use the /etc/bind/named.conf.local file to store your local DNS zone information, rather than using the global /etc/bind/named.conf file.

DNS zones provide a specific scope for managing and defining DNS records.. Since our domains will all be within the linuxpip.local domain, we will use that as our forward zone. Run the following commands to edit zone configuration.

sudo nano /etc/bind/named.conf.local

We’ll need to put both forward zone and reverse zone in the files. The contents of the file should look similar to this.

zone "linuxpip.local" IN { type master; file "/etc/bind/forward.linuxpip.local.db"; allow-update { none; }; }; zone "0.168.192.in-addr.arpa" IN { type master; file "/etc/bind/reverse.linuxpip.local.db"; allow-update { none; }; };

Code language: JavaScript (javascript)

The first block is configuration for forward zone and the latter is reverse zone.

Create Zone lookup file

With zones created, you can then generate data files holding DNS records for the forward and reverse zones.

Forward Zone lookup file

Copy the sample entries to zone file called forward.linuxpip.local.db for the forward zone under /etc/bind directory.

Here’s a list of record types in the zone file:

SOA – Start of Authority NS – Name Server A – A record MX – Mail for Exchange CN – Canonical Name

Domain names should end with a dot (.). Run the following commands to update the zone file.

sudo cp /etc/bind/db.local /etc/bind/forward.linuxpip.local.db sudo nano /etc/bind/forward.linuxpip.local.db

Put the contents below in the file. You can edit the details to fit your scenario.

$TTL 604800 @ IN SOA ns1.linuxpip.local. root.linuxpip.local. ( 3 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; ;@ IN NS localhost. ;@ IN A 127.0.0.1 ;@ IN AAAA ::1 ;Name Server Information @ IN NS ns1.linuxpip.local. ;IP address of Name Server ns1 IN A 192.168.0.10 ;Mail Exchanger linuxpip.local. IN MX 10 mail.linuxpip.local. ;A – Record HostName To Ip Address www IN A 192.168.0.100 mail IN A 192.168.0.150 ;CNAME record ftp IN CNAME www.linuxpip.local.

Code language: PHP (php)

Reverse Zone lookup file

Copy the example entries to the reverse zone file called reverse.linuxpip.local.db, and create reverse pointers for the above forward zone records.

PTR – Pointer SOA – Start of Authority

sudo cp /etc/bind/db.127 /etc/bind/reverse.linuxpip.local.db sudo nano /etc/bind/reverse.linuxpip.local.db

Update the file with the content shown below.

$TTL 604800 @ IN SOA linuxpip.local. root.linuxpip.local. ( 3 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; ;@ IN NS localhost. ;1.0.0 IN PTR localhost. ;Name Server Information @ IN NS ns1.linuxpip.local. ;Reverse lookup for Name Server 10 IN PTR ns1.linuxpip.local. ;PTR Record IP address to HostName 100 IN PTR www.linuxpip.local. 150 IN PTR mail.linuxpip.local.

Code language: PHP (php)

Verify BIND Configuration

In order to check BIND configuration for syntax error, use named-checkconf command to check named.conf* files for any syntax errors.

Similarly, you can use a built-in command in BIND called named-checkzone to check for syntax errors in zone files.

Forward zone

sudo named-checkzone linuxpip.local /etc/bind/forward.linuxpip.local.db

Output:

zone linuxpip.local/IN: loaded serial 3 OK

Reverse zone

named-checkzone 0.168.192.in-addr.arpa /etc/bind/reverse.linuxpip.local.db

Output:

zone 0.168.192.in-addr.arpa/IN: loaded serial 3 OK

Run the following commands to restart bind9 service and enable it on system startup.

sudo systemctl restart bind9 sudo systemctl enable bind9

Check the status of the bind9 service using the following commands.

sudo systemctl status bind9

Whenever you change a DNS record, do not forget to change the serial number in the zone file and reload the zone.

Remember to replace linuxpip.local and 0.168.192.in-addr.arpa with your zone names.

**### Forward Zone ###** sudo rndc reload **linuxpip.local** **### Reverse Zone ###** sudo rndc reload **0.168.192.in-addr.arpa**

Code language: CSS (css)

Check DNS Server

The next step is to verify that our DNS server responds properly to imcoming requests. In order to do that, go to any client machine and add our new DNS server IP Address in /etc/resolv.conf file.

sudo nano /etc/resolv.conf

Add the line below to the very last line of the file.

Code language: CSS (css)

Then, use dig to perform a DNS lookup.

Code language: CSS (css)

You should see an output that looks like this if things go well.

; <<>> DiG 9.10.3-P4-Ubuntu <<>> www.linuxpip.local ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18022 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;www.linuxpip.local. IN A ;; ANSWER SECTION: www.linuxpip.local. 604800 IN A 192.168.0.100 ;; AUTHORITY SECTION: linuxpip.local. 604800 IN NS ns1.linuxpip.local. ;; ADDITIONAL SECTION: ns1.linuxpip.local. 604800 IN A 192.168.0.10 ;; Query time: 0 msec ;; SERVER: 127.0.1.1#53(127.0.1.1) ;; WHEN: Mon Dec 30 12:42:18 EST 2019 ;; MSG SIZE rcvd: 96

Code language: CSS (css)

Confirm the reverse lookup with dig command.

Code language: CSS (css)

; <<>> DiG 9.10.3-P4-Ubuntu <<>> -x 192.168.0.100 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37122 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;100.0.168.192.in-addr.arpa. IN PTR ;; ANSWER SECTION: 100.0.168.192.in-addr.arpa. 604800 IN PTR www.linuxpip.local. ;; AUTHORITY SECTION: 0.168.192.in-addr.arpa. 604800 IN NS ns1.linuxpip.local. ;; ADDITIONAL SECTION: ns1.linuxpip.local. 604800 IN A 192.168.0.10 ;; Query time: 0 msec ;; SERVER: 127.0.1.1#53(127.0.1.1) ;; WHEN: Mon Dec 30 12:43:20 EST 2019 ;; MSG SIZE rcvd: 120

Code language: CSS (css)

We hope that the article helps you successfully set up a DNS server in Ubuntu. You may be interested in our Linux software roundups, including 8 Best Open Source CMDB software, Best Linux Video Converters or Best Python Graphics Libraries. If you have any suggestion, please feel free to leave a comment below.