Temporary failure in name resolution on a Linux server
Temporary failure in name resolutionShort answer
The name lookup got no usable DNS server. On systemd-resolved systems, /etc/resolv.conf should link to the stub file that points at 127.0.0.53. It fails when that link is missing or stale, when resolved has no upstream servers (DNS=), or when the stub listener is off while resolv.conf still names it.
Fix it fast
1Find out which cause you have
Show what resolv.conf is and whether a lookup through the system resolver works. Raw IP connectivity should be tested too, so you know DNS is the problem.
ls -l /etc/resolv.conf cat /etc/resolv.conf getent hosts example.com ping -c 2 1.1.1.12Match what you see, then jump to its fix
- 1
resolv.conf is a plain file that is empty or lists dead servers, and systemd-resolved is running./etc/resolv.conf is not linked to the resolved stub fileFix - 2
resolv.conf points at 127.0.0.53 and the lookup still fails; the network has no DHCP-supplied DNS.systemd-resolved has no upstream DNS serverFix - 3
resolv.conf names 127.0.0.53 but nothing answers on it.The stub listener is off, or its port is takenFix
- 1
What does the error look like?
Temporary failure in name resolutionping: example.com: Temporary failure in name resolutioncurl and apt fail on host names while pinging an IP address works
Cause 1 of 3
/etc/resolv.conf is not linked to the resolved stub file
1Check
systemd-resolved maintains /run/systemd/resolve/stub-resolv.conf, which lists only the 127.0.0.53 stub. The manual recommends linking /etc/resolv.conf to it. If another package manages the file, resolved only reads it.
systemctl is-active systemd-resolved
ls -l /etc/resolv.conf /run/systemd/resolve/2Fix
Point /etc/resolv.conf at the stub file.
sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf3Verify
A lookup through the system resolver should answer.
getent hosts example.comConfirmed by manpages.ubuntu.com
Cause 2 of 3
systemd-resolved has no upstream DNS server
1Check
Resolved uses per-link servers and the DNS= setting. Without DNS=, it falls back to the servers listed in /etc/resolv.conf, and FallbackDNS= only applies when no other DNS information is known.
grep -vE '^\s*(#|$)' /etc/systemd/resolved.conf2Fix
Give resolved explicit servers, then restart the service.
# /etc/systemd/resolved.conf
[Resolve]
DNS=1.1.1.1 9.9.9.93Verify
Restart resolved and look the name up again.
sudo systemctl restart systemd-resolved
getent hosts example.comConfirmed by manpages.ubuntu.com
Cause 3 of 3
The stub listener is off, or its port is taken
1Check
DNSStubListener=no turns the stub off, and the stub also turns itself off when its address and port are already in use (for example by another DNS server on the machine).
grep -rn "DNSStubListener" /etc/systemd/resolved.conf /etc/systemd/resolved.conf.d/ 2>/dev/null
sudo ss -lunp | grep ':53 '2Fix
Remove the DNSStubListener=no line, or stop the other service using port 53. If you must keep the stub off, link resolv.conf to the uplink file instead, which lists the real upstream servers.
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf3Verify
Restart resolved and test a lookup.
sudo systemctl restart systemd-resolved
getent hosts example.comConfirmed by manpages.ubuntu.com
How do I stop it coming back?
- Keep one owner for /etc/resolv.conf. Do not edit it by hand on a machine where systemd-resolved manages it.
- Put permanent DNS servers in /etc/systemd/resolved.conf or in your network configuration, not in resolv.conf.
- After installing a local DNS server such as dnsmasq, decide who owns port 53.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Servers
ssh says it could not resolve the hostname
ssh: Could not resolve hostname
ssh could not turn the name you gave into an address.
4 causes, each with a fixServers
Docker container cannot resolve hostnames (pip, apt, curl fail)
[Errno -3] Temporary failure in name resolution
A container copies its DNS settings from the host.
3 causes, each with a fixServers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fix