Ubuntu DNS Settings Guide (22.04/24.04): Check, Change, and Fix Name Resolution

目次

1. Introduction

When you use the internet on Ubuntu, you may suddenly run into issues like “websites won’t load,” “apt update fails,” or “internal server hostnames can’t be resolved.”
One surprisingly common cause is DNS (name resolution) configuration.

In simple terms, DNS is the system that converts a domain name (for example, google.com) into an IP address.
If DNS isn’t working correctly, you can still be connected to the network, yet you won’t be able to access websites or servers.

In this article, following the main keyword “ubuntu dns settings”, we’ll clearly organize and explain how to check and change DNS settings on Ubuntu in a beginner-friendly way.

1.1 What You’ll Learn in This Article

By the end of this article, you’ll be able to do the following:

  • Check your current DNS settings on Ubuntu
  • Change DNS settings on Ubuntu Desktop (GUI)
  • Configure DNS persistently on Ubuntu Server (CLI)
  • Understand the relationship between systemd-resolved and /etc/resolv.conf
  • Troubleshoot cases where DNS changes don’t apply or name resolution fails

1.2 Who This Article Is For

This content is a good fit for people like the following:

  • You’re new to Ubuntu and the term “DNS” is still a bit unclear
  • You run Ubuntu Server on a VPS or a home server
  • Your network is connected, but the web and updates aren’t working
  • You want to pin DNS (use Google DNS / Cloudflare DNS, etc.)

1.3 Ubuntu DNS Settings Can Be Confusing: “Where Should You Change It?”

Ubuntu DNS settings often feel difficult because there isn’t just one place where you “enter DNS.”

Depending on your environment, Ubuntu may manage DNS in different ways:

  • Ubuntu Desktop: Often configured via the GUI (Network Settings)
  • Ubuntu Server: Often managed via Netplan (configuration files)
  • Common component: systemd-resolved may manage name resolution behind the scenes

Also, /etc/resolv.conf—frequently referenced in networking guides—may behave differently depending on your Ubuntu setup, and in some cases editing it directly won’t take effect.

If you don’t know this, you can easily end up in situations like:

  • You changed settings, but nothing improves
  • It worked—then reverted after a reboot
  • You don’t know which article’s instructions to trust

In this article, to avoid that confusion, we’ll organize Ubuntu DNS settings systematically and explain them clearly.

1.4 Supported Ubuntu Versions

This article mainly assumes the following commonly used Ubuntu versions:

  • Ubuntu 22.04 LTS
  • Ubuntu 24.04 LTS

However, the core DNS concepts and verification methods are largely the same across other versions.
Only small details (such as Netplan file names) may differ.

2. DNS Basics (Key Terms)

To configure DNS correctly on Ubuntu, it helps to understand—at a high level—what DNS does and where it’s managed.
Here, we’ll keep it beginner-friendly and focus only on the essentials.

2.1 What Is DNS? (A Quick Explanation Is Enough)

DNS (Domain Name System) is a mechanism that converts domain names into IP addresses.

For example, you might access the following in your browser:

  • https://www.google.com

But computers typically communicate using IP addresses.

  • A numeric “address” like 142.250.xxx.xxx

So DNS works behind the scenes to do a conversion like this:

  • www.google.com142.250.xxx.xxx

This conversion is called name resolution, and it allows your system to connect to the correct server.

In other words, DNS is like the internet’s “phonebook” or “address book.”

2.2 When DNS Settings Matter

DNS configuration becomes especially important on Ubuntu in cases like these:

  • Websites won’t load (but Wi-Fi/LAN is connected)
  • apt update or snap updates fail
  • Name resolution fails in Docker or Kubernetes environments
  • Internal hostnames (e.g., intra-server.local) can’t be resolved
  • Only during VPN connections, certain domains can’t be resolved
  • You want to use ad-blocking DNS or faster DNS

Since DNS is close to the “core” of whether networking works, it shows up constantly in troubleshooting.

2.3 What Is a DNS Server? (Where Are You Asking?)

DNS conversion isn’t something your PC calculates by itself.
Typically, it queries a DNS server and receives the result.

