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

Kali Linux Commands Cheat Sheet: Complete Quick Reference

This cheat sheet covers the essential Kali Linux commands every pentester and ethical hacker uses…

13 hours ago

What I Wish I Knew Before Learning Malware Analysis and Reverse Engineering

When I first started learning malware analysis and reverse engineering, I thought the hardest part…

5 days ago

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

2 weeks ago

git cherry-pick Command: Apply Commits from Another Branch

Sometimes the change you need already exists, just on the wrong branch. A hotfix lands…

2 weeks ago

Best Email APIs for Secure Business Email: Why Developers Are Moving Beyond SMTP

Email is still one of the most important communication channels inside modern applications. Password resets,…

2 weeks ago

Nginx Commands in Linux: Start, Stop, Reload, Test, and Log

Nginx is a high-performance web server and reverse proxy trusted by some of the largest…

3 weeks ago