"Temporary failure in name resolution": fix DNS on a Linux server
Fix "Temporary failure in name resolution" and "Could not resolve host" on Linux: tell DNS from network problems, check systemd-resolved, and set DNS servers that stick.
by OhSudo ··
Not sure this is your cause?Find it step by step: Can't connect over SSH →
Nothing that uses a name works anymore:
$ ping github.comping: github.com: Temporary failure in name resolution
$ curl https://github.comcurl: (6) Could not resolve host: github.com
$ sudo apt updateErr:1 http://archive.ubuntu.com/ubuntu noble InRelease Temporary failure resolving 'archive.ubuntu.com'“Name resolution” is DNS: turning github.com into an IP address. Temporary failure means the resolver couldn’t get any answer — no DNS server was reachable, or none replied in time. That’s different from Name or service not known, which means a DNS server answered and said the name doesn’t exist.
- ping, curl, aptneed github.comlook up the name
- Resolver/etc/resolv.conf (127.0.0.53 on Ubuntu)(works)ask(fails)
- DNS serverno answer(breaks here)
TL;DR
ping -c 3 1.1.1.1 # does the network work without DNS?resolvectl status # which DNS servers is the system really using?dig @1.1.1.1 github.com # does a known DNS server answer?If the IP works, the name doesn’t, and dig @1.1.1.1 answers → your configured DNS servers are the problem. Set working ones (section 4).
1. Is it DNS, or the whole network?
ping -c 3 1.1.1.1ip route- No reply from
1.1.1.1either → it’s not DNS. The server has no route out: checkip routefor adefault via …line, the interface (ip -br a), the cloud firewall / security group. - The IP replies, names don’t → it’s DNS. Continue.
(Some networks block ping. If so, try curl -sI https://1.1.1.1 instead.)
2. Which DNS server does the system use?
cat /etc/resolv.confOn Ubuntu and many Debian systems you’ll see:
nameserver 127.0.0.53options edns0 trust-ad127.0.0.53 is systemd-resolved, a local DNS service that forwards questions to the real servers. The real ones are here:
resolvectl statusLink 2 (eth0) Current Scopes: DNSCurrent DNS Server: 10.0.0.2 DNS Servers: 10.0.0.2No DNS Servers line at all means the network configuration gave this interface no DNS servers. If systemd-resolved itself isn’t running, 127.0.0.53 answers nothing:
systemctl status systemd-resolved --no-pagersudo systemctl restart systemd-resolvedOn RHEL-family systems, /etc/resolv.conf is usually written by NetworkManager and lists the real servers directly; nmcli dev show | grep DNS shows them too.
3. Ask a DNS server directly
dig github.com # through the system's configured serversdig @10.0.0.2 github.com # one specific serverdig @1.1.1.1 github.com # a public one, for comparison(dig is in bind9-dnsutils on Debian/Ubuntu, bind-utils on RHEL. nslookup github.com 1.1.1.1 works too.)
| Result | Meaning |
|---|---|
@1.1.1.1 answers, your server times out |
Your DNS server is down or unreachable — use another one |
Nothing answers, not even @1.1.1.1 |
Outgoing DNS (port 53, UDP and TCP) is blocked by a firewall |
status: NXDOMAIN |
The name really doesn’t exist (typo, or an internal name only your company’s DNS knows) |
4. Set DNS servers that stick
Don’t just edit /etc/resolv.conf: on most systems it’s generated, and your change disappears at the next reboot or DHCP renewal. Set the servers where the network is configured.
Ubuntu (netplan): in the file under /etc/netplan/, under your interface:
network: version: 2 ethernets: eth0: dhcp4: true nameservers: addresses: [1.1.1.1, 9.9.9.9]sudo netplan try # applies it, and rolls back by itself if you lose the connectionRHEL / Rocky / AlmaLinux (NetworkManager):
nmcli connection show # find the connection namesudo nmcli connection modify "System eth0" ipv4.dns "1.1.1.1 9.9.9.9"sudo nmcli connection up "System eth0"On a cloud server, prefer the provider’s own DNS address if it has one (for example 169.254.169.253 on AWS, or the .2 address of the VPC) — internal names often resolve only there.
5. Inside Docker containers
Containers get their own copy of the resolver settings. If the host uses 127.0.0.53 (an address that means nothing inside a container), Docker gives the container the host’s real upstream servers instead, or public ones as a last resort. On company networks that block public DNS, containers then fail while the host works. Tell Docker which servers to use in /etc/docker/daemon.json:
{ "dns": ["10.0.0.2", "1.1.1.1"] }sudo systemctl restart dockerRecreate the containers afterwards (docker compose up -d --force-recreate). Check from inside one: docker run --rm busybox nslookup github.com.
Note
WSL 2: Windows generates /etc/resolv.conf inside WSL. With some VPNs that file points to a server WSL can’t reach. Turn generation off in /etc/wsl.conf ([network] → generateResolvConf = false), run wsl --shutdown from Windows, then write your own /etc/resolv.conf.
Shell, we have a problem!
Similar, but different: Name or service not known / NXDOMAIN — DNS works, but the name doesn’t exist: check the spelling, or whether it’s an internal name. A name that resolves to the wrong address is often a stale line in /etc/hosts — getent hosts github.com shows what the system really uses, /etc/hosts included. If DNS works and apt still can’t find a package, see Unable to locate package.
Found this useful? Share it.
Found a mistake? Let us know at contact@ohsudo.com.