When Ubuntu performs name resolution, it generally follows this flow:

  1. Ubuntu queries a DNS server
  2. The DNS server replies: “This domain maps to this IP”
  3. Ubuntu connects to that IP

DNS servers commonly come from places like:

  • Your router (a home Wi-Fi router hands out DNS)
  • Company/internal DNS servers
  • Public DNS (Google DNS / Cloudflare DNS, etc.)

Here are well-known public DNS options:

  • Google Public DNS: 8.8.8.8 / 8.8.4.4
  • Cloudflare DNS: 1.1.1.1 / 1.0.0.1

There’s no single “correct” choice—what matters is choosing what fits your environment and goals.

2.4 Why DNS Settings Are a Bit Tricky on Ubuntu

On Windows and some other OSes, the place to change DNS is relatively straightforward.
On Ubuntu, however, the setup can vary, such as:

  • Managed via GUI (NetworkManager)
  • Managed via Netplan
  • systemd-resolved centralizes DNS processing
  • /etc/resolv.conf may be a link rather than the “real” file

As a result, when you read online guides, you may see conflicting advice like:

  • “Just edit /etc/resolv.conf
  • “No—you must configure Netplan”
  • “You should change systemd-resolved settings”

It’s easy to get confused.

But don’t worry.
It’s not that “everything is wrong”—it’s simply that the correct procedure depends on your Ubuntu configuration.

This article will also explain how to identify which approach applies to your setup.

2.5 Key Files and Components You’ll See in Ubuntu DNS Management

Let’s quickly define the terms that commonly appear in DNS configuration guides.

2.5.1 What Is /etc/resolv.conf?

/etc/resolv.conf is the traditional DNS configuration file used in Linux for a long time.

Its contents typically look like this:

nameserver 8.8.8.8
nameserver 1.1.1.1

However, on Ubuntu, this file is not always used directly.

On modern Ubuntu, /etc/resolv.conf is often a symbolic link that points to another file, such as:

  • A file auto-generated by systemd-resolved
  • A file generated by NetworkManager

That’s why direct edits can get overwritten.

2.5.2 What Is systemd-resolved?

systemd-resolved is a service that manages DNS name resolution on Ubuntu.

Key characteristics include:

  • Makes it easier to centralize DNS configuration
  • Provides DNS caching
  • Can handle multiple interfaces (Wi-Fi and VPN, etc.)

Depending on your environment, this can be the practical “center” of DNS configuration.

2.5.3 What Is Netplan?

Netplan is a network configuration system commonly used on Ubuntu Server.
You define network settings using YAML files.

DNS can also be included in Netplan configuration, along with:

  • IP address
  • Gateway
  • DNS servers

Since you can manage everything together, it’s a standard approach for server use.

2.6 The Most Important Thing When Changing DNS: Persistence

When setting DNS on Ubuntu, the most important point—especially on servers—is:

  • Will the setting survive a reboot? (Persistence)

You can sometimes change DNS temporarily, but it may revert when:

  • You reboot
  • You reconnect the network
  • DHCP renews
  • A VPN disconnects

In this article, we’ll focus not on “quick fixes,” but on how to persist DNS settings correctly based on your goal.

3. How to Check Current DNS Settings on Ubuntu

Before changing DNS settings, you should first confirm what Ubuntu is currently using.
If you skip this step, you may end up changing the wrong place and nothing will improve.

In this section, we’ll go through reliable ways to check DNS settings on Ubuntu, including both Desktop and Server environments.

3.1 Check DNS with resolvectl (Recommended)

If your Ubuntu uses systemd-resolved, the most accurate way to check DNS is resolvectl.

Run this command:

resolvectl status

You’ll see information like:

  • DNS servers currently used
  • Which interface (Wi-Fi / Ethernet / VPN) is providing DNS
  • Search domains (if configured)

If the output shows a DNS server you didn’t expect (such as your router IP), that might explain slow or unstable name resolution.

3.2 Check /etc/resolv.conf (But Be Careful)

Many guides mention checking /etc/resolv.conf because it historically contains DNS settings.

You can check it with:

cat /etc/resolv.conf

Typical output might look like:

nameserver 127.0.0.53
options edns0 trust-ad
search example.local

