What the File Holds
nameserver 192.0.2.53
nameserver 198.51.100.53
search example.com
options timeout:2 attempts:3 rotate
- nameserver: a DNS server to ask, tried in the order listed. The C library reads at most three.
- search: domains appended to short names, so
dbis looked up asdb.example.com. - options: settings for timeouts, retries, and order, described further down.
Who Writes It Today
Start by checking whether the file is a link:
ls -l /etc/resolv.conf
- systemd-resolved: on Ubuntu Server the file is a link to a file under
/run/systemd/resolve/and listsnameserver 127.0.0.53, a local stub that forwards queries to the real servers. - NetworkManager: on AlmaLinux and Rocky Linux it is a plain file whose first line says NetworkManager generated it.
- cloud-init and netplan: on cloud images, cloud-init writes the network configuration at first boot, and netplan passes the DNS servers on. See what is cloud-init.
- ifupdown: Debian systems that use it often keep a plain file, which a DHCP client can rewrite.
See the Servers Really in Use
resolvectl status
nmcli device show | grep DNS
With the stub, resolv.conf shows only 127.0.0.53. resolvectl status shows the real upstream servers per interface. The second command is for NetworkManager systems.
Set DNS Servers with Netplan
On Ubuntu, add the servers to the interface in your file under /etc/netplan/:
network:
version: 2
ethernets:
eth0:
nameservers:
addresses: [192.0.2.53, 198.51.100.53]
search: [example.com]
Apply with sudo netplan try, which rolls back unless you confirm. Use your real interface name. The full file is in how to configure a static IP with netplan.
Set DNS Servers with nmcli
nmcli connection show
sudo nmcli connection modify "System eth0" ipv4.dns "192.0.2.53 198.51.100.53" ipv4.ignore-auto-dns yes
sudo nmcli connection up "System eth0"
Reactivating the connection can drop an SSH session for a moment, so keep the console in your provider's control panel at hand. More in how to set a static IP with nmcli.
Set DNS Servers in resolved.conf
For a global setting in systemd-resolved, create a drop-in file such as /etc/systemd/resolved.conf.d/dns.conf:
[Resolve]
DNS=192.0.2.53 198.51.100.53
Then run sudo systemctl restart systemd-resolved. Servers set per interface by netplan or DHCP stay in place next to the global ones.
Timeout, Attempts, and Rotate
| Option | Effect |
|---|---|
timeout:n | Seconds before the next server |
attempts:n | Rounds through the list |
rotate | Spreads queries over servers |
With the 127.0.0.53 stub there is only one entry, so these options matter little; systemd-resolved handles retries itself.
Editing the File by Hand
A wrong entry breaks name resolution for updates and applications, although SSH to the IP address keeps working. If you edit it for a quick test, copy it first with sudo cp /etc/resolv.conf /root/resolv.conf.bak, and do not replace a link with a plain file while a service still manages it. Make the lasting change in the owning tool.
Test the Result
dig example.com
resolvectl query example.com
getent hosts example.com
dig asks the server listed in resolv.conf directly, resolvectl query asks systemd-resolved where it runs, and getent goes the way applications do, including /etc/hosts. Details are in the dig command guide. If lookups fail, see temporary failure in name resolution; for stale answers, flush the DNS cache.