Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Temporary failure in name resolution on a Linux server

ErrorTemporary failure in name resolution

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

  • Applies to Ubuntu 24.04, systemd 255
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.1
  2. 2Match what you see, then jump to its fix

    1. 1resolv.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. 2resolv.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. 3resolv.conf names 127.0.0.53 but nothing answers on it.The stub listener is off, or its port is takenFix

What does the error look like?

  • Temporary failure in name resolution
  • ping: example.com: Temporary failure in name resolution
  • curl 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.conf

3Verify

A lookup through the system resolver should answer.

getent hosts example.com

Confirmed by manpages.ubuntu.com

Did this fix it?

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

2Fix

Give resolved explicit servers, then restart the service.

# /etc/systemd/resolved.conf
[Resolve]
DNS=1.1.1.1 9.9.9.9

3Verify

Restart resolved and look the name up again.

sudo systemctl restart systemd-resolved
getent hosts example.com

Confirmed by manpages.ubuntu.com

Did this fix it?

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

3Verify

Restart resolved and test a lookup.

sudo systemctl restart systemd-resolved
getent hosts example.com

Confirmed by manpages.ubuntu.com

Did this fix it?

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

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.