How to Fix ‘Temporary Failure in Name Resolution’ in Ubuntu Terminal

Executing command-line utilities such as sudo apt update, curl, git clone, or ping google.com on an Ubuntu desktop or cloud server only to receive ‘Could not resolve host’ or ‘Temporary failure in name resolution’ completely prevents network operations. Despite your physical network interface or Wi-Fi adapter showing active link status, your system cannot translate human-readable domain names into IP addresses.

This breakdown typically occurs when the local systemd-resolved DNS stub service crashes or stalls, the /etc/resolv.conf symlink breaks, upstream DHCP-assigned DNS servers fail to respond, or NetworkManager overrides static nameserver declarations. Following this tutorial will systematically diagnose and resolve the DNS resolution failure.

Test Network Connectivity Using Raw IP Addresses

Before modifying DNS configurations, confirm whether the system possesses basic IP-level routing to rule out physical cable disconnections or default gateway routing failures.

  1. Open your terminal and ping a known public IP address directly (such as Google Public DNS):
    ping -c 3 8.8.8.8
  2. If packets return successfully (0% packet loss), your internet gateway and physical routing are healthy, confirming the fault is strictly isolated to the domain name resolution subsystem.
  3. If the ping returns ‘Network is unreachable’, check your physical link, restart your network adapter with sudo ip link set <interface> up, or inspect default routes using ip route.

Restart and Inspect systemd-resolved Service

Modern Ubuntu installations (18.04 LTS through 24.04 LTS) route all internal DNS queries through the local caching daemon systemd-resolved via the loopback stub resolver at 127.0.0.53.

  1. Inspect the operational state of the resolver daemon:
    sudo systemctl status systemd-resolved
  2. If the service is dead, inactive, or reporting internal timeout errors, restart it cleanly:
    sudo systemctl restart systemd-resolved
  3. Ensure the service is configured to launch automatically at system startup:
    sudo systemctl enable systemd-resolved
  4. Query the current upstream DNS servers recognised by systemd:
    resolvectl status

Reconstruct the /etc/resolv.conf Symbolic Link

A widespread issue occurs when text editing utilities or misconfigured VPN clients overwrite /etc/resolv.conf with a static text file, severing the link to the active systemd stub resolver.

  1. Check if /etc/resolv.conf is a proper symlink:
    ls -l /etc/resolv.conf
  2. If it is a standard file rather than pointing to ../run/systemd/resolve/stub-resolv.conf, remove the static file:
    sudo rm -f /etc/resolv.conf
  3. Recreate the correct symbolic link:
    sudo ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
  4. Test name resolution immediately by running ping -c 2 digitash.com.

Configure Static Upstream Fallback Nameservers

If your local router or ISP upstream DNS servers are unresponsive or refusing recursive lookup requests, configure trusted public resolvers directly within systemd configuration.

  1. Open the systemd-resolved configuration file in a terminal text editor:
    sudo nano /etc/systemd/resolved.conf
  2. Locate the [Resolve] section and uncomment or add the following lines to define reliable public nameservers:
    DNS=1.1.1.1 8.8.8.8
    FallbackDNS=1.0.0.1 8.8.4.4
  3. Save the file by pressing Ctrl + O, confirm with Enter, and exit via Ctrl + X.
  4. Restart the resolver service to apply the new upstream servers:
    sudo systemctl restart systemd-resolved
  5. Flush local DNS caches to clear corrupted lookup records:
    sudo resolvectl flush-caches
  6. Run sudo apt update to confirm that all repositories resolve and update smoothly.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.