If you see 127.0.0.53, it usually means Ubuntu is using systemd-resolved and /etc/resolv.conf is pointing to a local stub resolver.

In that case, the “real” DNS servers are better confirmed using resolvectl status.

3.3 Confirm Whether /etc/resolv.conf Is a Symlink

On Ubuntu, /etc/resolv.conf is often a symbolic link (symlink).
If so, direct edits may not persist.

Check it using:

ls -l /etc/resolv.conf

If you see something like this, it’s a symlink:

/etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf

This is normal on modern Ubuntu, and it means DNS is managed through system services rather than by editing this file directly.

3.4 Check DNS via NetworkManager (Desktop Users)

If you are using Ubuntu Desktop, DNS is often managed by NetworkManager.
You can check your active connection settings with this command:

nmcli dev show

Look for lines like:

  • IP4.DNS[1]
  • IP4.DNS[2]

This shows the DNS servers NetworkManager is currently using for your connection.

3.5 Quick DNS Function Test (Does Name Resolution Work?)

Even if your DNS servers are configured, name resolution might still fail due to network or firewall issues.
So it’s helpful to run a simple test.

Try this:

ping -c 1 google.com

If it resolves and pings successfully, DNS is likely working.

If you get an error like:

ping: google.com: Temporary failure in name resolution

That strongly suggests DNS is failing.

To confirm the network itself works, you can also ping a public IP address directly:

ping -c 1 1.1.1.1

If pinging the IP works but domain names fail, the issue is almost certainly DNS-related.

4. How to Change DNS Settings on Ubuntu Desktop (GUI Method)

If you’re using Ubuntu Desktop, the easiest and safest way to change DNS settings is through the GUI network settings.
This method is beginner-friendly and the settings persist across reboots.

4.1 Change DNS on Ubuntu Desktop (Wi-Fi)

Follow these steps to change DNS for a Wi-Fi connection:

  1. Open Settings
  2. Go to Network (or Wi-Fi)
  3. Select your connected Wi-Fi network
  4. Click the gear icon (connection settings)
  5. Open the IPv4 tab
  6. Find DNS and switch from Automatic to Manual
  7. Enter your preferred DNS servers
  8. Save the settings

Example DNS servers you can enter:

  • Cloudflare: 1.1.1.1, 1.0.0.1
  • Google: 8.8.8.8, 8.8.4.4

After saving, disconnect and reconnect to Wi-Fi, or toggle Wi-Fi off and on, to ensure the change applies.

4.2 Change DNS on Ubuntu Desktop (Wired Ethernet)

For wired connections, the steps are almost the same:

  1. Open Settings
  2. Go to Network
  3. Under Wired, click the gear icon
  4. Open the IPv4 tab
  5. Switch DNS from Automatic to Manual
  6. Enter the DNS servers
  7. Save

This is a stable approach for desktops, especially when you want consistent DNS behavior for development work or remote access.

4.3 IPv6 DNS Settings (Optional)

If your environment uses IPv6, you may also want to configure DNS under the IPv6 tab.

Example IPv6 DNS servers:

  • Cloudflare IPv6: 2606:4700:4700::1111 / 2606:4700:4700::1001
  • Google IPv6: 2001:4860:4860::8888 / 2001:4860:4860::8844

If you don’t use IPv6 or you’re unsure, it’s fine to leave IPv6 DNS as automatic.

4.4 Verify the Change Worked

After changing DNS via GUI, verify it using:

resolvectl status

Or if you prefer NetworkManager output:

nmcli dev show | grep DNS

Then test name resolution again:

ping -c 1 google.com

If it works, your DNS settings are successfully applied.

4.5 Common Mistake: “It Still Uses the Router DNS”

Sometimes, even after setting DNS manually, you may still see your router IP as the DNS server.

This can happen if:

  • The connection didn’t reconnect properly
  • Another network profile is active
  • A VPN is overriding DNS settings

In those cases, try disconnecting and reconnecting, or temporarily disabling VPN, then check again using resolvectl status.

5. How to Change DNS Settings on Ubuntu Server (Netplan Method)

On Ubuntu Server, DNS configuration is commonly managed through Netplan.
This method is different from Ubuntu Desktop, because you typically edit a YAML file and apply the configuration.

