Skip to content
ohsudo, Home
Networking

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

Beginner4 min readApplies to Ubuntu 20.04+ · Debian 11+ · RHEL / Rocky / AlmaLinux 8–9 · Docker

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.com
ping: github.com: Temporary failure in name resolution
$ curl https://github.com
curl: (6) Could not resolve host: github.com
$ sudo apt update
Err: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.

  1. ping, curl, aptneed github.com
  2. Resolver/etc/resolv.conf (127.0.0.53 on Ubuntu)(works)
  3. DNS serverno answer(breaks here)
A name lookup goes through the resolver to a DNS server. Temporary failure: no answer came back, because no DNS server was reachable or none replied in time.

TL;DR

Terminal window
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?

Terminal window
ping -c 3 1.1.1.1
ip route
  • No reply from 1.1.1.1 either → it’s not DNS. The server has no route out: check ip route for a default 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?

Terminal window
cat /etc/resolv.conf

On Ubuntu and many Debian systems you’ll see:

nameserver 127.0.0.53
options edns0 trust-ad

127.0.0.53 is systemd-resolved, a local DNS service that forwards questions to the real servers. The real ones are here:

Terminal window
resolvectl status
Link 2 (eth0)
Current Scopes: DNS
Current DNS Server: 10.0.0.2
DNS Servers: 10.0.0.2

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

Terminal window
systemctl status systemd-resolved --no-pager
sudo systemctl restart systemd-resolved

On 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

Terminal window
dig github.com # through the system's configured servers
dig @10.0.0.2 github.com # one specific server
dig @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]
Terminal window
sudo netplan try # applies it, and rolls back by itself if you lose the connection

RHEL / Rocky / AlmaLinux (NetworkManager):

Terminal window
nmcli connection show # find the connection name
sudo 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"] }
Terminal window
sudo systemctl restart docker

Recreate 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.

Tools

Try it yourself

Articles

Related articles