How To

Set DNS Nameservers on Ubuntu 18.04: Desktop and Server Guide

DNS (Domain Name System) is what translates domain names into IP addresses. When you type a website address into your browser, your operating system first checks its local hosts file for a matching entry. If it finds nothing, it queries the configured DNS nameservers to resolve the domain.

By default, DNS resolvers are assigned automatically by your ISP. These resolvers are often slow, poorly maintained, or in some cases used to log browsing activity. Switching to a faster, privacy-focused public DNS server can improve response times and reliability.

The most popular public DNS resolvers are:

  • Google: 8.8.8.8 and 8.8.4.4
  • Cloudflare: 1.1.1.1 and 1.0.0.1
  • OpenDNS: 208.67.222.222 and 208.67.220.220
  • Level3: 209.244.0.3 and 209.244.0.4

Router tip: If you want every device on your local network to use the same DNS servers, make the change on your home router instead of configuring each device separately.

Set DNS Nameservers on Ubuntu Desktop

On Ubuntu 18.04 Desktop, you configure DNS through the Network Manager graphical interface. No terminal required.

Open Settings and click the Wi-Fi tab if you are on a wireless connection, or the Network tab for a wired connection.

Find your active connection and click the cog icon to open its settings. Go to the IPv4 tab.

Disable the Automatic toggle next to DNS. Enter your preferred DNS server addresses separated by a comma — for example, 8.8.8.8, 8.8.4.4 for Google DNS or 1.1.1.1, 1.0.0.1 for Cloudflare.

Click Apply to save the changes. The new DNS settings take effect immediately, though entries already cached by the system or an application may continue using the old resolver until the cache expires.

To revert to your ISP’s default DNS, open Network Manager, go back to the IPv4 tab, and re-enable the Automatic toggle. Your system will start using your ISP’s resolvers right away.

Set DNS Nameservers on Ubuntu Server via Netplan

On Ubuntu 18.04 Server, the /etc/resolv.conf file is no longer edited directly. It is a symlink managed by the systemd-resolved service. The correct way to configure DNS is through Netplan, the default network management tool on Ubuntu 18.04.

Netplan stores its configuration as YAML files in /etc/netplan/. Common filenames are 01-netcfg.yaml and 50-cloud-init.yaml. Open your configuration file:

bashsudo nano /etc/netplan/01-netcfg.yaml

A typical file looks like this:

yamlnetwork:  version: 2  renderer: networkd  ethernets:    ens3:      dhcp4: no      addresses:        - 192.168.121.199/24      gateway4: 192.168.121.1      nameservers:          addresses: [8.8.8.8, 8.8.4.4]

Change the addresses values under nameservers to your preferred DNS servers. For Cloudflare:

yaml      nameservers:          addresses: [1.1.1.1, 1.0.0.1]

If the nameservers block does not exist in your file, add it under the interface name block. Pay close attention to indentation — YAML is whitespace-sensitive, and a misaligned line will cause Netplan to fail when you apply the configuration.

Apply the changes:

bashsudo netplan apply

Netplan generates the configuration for the systemd-resolved service automatically. Verify the new DNS servers are active:

bashsystemd-resolve --status | grep 'DNS Servers' -A2

Output:

         DNS Servers: 1.1.1.1                      1.0.0.1

Changing your DNS nameservers on Ubuntu 18.04 takes just a few minutes on both the desktop and the server. Whether you switch for better speed, privacy, or reliability, Cloudflare and Google DNS are solid starting points. Leave a comment below if you run into any issues.

Cyber Defence

Recent Posts

Enable SSH on Ubuntu 18.04: Install, Connect, and Manage

SSH (Secure Shell) is a cryptographic network protocol that creates a secure, encrypted connection between your…

12 minutes ago

Install Node.js and npm on Ubuntu 18.04: Three Methods Compared

Node.js is an open-source, cross-platform JavaScript runtime that lets you run JavaScript on the server side,…

18 minutes ago

Install Docker on Ubuntu 18.04: Setup, Images, and Containers

Docker is a containerization platform that lets you package applications and their dependencies into lightweight, portable…

52 minutes ago

Install Yarn on Ubuntu 18.04: APT Setup and Essential Commands

Yarn is a fast, reliable JavaScript package manager that works alongside npm. It was built to fix…

57 minutes ago

Install Webmin on Ubuntu 18.04: Web Control Panel Setup Guide

Webmin is an open-source, browser-based control panel for Linux server administration. Instead of managing your server…

1 day ago

Install Go on Ubuntu 18.04: Tarball Setup and Hello World Guide

Go (also called Golang) is a modern, statically typed programming language created at Google. It is…

1 day ago