Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

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.

~5 min readLinux
#linux#dns#resolv-conf#systemd-resolved
Bold white headline reading DNS FAILURE beside a cyan resolver cube cut off by an amber broken cable.

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.

bash
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".

bash
# 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.com

Reproduce with an empty nameserver list:

bash
unshare -m --map-root-user bash -c 'mount --bind /dev/null /etc/resolv.conf; getent hosts example.com' # getent: Temporary failure in name resolution
LayerFile or serviceFails when
nsswitch order/etc/nsswitch.confdns missing, or resolve used without systemd-resolved running
local overrides/etc/hostswrong entry shadows the real name
resolver config/etc/resolv.confno nameserver, bad address, options too strict
stub resolversystemd-resolved on 127.0.0.53service stopped, symlink overwritten
upstream DNSDHCP, VPN, cloud metadataserver unreachable, blocked or rate limited
transportUDP/TCP 53firewall, NAT, IPv6-only route
SymptomPoints toCheck
ping 1.1.1.1 works, names failDNS onlycat /etc/resolv.conf
both failrouting or interfaceip route, ip addr
works as root, fails as userpermissions on configls -l /etc/resolv.conf
works on host, fails in containercontainer DNS policydocker exec c cat /etc/resolv.conf
fails only for internal namessplit DNS or search domainresolvectl domain
slow then failstimeout, packet lossdig +time=5 +tries=1

Key Comparison Table

/etc/resolv.conf stateTypical originEffect
symlink to /run/systemd/resolve/stub-resolv.confsystemd-resolvednameserver 127.0.0.53, works if resolved runs
symlink to /run/systemd/resolve/resolv.confmanual configurationreal upstream servers, bypasses the stub
regular file with nameserver 8.8.8.8Docker inserts itworks unless the network blocks it
empty filecontainer started with --dns=noneevery lookup fails
only IPv6 nameserverDHCPv6fails on IPv4-only networks
search with a stale domainVPN or DHCP changeinternal names resolve to wrong suffix
FixCommandPersistence
Restart the resolversystemctl restart systemd-resolveduntil next change
Regenerate the symlinkln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.confsurvives reboot
Set DNS per linkresolvectl dns eth0 1.1.1.1 9.9.9.9NetworkManager profile
Persistent configedit /etc/systemd/resolved.conf then restartreboot-safe
Container DNSdocker run --dns 1.1.1.1 or daemon.jsonimage or daemon level
Immutable filechattr +i /etc/resolv.confblocks the culprit and the fix

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Empty or replaced resolv.conf

bash
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
bash
# 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 resolution

Restore 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

bash
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:

bash
kubectl exec deploy/api -- cat /etc/resolv.conf kubectl exec deploy/api -- nslookup kubernetes.default

ndots: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

bash
resolvectl domain # Global: ~. # wg0: ~corp.internal resolvectl query db.corp.internal

A 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

bash
dig +short example.com @8.8.8.8 dig +tcp +short example.com @8.8.8.8

If 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

bash
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.conf on a systemd host. systemd-resolved rewrites the symlink target; configure /etc/systemd/resolved.conf or the network profile instead.
  • chattr +i as 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 lack ping, and ICMP success says nothing about DNS. getent hosts is the accurate test because it uses the same nsswitch path as applications.
  • Forgetting nsswitch.conf. A container built from scratch with only libc and no /etc/nsswitch.conf can fail to resolve even with a valid resolv.conf.
  • Assuming host and nslookup exist. Minimal images ship neither; install bind-utils or use getent, 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: Always on 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 documentation

The Linux documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Linux work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Linux guides

More in Linux

All Linux guides

The guides filed next to this one in Linux, in library order.