In this section, you’ll learn how to safely update DNS settings using Netplan, including how to avoid common YAML mistakes.

5.1 Confirm Your Network Interface Name

First, confirm the name of your network interface.
On servers, interface names often look like ens3, ens160, enp0s3, etc.

Use this command:

ip link

Look for an interface that is “UP” and is used for your active connection.

5.2 Find Your Netplan Config File

Netplan configuration files are usually located under /etc/netplan/.

List them with:

ls /etc/netplan/

You may see files like:

00-installer-config.yaml
01-netcfg.yaml

There is usually one main YAML file. That’s the one you’ll edit.

5.3 Edit Netplan YAML to Set DNS Servers

Open the file with an editor such as nano:

sudo nano /etc/netplan/00-installer-config.yaml

Below is a typical example for a server using DHCP, where we manually set DNS servers:

network:
  version: 2
  ethernets:
    ens3:
      dhcp4: true
      nameservers:
        addresses:
          - 1.1.1.1
          - 1.0.0.1

Key points:

  • nameservers must be aligned correctly (YAML indentation matters).
  • addresses is a list, so use - for each DNS server.

If your server uses a static IP, the DNS configuration will be placed alongside the static address configuration. Example:

network:
  version: 2
  ethernets:
    ens3:
      dhcp4: false
      addresses:
        - 192.168.1.50/24
      gateway4: 192.168.1.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4

This setup is common for servers that need predictable networking.

5.4 Apply Netplan Changes Safely

After editing the YAML, apply the configuration.

Recommended safest approach:

sudo netplan try

netplan try temporarily applies changes and asks for confirmation.
If you lose network connectivity (e.g., SSH drops), the changes should revert automatically after a timeout.

If everything is fine, you can apply permanently:

sudo netplan apply

5.5 Verify DNS Settings on Server

Check current DNS with:

resolvectl status

Then verify name resolution works:

ping -c 1 google.com

If it resolves successfully, DNS configuration is working.

5.6 Common Netplan Errors and How to Avoid Them

Netplan YAML is strict. Many problems happen due to indentation or syntax mistakes.

Indentation Mistakes

YAML uses spaces, not tabs. A single wrong indentation level can break everything.

Wrong Interface Name

If you configure ens3 but your actual interface is ens160, your DNS changes won’t apply.

Forgot to Apply the Config

If you edit the file but don’t run netplan apply, nothing changes.

6. Recommended Public DNS Providers (Which Should You Choose?)

Choosing a DNS provider affects speed, stability, privacy, and reliability.
Here are common public DNS services that many people use on Ubuntu.

6.1 Cloudflare DNS (Fast and Popular)

Cloudflare DNS is known for speed and strong global infrastructure.

  • IPv4: 1.1.1.1 / 1.0.0.1
  • IPv6: 2606:4700:4700::1111 / 2606:4700:4700::1001

6.2 Google Public DNS (Stable and Widely Used)

Google DNS is extremely well-known and tends to be stable, especially for troubleshooting.

  • IPv4: 8.8.8.8 / 8.8.4.4
  • IPv6: 2001:4860:4860::8888 / 2001:4860:4860::8844

6.3 Quad9 (Security-Focused)

Quad9 is often chosen by users who want malware-blocking and security-focused DNS resolution.

  • IPv4: 9.9.9.9 / 149.112.112.112
  • IPv6: 2620:fe::fe / 2620:fe::9

6.4 Which DNS Should You Pick?

There is no single best choice for everyone, but here’s a simple guideline:

  • Speed-first: Cloudflare
  • Stability/troubleshooting: Google DNS
  • Security-focused: Quad9

If you’re unsure, start with Cloudflare or Google DNS and see if your browsing and updates become more stable.

7. Troubleshooting: DNS Changes Don’t Apply or Name Resolution Still Fails

You changed Ubuntu DNS settings, but it still doesn’t work.
This situation is common, and the cause is often something simple like cache, conflicting settings, or VPN overrides.

In this section, we’ll go through practical troubleshooting steps that work well on Ubuntu 22.04/24.04.

7.1 First Check: Can You Ping an IP Address?

