When executing package updates (sudo apt update), querying remote repositories, or executing curl and ping commands in Ubuntu Linux, the terminal may return an immediate failure: Temporary failure in name resolution. While the host computer often retains local link connectivity and can reach numerical gateway IP addresses, it cannot resolve fully qualified domain names into IP addresses. This disruption halts automated deployments, Docker container builds, and daily system management.
Fixing name resolution failures requires inspecting the status of the local DNS stub resolver (systemd-resolved), correcting broken /etc/resolv.conf symlinks, and assigning reliable upstream DNS nameservers.
What Causes ‘Temporary Failure in Name Resolution’ in Ubuntu?
In Ubuntu 20.04, 22.04, and 24.04 LTS, name resolution is orchestrated by systemd-resolved via a local loopback stub listener (127.0.0.53). Name resolution halts when:
- systemd-resolved Service Stopped or Hung: The local DNS caching and stub resolution daemon is not active.
- Corrupted /etc/resolv.conf Symlink: The traditional Unix resolver file has been replaced by a static file or points to a non-existent stub target.
- Unreachable or Filtered Upstream DNS Servers: Upstream nameservers assigned by DHCP (such as local router resolvers) are timing out or filtering port 53 UDP traffic.
- DNSSEC Validation Failures: Upstream DNS resolvers lack proper DNSSEC signing support, causing
systemd-resolvedto reject responses. - Netplan DNS Directive Omissions: Static IP configurations in Netplan lack declared
nameserversblocks.
Step 1: Test Connectivity via Numerical IP vs Domain Name
Determine whether the issue is strictly isolated to DNS or represents a complete network routing collapse:
- Open a terminal and ping Cloudflare’s numerical DNS IP:
ping -c 3 1.1.1.1 - If the numerical ping succeeds with 0% packet loss, your network routing and default gateway are functioning properly, confirming the fault is purely DNS.
- If the numerical ping fails with Network is unreachable, troubleshoot your physical interface and default gateway first before adjusting DNS.
Step 2: Restart and Inspect systemd-resolved
Restarting the systemd stub resolver flushes stale socket locks and reinitialises lookup threads:
- Check the operational status of the DNS daemon:
sudo systemctl status systemd-resolved - If the service is inactive or failed, start and enable it:
sudo systemctl enable --now systemd-resolved - Restart the service to flush runtime caches:
sudo systemctl restart systemd-resolved - Inspect current DNS servers bound to active interfaces:
Verify that your primary interface (e.g.resolvectl statuseth0orenp3s0) lists valid DNS Servers.
Step 3: Recreate the /etc/resolv.conf Symlink
In modern Ubuntu systems, /etc/resolv.conf must be a symbolic link pointing to the systemd stub listener:
- Check the file type of your current resolver configuration:
ls -l /etc/resolv.conf - If it is a regular static file or broken link, remove it:
sudo rm -f /etc/resolv.conf - Recreate the correct symbolic link pointing to the systemd-resolved stub:
sudo ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf - Restart the resolver service:
sudo systemctl restart systemd-resolved
Step 4: Configure Upstream DNS Servers in resolved.conf
If your local router’s DNS server is unreliable, hardcode public DNS fallbacks directly in systemd configuration:
- Edit the main
resolved.confconfiguration file:sudo nano /etc/systemd/resolved.conf - Locate the
[Resolve]section and configure the following directives (remove leading#symbols):[Resolve] DNS=1.1.1.1 8.8.8.8 FallbackDNS=1.0.0.1 8.8.4.4 DNSSEC=no - Save the file by pressing
Ctrl + O, then exit withCtrl + X. - Restart the resolver to apply the new upstream nameservers:
sudo systemctl restart systemd-resolved - Test domain resolution immediately:
ping -c 3 digitash.com
Step 5: Add Nameservers to Netplan Configuration
If your server uses static IP addressing configured through Netplan, declare nameservers explicitly:
- Open your Netplan YAML file:
sudo nano /etc/netplan/01-netcfg.yaml - Ensure your active interface configuration includes a dedicated
nameserversblock:nameservers: addresses: [1.1.1.1, 8.8.8.8] - Apply changes cleanly:
sudo netplan generate sudo netplan apply - Run
sudo apt updateto confirm that all repository domains resolve without errors.