When running commands like sudo apt update, curl, wget, or git clone in Ubuntu, encountering the error message “Temporary failure in name resolution” or “Could not resolve host” means your system cannot convert domain names into IP addresses. While basic network connectivity may exist, Domain Name System (DNS) resolution is completely broken.
This failure occurs when Ubuntu’s local DNS stub resolver fails, when the /etc/resolv.conf symlink points to an obsolete file location, when upstream router DNS servers fail to respond, or when firewall configurations block UDP port 53. Follow these steps to restore fast, reliable DNS name resolution across your Ubuntu installation.
Verify Network Connectivity and Ping a Public IP
Before modifying DNS configurations, confirm whether the issue is strictly isolated to name resolution or if your entire internet gateway connection is offline.
- Open the Terminal application (Ctrl + Alt + T).
- Ping a reliable public IP address directly without using domain names:
ping -c 4 1.1.1.1 - If the ping returns
0% packet loss, your internet connection is active and the defect is 100% related to DNS name resolution. - If the ping fails with “Network is unreachable,” check your physical Ethernet cable, Wi-Fi connection, or default gateway routing (
ip route) before proceeding.
Restart and Inspect systemd-resolved Service
Modern Ubuntu distributions (18.04, 20.04, 22.04, and 24.04 LTS) use systemd-resolved to manage local caching and DNS multiplexing.
- Check the operational status of the resolver daemon:
sudo systemctl status systemd-resolved - If the service is inactive or in a failed state, restart it immediately:
sudo systemctl restart systemd-resolved - Flush local DNS caches to clear corrupted query records:
sudo resolvectl flush-caches - Inspect active DNS servers assigned to your interfaces:
resolvectl status
Repair the /etc/resolv.conf Symbolic Link
A frequent cause of broken DNS after software upgrades or manual edits is an invalid or broken /etc/resolv.conf file that has lost its symbolic link to the systemd-resolved stub.
- Inspect the current nature of
/etc/resolv.conf:ls -l /etc/resolv.conf - If it is a static file or a broken symlink, remove it:
sudo rm /etc/resolv.conf - Recreate the proper symbolic link to the systemd-resolved stub resolver:
sudo ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf - Restart the service:
sudo systemctl restart systemd-resolved
Configure Reliable Upstream DNS in Netplan
If your local router or DHCP server supplies non-responsive DNS nameservers, configure reliable public fallback DNS servers (such as Cloudflare and Google) directly in your system network configuration.
- Inspect your Netplan configuration file:
sudo nano /etc/netplan/01-netcfg.yaml(Note: Your filename may be
50-cloud-init.yamlor00-installer-config.yamldepending on installation type). - Under your active interface (e.g.
eth0orenp3s0), add or update thenameserversblock with correct YAML spacing:nameservers: addresses: [1.1.1.1, 1.0.0.1, 8.8.8.8] - Save changes (Ctrl + O, Enter, Ctrl + X).
- Apply the new network configuration cleanly:
sudo netplan apply
Apply an Emergency Temporary Nameserver
If you need immediate internet resolution to download packages or run updates while troubleshooting deeper network files, you can temporarily assign a public nameserver directly.
- Open
/etc/resolv.confin a text editor:sudo nano /etc/resolv.conf - Add the following lines at the very top:
nameserver 1.1.1.1 nameserver 8.8.8.8 - Save and exit the file.
- Test resolution immediately by running:
ping -c 3 ubuntu.com - Once resolution succeeds, proceed with your scheduled APT updates or package installations smoothly.