Before focusing only on DNS, confirm whether the network itself works.

Try pinging a public IP:

ping -c 1 1.1.1.1

If this works, your network connection is likely fine.

Next, test a domain name:

ping -c 1 google.com

If pinging the IP works but the domain fails, it strongly suggests a DNS issue.

7.2 Check Which DNS Is Actually Being Used

Sometimes you set DNS, but Ubuntu is still using a different DNS server due to DHCP, VPN, or another interface.

Check the active DNS servers with:

resolvectl status

Look for:

  • Which interface is “Current DNS Server”
  • Whether the DNS servers match what you configured

If you still see your router IP (for example 192.168.1.1), your manual DNS might not be applied properly.

7.3 Flush DNS Cache (systemd-resolved)

Ubuntu may cache DNS results. Even after changing DNS, old cached results can remain.

Flush the cache with:

sudo resolvectl flush-caches

Then test again:

ping -c 1 google.com

7.4 Restart Name Resolution Services

If cache flush isn’t enough, restarting the resolver service can help.

Restart systemd-resolved:

sudo systemctl restart systemd-resolved

If you are on Ubuntu Desktop, you may also restart NetworkManager:

sudo systemctl restart NetworkManager

Then check DNS again using:

resolvectl status

7.5 DNS Overwritten by DHCP (Router Settings)

In many home networks, DHCP from the router automatically assigns DNS settings.

Even if you set DNS manually, it may be overwritten if your connection is still configured as “Automatic.”

To fix this:

  • On Desktop: ensure DNS is set to Manual in the GUI
  • On Server: ensure DNS is defined under nameservers in Netplan

7.6 VPN or Corporate Network Overrides DNS

VPN software often changes DNS automatically to route name resolution through the VPN tunnel.

Common symptoms include:

  • Only internal domains resolve while VPN is connected
  • Public websites stop working after connecting VPN
  • DNS servers change when VPN is enabled

To confirm, compare DNS before and after connecting VPN:

resolvectl status

 

If DNS changes unexpectedly, the VPN is likely overriding it.

In such cases, you may need to configure DNS settings inside the VPN client, or adjust split-DNS settings depending on your VPN setup.

7.7 Directly Test DNS with dig or nslookup

Sometimes ping is not enough. It’s useful to query DNS directly.

If dig is available:

dig google.com

If dig is not installed, you can install it with:

sudo apt update
sudo apt install -y dnsutils

You can also use nslookup:

nslookup google.com

If the DNS query times out, that usually means your configured DNS server is unreachable or blocked.

7.8 Firewall or Network Restrictions Blocking DNS

DNS typically uses port 53 (UDP and sometimes TCP).
Some networks block external DNS to force you to use their own DNS server.

In that case, using public DNS like 1.1.1.1 may not work, and you may need to use the DNS provided by the network.

This is especially common on:

  • Corporate Wi-Fi
  • Hotel networks
  • Public networks

8. Advanced: Understanding /etc/resolv.conf and systemd-resolved

If you search “ubuntu dns settings,” you will often see /etc/resolv.conf mentioned.
However, on modern Ubuntu, this file may not behave the way older Linux tutorials describe.

Here’s the key idea:

  • /etc/resolv.conf is often auto-generated
  • Ubuntu often uses systemd-resolved to manage DNS

8.1 Why Editing /etc/resolv.conf Directly Often Fails

On many Ubuntu systems, /etc/resolv.conf is a symlink to a file managed by system services.

Confirm the symlink:

ls -l /etc/resolv.conf

If you see something like:

/etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf

Then manual edits are not persistent, because the file is regenerated automatically.

8.2 The Meaning of 127.0.0.53

If your /etc/resolv.conf contains:

nameserver 127.0.0.53

This does not mean “your DNS server is broken.”

It usually means:

  • Ubuntu is using a local stub resolver
  • systemd-resolved is handling DNS queries internally

The actual upstream DNS servers are configured elsewhere and can be checked using:

resolvectl status

8.3 When You Might Need to Configure systemd-resolved Directly

In most cases, you don’t need to edit systemd-resolved configuration manually.
Desktop users should use GUI settings, and server users should use Netplan.

