Skip to main content
To change the DNS server on Linux, change it where your network tool stores it rather than editing /etc/resolv.conf by hand. On Ubuntu, set nameservers: addresses: [1.1.1.1, 9.9.9.9] in your Netplan file and run sudo netplan apply; systemd-resolved then uses them. On AlmaLinux/Rocky, run sudo nmcli connection modify "System eth0" ipv4.dns "1.1.1.1 9.9.9.9" ipv4.ignore-auto-dns yes. Check with resolvectl status or cat /etc/resolv.conf.

Before you start

  • A DNS resolver turns names like example.com into IP addresses. Your server asks the resolvers listed in its network settings.
  • On a VPS you can also pick resolvers in the panel: see change your VPS’s DNS resolvers. Whether the panel setting reaches the server depends on how its network is configured; the steps below change it inside the server.
  • Commands use sudo; as root, leave it out.

Which method applies to my server?

On Ubuntu, /etc/resolv.conf lists nameserver 127.0.0.53. That’s systemd-resolved’s local stub, which forwards queries to your real resolvers. Don’t replace it.

How to change the DNS server

1

Edit the Netplan file

Set the resolvers under your interface:
use-dns: false stops DHCP from adding its own resolvers. With a static setup (dhcp4: false), you only need nameservers.
2

Apply

Press Enter to keep the change.
3

Check

DNS Servers should list 1.1.1.1 9.9.9.9.
To try a resolver without changing files (lost at reboot or next network change), use sudo resolvectl dns eth0 1.1.1.1 9.9.9.9, and undo it with sudo resolvectl revert eth0.
Don’t delete the /etc/resolv.conf symlink or replace it with a static file on Ubuntu unless you also disable systemd-resolved. Otherwise name resolution breaks, and the server can’t install updates or reach APIs by name.

How to set DNS for the whole system with systemd-resolved

To use the same resolvers on every interface, create a drop-in file. Files in /etc/systemd/resolved.conf.d/ override the main file:
Per-interface resolvers (from Netplan or DHCP) are still used alongside these. To use only the global servers, remove the interface resolvers as shown in the Ubuntu tab.

How to check it worked

dig also shows which server answered: run dig example.com and look at the SERVER: line. Install it with sudo apt install bind9-dnsutils (Ubuntu/Debian) or sudo dnf install bind-utils (AlmaLinux/Rocky).

Frequently asked questions

Why does my change to /etc/resolv.conf disappear?

A tool regenerates the file: systemd-resolved, NetworkManager, cloud-init or DHCP. Change DNS in that tool instead, as shown above.

What is 127.0.0.53 in resolv.conf?

The local systemd-resolved stub resolver. Programs ask it, and it forwards to the resolvers you configured. See them with resolvectl status.

How do I clear the DNS cache on Linux?

On systemd-resolved, run sudo resolvectl flush-caches. Other setups usually don’t cache locally unless you run a caching service such as nscd or dnsmasq.

Which public DNS servers should I use?

Common choices are Cloudflare (1.1.1.1, 1.0.0.1), Quad9 (9.9.9.9) and Google (8.8.8.8, 8.8.4.4). Use two from different providers so lookups still work if one fails.

VPS and dedicated server guides

Every guide in this section.

Fix name resolution errors

Temporary failure in name resolution.

Static IP with Netplan

Full Netplan network setup.

VPS DNS resolvers

Choose resolvers in the VPS Panel.

Point a domain to your server

Records for your own domain.

Checked against the Ubuntu Server networking guide, the systemd resolvectl and resolved.conf manuals and the Red Hat Enterprise Linux 9 networking guide on 4 November 2026; the Netplan example was validated with netplan generate on Ubuntu 24.04 LTS. Commands can differ on other distributions or releases.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026