Temporary failure resolving (DNS errors during updates)
What this is
Running apt update (or curl, git, anything that needs a hostname) fails with "Temporary failure resolving 'archive.ubuntu.com'" or "Could not resolve host". Your VPS's network is fine, but its DNS resolver isn't answering, so it can't turn names into IPs.
The fix
Point systemd-resolved at a public resolver:
- Edit the resolver config:
nano /etc/systemd/resolved.conf - Find the
#DNS=line, uncomment it, and set a resolver:DNS=8.8.8.8 - Save (Ctrl+X, then Y) and restart the resolver:
systemctl restart systemd-resolved
Or as a single command:
sed -i 's/#DNS=/DNS=8.8.8.8/' /etc/systemd/resolved.conf && systemctl restart systemd-resolved
Then retry the update. 8.8.8.8 is Google's public resolver; 1.1.1.1 (Cloudflare) works just as well.
If that doesn't do it
- Check
/etc/resolv.confexists and isn't empty. On systemd-resolved systems it should be a symlink managed for you; on others, a plainnameserver 8.8.8.8line in it does the job. - Check your own firewall isn't blocking outbound DNS (UDP/TCP port 53), an overzealous ruleset with a default-deny on output does exactly this.
- Still stuck? Open a ticket with the exact error and what you've tried.
Related questions
- "Why does apt update say temporary failure resolving?"
- "My VPS can't resolve any hostnames."
- "How do I fix DNS inside my VPS?"
- "Could not resolve host errors on my VPS."