/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.cominto 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
- Ubuntu (Netplan + systemd-resolved)
- AlmaLinux / Rocky (NetworkManager)
- Debian (static file)
1
Edit the Netplan file
use-dns: false stops DHCP from adding its own resolvers. With a static setup (dhcp4: false), you only need nameservers.2
Apply
3
Check
1.1.1.1 9.9.9.9.sudo resolvectl dns eth0 1.1.1.1 9.9.9.9, and undo it with sudo resolvectl revert eth0.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:
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 withresolvectl status.
How do I clear the DNS cache on Linux?
On systemd-resolved, runsudo 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.
Related guides
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:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026