However, in special cases you may consider it, such as:

  • You want system-wide fallback DNS regardless of DHCP
  • You want to configure DNS behavior for multiple interfaces
  • You are troubleshooting complex VPN split-DNS issues

In the next section, we’ll show how to set fallback DNS using systemd-resolved in a safe way.

9. Optional: Set Fallback DNS with systemd-resolved (Advanced)

This section is optional and intended for users who want deeper control over DNS behavior on Ubuntu.

In many cases, you should configure DNS through:

  • Ubuntu Desktop: GUI (Network Settings)
  • Ubuntu Server: Netplan YAML

However, there are situations where you may want to define Fallback DNS so Ubuntu can still resolve names even if the primary DNS becomes unavailable.

9.1 What Is “Fallback DNS”?

Fallback DNS is a backup DNS server that Ubuntu can use if the current DNS configuration fails.

For example, if your network-provided DNS server (router or corporate DNS) becomes unstable, fallback DNS can prevent total name resolution failure.

9.2 Check Current systemd-resolved Settings

First, check whether systemd-resolved is active:

systemctl status systemd-resolved

If it’s running, you can proceed.

9.3 Edit /etc/systemd/resolved.conf

The main configuration file is:

/etc/systemd/resolved.conf

Open it with nano:

sudo nano /etc/systemd/resolved.conf

Inside, you may see commented lines like this:

#DNS=
#FallbackDNS=

To set fallback DNS, add or modify lines like:

[Resolve]
FallbackDNS=1.1.1.1 1.0.0.1
DNS=

Notes:

  • FallbackDNS can include multiple servers separated by spaces.
  • You can leave DNS= empty if you only want fallback behavior.
  • If you set DNS=, it may override per-interface DNS in some setups, so be careful.

9.4 Restart systemd-resolved

After editing the file, restart the service:

sudo systemctl restart systemd-resolved

9.5 Confirm Fallback DNS Is Recognized

Check the current resolver status:

resolvectl status

If configured correctly, you should see the fallback DNS listed in the output.

10. Frequently Asked Questions (FAQ)

10.1 Is It Safe to Use Google DNS or Cloudflare DNS on Ubuntu?

Yes, it’s generally safe, and many users use them for speed and stability.

However, DNS is part of your network privacy and routing behavior, so the “best” choice depends on your preferences and environment.

10.2 Why Does My DNS Setting Revert After Reboot?

This usually happens when DNS was changed temporarily (for example, editing /etc/resolv.conf directly) instead of using the correct persistent method.

For persistent DNS configuration:

  • Ubuntu Desktop: configure DNS in GUI settings
  • Ubuntu Server: configure DNS in Netplan YAML

10.3 Why Does /etc/resolv.conf Show 127.0.0.53?

This is normal on modern Ubuntu and means Ubuntu is using a local stub resolver via systemd-resolved.

To see the actual upstream DNS servers, use:

resolvectl status

10.4 My DNS Works in Browser but apt update Fails. Why?

This can happen due to proxy settings, firewall rules, or temporary DNS resolution problems affecting specific domains.

Try testing DNS resolution for Ubuntu repositories:

nslookup archive.ubuntu.com

If name resolution fails for repository domains, adjusting DNS servers may help.

10.5 Should I Disable IPv6 If DNS Feels Unstable?

Not necessarily. IPv6 is widely used and often works fine.

However, if your network has partial IPv6 support, it can cause delays.
A safer approach is to set IPv4 DNS correctly and verify performance first.

11. Summary

Ubuntu DNS settings can feel confusing because multiple systems may be involved, such as Netplan, NetworkManager, and systemd-resolved.

But once you understand the correct workflow, troubleshooting becomes much easier.

11.1 Quick Checklist

  • Check DNS with resolvectl status
  • Desktop users: change DNS via GUI network settings
  • Server users: set DNS via Netplan YAML and apply changes
  • Don’t rely on editing /etc/resolv.conf directly
  • Flush caches and restart services if changes don’t apply

If you follow these steps, you’ll be able to solve most “Ubuntu can’t open websites” or “DNS not working” problems quickly.

DNS issues can be frustrating, but the upside is that they are usually fixable with a consistent troubleshooting process.