Linux: Temporary failure in name resolution
The resolver could not reach an answer: check resolv.conf, the systemd-resolved stub, container DNS policy and port 53 before touching the app.

Introduction & Quick Summary
A fresh server or container can reach IP addresses but not names:
Temporary failure in name resolution
It appears from apt update, curl, ssh, git clone, pip install and docker build, usually with a second line such as Could not resolve 'archive.ubuntu.com' or Name or service not known. Quick answer: the resolver could not get an answer from any configured DNS server, so the name never became an address.
getent hosts example.com # uses nsswitch, closest to what apps see
cat /etc/resolv.conf
resolvectl status 2>/dev/null | head -20
ping -c1 1.1.1.1 # routing works?
dig +short example.com @1.1.1.1 # does a direct query work?The error says "temporary", and sometimes it is: a resolver timeout, a VPN that has not finished connecting, or a container started before its network namespace was ready. Far more often it is persistent configuration: a missing or empty resolv.conf, a stub resolver that is not running, a firewall dropping UDP 53, or a container DNS policy that points at nothing. This guide walks the resolution path from nsswitch to the wire and fixes each break.
Core Mechanics, Signatures & Reproducible Setup
Name resolution in glibc goes through nsswitch.conf: files reads /etc/hosts, dns asks the servers in /etc/resolv.conf, mymachines and resolve are systemd modules. The error is the generic glibc diagnosis for "try again later, no server answered".
# what the app sees
getent ahosts example.com
# what the resolver would ask
resolvectl query example.com
# what the wire answers
dig +time=2 +tries=1 example.comReproduce with an empty nameserver list:
unshare -m --map-root-user bash -c 'mount --bind /dev/null /etc/resolv.conf; getent hosts example.com'
# getent: Temporary failure in name resolution| Layer | File or service | Fails when |
|---|---|---|
| nsswitch order | /etc/nsswitch.conf | dns missing, or resolve used without systemd-resolved running |
| local overrides | /etc/hosts | wrong entry shadows the real name |
| resolver config | /etc/resolv.conf | no nameserver, bad address, options too strict |
| stub resolver | systemd-resolved on 127.0.0.53 | service stopped, symlink overwritten |
| upstream DNS | DHCP, VPN, cloud metadata | server unreachable, blocked or rate limited |
| transport | UDP/TCP 53 | firewall, NAT, IPv6-only route |
| Symptom | Points to | Check |
|---|---|---|
ping 1.1.1.1 works, names fail | DNS only | cat /etc/resolv.conf |
| both fail | routing or interface | ip route, ip addr |
| works as root, fails as user | permissions on config | ls -l /etc/resolv.conf |
| works on host, fails in container | container DNS policy | docker exec c cat /etc/resolv.conf |
| fails only for internal names | split DNS or search domain | resolvectl domain |
| slow then fails | timeout, packet loss | dig +time=5 +tries=1 |
Key Comparison Table
/etc/resolv.conf state | Typical origin | Effect |
|---|---|---|
symlink to /run/systemd/resolve/stub-resolv.conf | systemd-resolved | nameserver 127.0.0.53, works if resolved runs |
symlink to /run/systemd/resolve/resolv.conf | manual configuration | real upstream servers, bypasses the stub |
regular file with nameserver 8.8.8.8 | Docker inserts it | works unless the network blocks it |
| empty file | container started with --dns=none | every lookup fails |
| only IPv6 nameserver | DHCPv6 | fails on IPv4-only networks |
search with a stale domain | VPN or DHCP change | internal names resolve to wrong suffix |
| Fix | Command | Persistence |
|---|---|---|
| Restart the resolver | systemctl restart systemd-resolved | until next change |
| Regenerate the symlink | ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf | survives reboot |
| Set DNS per link | resolvectl dns eth0 1.1.1.1 9.9.9.9 | NetworkManager profile |
| Persistent config | edit /etc/systemd/resolved.conf then restart | reboot-safe |
| Container DNS | docker run --dns 1.1.1.1 or daemon.json | image or daemon level |
| Immutable file | chattr +i /etc/resolv.conf | blocks the culprit and the fix |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
1. Empty or replaced resolv.conf
ls -l /etc/resolv.conf
# lrwxrwxrwx 1 root root 39 ... /etc/resolv.conf -> /run/systemd/resolve/stub-resolv.conf
cat /etc/resolv.conf
# nameserver 127.0.0.53# the symlink was replaced by an empty file, often by a container runtime or an installer
: > /etc/resolv.conf
getent hosts example.com
# Temporary failure in name resolutionRestore the symlink on a systemd host, or write real upstream servers if the host has no resolved. Do not leave an empty file, because DHCP clients and resolvconf managers may refuse to overwrite a regular file they did not create.
2. The systemd-resolved stub is not listening
systemctl status systemd-resolved --no-pager
ss -lunp | grep :53
resolvectl status | sed -n '1,12p'127.0.0.53 only answers while the service runs. A stopped or crashed unit makes every name fail with exactly this error while /etc/resolv.conf still looks correct. If ss shows nothing on port 53 and the unit is inactive, restart it and check journalctl -u systemd-resolved -n 40.
3. Containers and the embedded DNS server
docker run --rm alpine cat /etc/resolv.conf
docker network inspect bridge --format '{{.IPAM.Config}}'Docker's embedded DNS at 127.0.0.11 forwards to the host's resolvers; a host with a broken resolv.conf breaks every container. Kubernetes pods use the cluster DNS service, and a pod with dnsPolicy: None and an empty dnsConfig.nameservers fails the same way. Check from inside:
kubectl exec deploy/api -- cat /etc/resolv.conf
kubectl exec deploy/api -- nslookup kubernetes.defaultndots:5 makes short names try search domains first, which can add seconds of latency before the real query; it rarely causes this error but often explains "slow then fails".
4. VPN, split DNS and search domains
resolvectl domain
# Global: ~.
# wg0: ~corp.internal
resolvectl query db.corp.internalA VPN that installs split DNS routes internal names to its own resolver. If the tunnel is up but the route is missing, internal names fail while public names work. resolv.conf with a stale search corp.internal makes db resolve to db.corp.internal after the tunnel is gone.
5. Firewall and transport problems
dig +short example.com @8.8.8.8
dig +tcp +short example.com @8.8.8.8If UDP times out but TCP works, something drops UDP 53. If both fail but ping 8.8.8.8 succeeds, egress filtering is likely. On IPv6-only networks with NAT64, DNS64 must be present, otherwise AAAA answers come back empty and a resolver that only asks A records reports failure. Use the CIDR calculator to confirm which subnet the resolver is on, and the curl reference for the client-side error text of each failure.
6. WSL2 and cloud instances
cat /etc/resolv.conf
# nameserver 172.20.x.x (WSL2 virtual gateway)WSL2 regenerates resolv.conf on every start and points at a virtual gateway; a VPN client that changes routing breaks it, and the fix is either generateResolvConf = false with a static file or a restart of the WSL network. On cloud instances, DHCP-provided resolvers are usually correct, so a failure after a snapshot restore more often means the network interface came up without DHCP or the instance is in a private subnet without a DNS route.
Common Compilation/Runtime Mistakes & Version Gotchas
- Editing
/etc/resolv.confon a systemd host. systemd-resolved rewrites the symlink target; configure/etc/systemd/resolved.confor the network profile instead. chattr +ias a fix. It stops the manager from overwriting the file and also blocks legitimate DHCP updates, leaving a stale resolver forever.- Testing with
ping. Many images lackping, and ICMP success says nothing about DNS.getent hostsis the accurate test because it uses the same nsswitch path as applications. - Forgetting
nsswitch.conf. A container built fromscratchwith onlylibcand no/etc/nsswitch.confcan fail to resolve even with a validresolv.conf. - Assuming
hostandnslookupexist. Minimal images ship neither; installbind-utilsor usegetent, which is part of glibc. - Container restart loops masking DNS. A pod that starts before cluster DNS is ready fails once and is restarted; an init container with retries is more reliable than
restartPolicy: Alwayson the app itself. - systemd-resolved versus dnsmasq. Running both on port 53 produces one that fails to bind, and it is easy to miss because the other keeps working until a restart.
- Version notes. Ubuntu 22.04 and later ship systemd-resolved by default; Debian containers often ship neither resolved nor a meaningful
resolv.conf, which is why the same image behaves differently on a desktop and in CI.
Follow the path in order: nsswitch, then resolv.conf, then whether the configured server answers, then whether the packet leaves the host. Each step produces a different error, and the one that fails tells you which file or firewall rule to change.
Official documentation: resolv.conf(5) and systemd-resolved.service.
Official references
primary documentationThe Linux documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Linux work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Linux guides
All Linux guidesnginx 502 Bad Gateway: upstream connection refused
The log line names the address and errno, which is the diagnosis. Fix the host, the start-up order, the buffers, or the timeout that actually fired.
Linux: Read-only file system (EROFS) on a mounted volume
EROFS is a mount condition, not a permission error. Read the kernel log first: I/O errors, a full thin pool, an ro fstab entry or a read-only root.
Linux: bind: Cannot assign requested address
EADDRNOTAVAIL means the kernel had no address to bind: too many TIME_WAIT sockets, an IP missing from the interface, or a wrong listen address.
/usr/bin/env: bash with a carriage return: no such file or directory
A CRLF shebang names an interpreter that cannot exist. Normalise the file and stop the next one with .gitattributes.
More in Linux
All Linux guidesThe guides filed next to this one in Linux, in library order.