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.
- Open your terminal and ping a known public IP address directly (such as Google Public DNS):
ping -c 3 8.8.8.8 - 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.
- 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 usingip 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.
- Inspect the operational state of the resolver daemon:
sudo systemctl status systemd-resolved - If the service is dead, inactive, or reporting internal timeout errors, restart it cleanly:
sudo systemctl restart systemd-resolved - Ensure the service is configured to launch automatically at system startup:
sudo systemctl enable systemd-resolved - 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.
- Check if
/etc/resolv.confis a proper symlink:ls -l /etc/resolv.conf - 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 - Recreate the correct symbolic link:
sudo ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf - 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.
- Open the systemd-resolved configuration file in a terminal text editor:
sudo nano /etc/systemd/resolved.conf - Locate the
[Resolve]section and uncomment or add the following lines to define reliable public nameservers:DNS=1.1.1.1 8.8.8.8FallbackDNS=1.0.0.1 8.8.4.4 - Save the file by pressing Ctrl + O, confirm with Enter, and exit via Ctrl + X.
- Restart the resolver service to apply the new upstream servers:
sudo systemctl restart systemd-resolved - Flush local DNS caches to clear corrupted lookup records:
sudo resolvectl flush-caches - Run
sudo apt updateto confirm that all repositories resolve and update smoothly.