Aug 1, 2024 5 min read

How to Set DNS Nameservers on Ubuntu 24.04

Set DNS Nameservers on Ubuntu 24.04 with our step-by-step tutorial. DNS nameservers store domain and IP address details for website accessibility.

Set DNS Nameservers on Ubuntu 24.04
Set DNS Nameservers on Ubuntu 24.04
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to set DNS Nameservers on Ubuntu 24.04, let's briefly understand – What are DNS Nameservers?

Domain Name System (DNS) nameservers are servers that store DNS records, containing information about domain names and their corresponding IP addresses. These servers play a vital role in translating domain names into IP addresses, allowing users to access websites easily.

Nameservers help in directing internet traffic to the correct server hosting a website. By configuring nameservers properly, website owners ensure that users can reach their websites reliably. Understanding and managing nameservers is crucial for maintaining online presence and accessibility of websites.

In this tutorial, you will set DNS Nameservers on Ubuntu 24.04. We will also address a few FAQs on how to set DNS Nameservers on Ubuntu 24.04.

Method 1: How to Set DNS Nameserver Using CLI

Users can take the following actions to configure the DNS name servers on Ubuntu 24.04 using the command line:

Configure resolv.conf file

With the sudo privileges, open the /etc/resolv.conf file in a nano text editor:

sudo nano /etc/resolv.conf

For each DNS name server you plan on using, add a line to the file. The nameserver with the IP address should be the first thing on the line:

nameserver 8.8.8.8
nameserver 8.8.4.4

Save the file, then close the text editor.

Verify the DNS Nameservers

To verify the DNS Nameserver, run the script following with the sudo privilege:

sudo resolvectl status

The output verifies that DNS nameservers 8.8.8.8 and 8.8.4.4 have been configured.

Alternative Method: Configure 01-network-manager-all.yaml File Via netplan

A tool for configuring networking on Linux systems is called Netplan. You can select which DNS nameservers should be used by your system to resolve hostnames.

You must modify the Netplan configuration file for your network interface in order to set the DNS nameservers. The configuration file has a .yaml file format and is typically found in /etc/netplan/.

sudo nano /etc/netplan/01-network-manager-all.yaml

Below is an example of how the DNS nameservers can be set in a Netplan configuration file. The following is a description of the script:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: no
      addresses: [192.168.157.140/24]
      gateway4: 192.168.157.140
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]

The nameservers part of this example states that the system should resolve hostnames using Google's public DNS servers (8.8.8.8 and 8.8.4.4). Also, the machine has the IP address 192.168.157.140 and the subnet mask 24. 192.168.157.140 is the gateway via which traffic flows.

After making modifications to the configuration file, execute the following command to put the changes into effect:

sudo netplan apply

By doing this, you will be able to use the nameservers listed in the configuration file and update the system's DNS settings.

Let us look at the same method in the GUI.

Method 2: How to Set DNS Nameserver Using GUI

Domain names that can be supplied in the network configuration files are resolved by Ubuntu's DNS name servers. Using an Ubuntu GUI, these configuration files can be changed as shown below:

Step 1: Open the Network Settings Window

Click the Network icon in the top right corner of the desktop screen, then select Wired Settings:

Step 2: Edit Connection

It goes on to the Settings window's Network section. For the connection you want to configure DNS nameservers for, click the Edit button:

Step 3: Check the Automatic (DHCP)

See if Automatic (DHCP) addresses is enabled or disabled under the IPv4 Settings tab. If not, pick this one:

Step 4: Enter the IP Addresses of DNS

In the DNS Servers field, type the DNS nameservers' IP addresses. After that, click Apply to save the address:

FAQs on How to Set DNS Nameserver on Ubuntu 24.04

How do I check the current DNS settings on Ubuntu 24.04?

You can check the current DNS settings by running the command cat /etc/resolv.conf. This will display the current DNS nameservers configured on your system.

What are some popular DNS services I can use?

Some popular DNS services include Google Public DNS (8.8.8.8 and 8.8.4.4), Cloudflare DNS (1.1.1.1 and 1.0.0.1), and OpenDNS (208.67.222.222 and 208.67.220.220).

Can I set multiple DNS nameservers on Ubuntu 24.04?

Yes, you can set multiple DNS nameservers on Ubuntu 24.04 by adding multiple nameserver lines in the /etc/resolv.conf file.

How do I verify that the DNS changes have been applied successfully?

To verify that the DNS changes have been applied successfully, you can use the dig command to perform a DNS lookup. For example, dig www.example.com will show the IP address resolved by the configured DNS servers.

Can I use a different DNS configuration tool instead of editing the /etc/resolv.conf file?

Yes, you can use a different DNS configuration tool instead of manually editing the /etc/resolv.conf file. Ubuntu 24.04 supports the use of the systemd-resolved service, which provides a more robust and managed way of configuring DNS settings.

How do I configure DNS settings using systemd-resolved on Ubuntu 24.04?

To configure DNS settings using systemd-resolved on Ubuntu 24.04, you can edit the /etc/systemd/resolved.conf file and add the desired DNS server addresses under the [Resolve] section. Then, restart the systemd-resolved service using the command sudo systemctl restart systemd-resolved.

Do I need to restart my system after changing the DNS nameservers on Ubuntu 24.04?

No, you don't need to restart your system. After making changes to the nameservers configuration, you can simply run the sudo netplan apply command to apply the new settings.

Conclusion

We hope this detailed tutorial helped you understand how to set DNS Nameservers on Ubuntu 24.04.

If you have any suggestions or queries, kindly leave them in the comments section.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.