Changing DNS servers on Linux improves name resolution reliability, privacy, and performance when accessing internal services or public sites. Using trusted resolvers such as enterprise-provided servers or well-known public resolvers avoids outages caused by flaky default infrastructure and can bypass slow or misconfigured upstream providers.
On modern systemd-based distributions, systemd-resolved typically manages resolver settings and exposes them to applications through a stub listener and the /etc/resolv.conf file. The main configuration lives in /etc/systemd/resolved.conf, and this file controls which upstream DNS servers the resolver forwards queries to, along with optional fallback servers.
Some environments instead delegate DNS configuration to NetworkManager, VPN clients, or container runtimes, which can override settings at the interface level. Misconfiguring the resolver does not usually disconnect network links but can prevent domain names from resolving; keeping a backup of the original configuration and having IP-based access to critical systems greatly reduces risk when changing settings.
Steps to change DNS servers using systemd-resolved:
- Open a terminal with an account that can run administrative commands via sudo.
$ whoami user
- Check the systemd-resolved service status to confirm it is managing DNS queries.
$ sudo systemctl status systemd-resolved ● systemd-resolved.service - Network Name Resolution Manager Loaded: loaded (/lib/systemd/system/systemd-resolved.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2025-01-13 09:32:41 UTC; 15min ago ##### snipped #####An Active: active (running) line indicates that systemd-resolved is currently handling resolver duties.
- Inspect /etc/resolv.conf to confirm it is a symbolic link managed by systemd-resolved.
$ ls -l /etc/resolv.conf lrwxrwxrwx 1 root root 39 Jan 13 09:32 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
A symlink pointing into /run/systemd/resolve usually means this method applies; if it is a plain file, another tool such as NetworkManager or resolvconf may be in control.
- Create a timestamped backup of /etc/systemd/resolved.conf before editing it.
$ sudo cp /etc/systemd/resolved.conf /etc/systemd/resolved.conf.backup.$(date +%Y%m%d%H%M%S)
Restoring the backup with sudo cp is the quickest way to undo changes if name resolution fails after modification.
- Open /etc/systemd/resolved.conf in a text editor with elevated privileges.
$ sudo nano /etc/systemd/resolved.conf
- Add or update the DNS and FallbackDNS entries under the [Resolve] section with the preferred resolvers and save the file.
[Resolve] DNS=1.1.1.1 8.8.8.8 FallbackDNS=9.9.9.9 1.0.0.1
Multiple IP addresses on a single DNS line are tried in order; FallbackDNS is used when the primary servers are unreachable.
- Restart the systemd-resolved service to apply the new DNS configuration.
$ sudo systemctl restart systemd-resolved
If a typo produces an invalid configuration, applications may fail to resolve hostnames until the error is corrected or the backup configuration is restored.
- Confirm the active DNS servers reported by systemd-resolved.
$ resolvectl status Global Protocols: +LLMNR +mDNS +DNSOverTLS DNSSEC=no resolv.conf mode: stub Current DNS Server: 1.1.1.1 DNS Servers: 1.1.1.1 8.8.8.8 DNS Domain: ~.The Current DNS Server and DNS Servers lines should list the new IP addresses configured in /etc/systemd/resolved.conf.
- Test name resolution for a known domain to verify that queries succeed using the updated DNS infrastructure.
$ dig +short example.com 93.184.216.34
Repeated failures or timeouts suggest connectivity or configuration problems with the chosen resolvers and may require switching to different DNS servers or reverting the backup file.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.
