Ubuntu 20.04 出现 'temporary failure in name resolution' 错误导致无法联网及系统更新求助
Hey there, sorry to hear you've been stuck with this frustrating network issue for days—let's break this down step by step to get your internet access and system updates working again.
First, let's address the resolv.conf problem: on Ubuntu 20.04, this file is usually a symbolic link managed by systemd-resolved, so manually editing it often doesn't stick (it gets overwritten after a reboot or network restart). Here's how to fix that properly:
Check if
resolv.confis a symlink
Run this command to confirm:ls -l /etc/resolv.confIf you see it pointing to something like
/run/systemd/resolve/stub-resolv.conf, that meanssystemd-resolvedis handling your DNS settings.Configure DNS via
systemd-resolved- Open the resolved configuration file with a text editor:
sudo nano /etc/systemd/resolved.conf - Uncomment the
DNSline and add reliable DNS servers (like Google's or Cloudflare's):DNS=8.8.8.8 8.8.4.4 1.1.1.1 - Save the file (press
Ctrl+O, thenEnter, thenCtrl+Xto exit nano). - Restart the
systemd-resolvedservice to apply changes:sudo systemctl restart systemd-resolved - Verify the DNS settings are active:
Look for the "DNS Servers" line to confirm your chosen servers are listed.resolvectl status
- Open the resolved configuration file with a text editor:
Next, let's rule out other common issues:
Check basic network connectivity
First, make sure you're actually connected to your network (Wi-Fi signal is strong, Ethernet cable is plugged in). Then ping your router's gateway (replace192.168.1.1with your actual gateway IP—you can find it viaip route):ping 192.168.1.1If this fails, your issue is with the network connection itself, not DNS. Try restarting your router or reconnecting to the network.
Check firewall settings
Sometimesufw(Ubuntu's default firewall) can block DNS traffic. Check its status:sudo ufw statusIf it's active, ensure UDP and TCP port 53 (used for DNS) is allowed:
sudo ufw allow 53 sudo ufw reloadCheck for incorrect proxy settings
A misconfigured proxy can block internet access. Check if any proxy variables are set:echo $HTTP_PROXY $HTTPS_PROXYIf you see values here that shouldn't be there, unset them with:
unset HTTP_PROXY HTTPS_PROXYYou can also check proxy settings in the system settings > Network > Network Proxy, set it to "None" if needed.
After trying these steps, test your internet access again by pinging a domain:
ping google.com
If this works, you should be able to run system updates with:
sudo apt update && sudo apt upgrade
Let me know if any of these steps resolve your issue, or if you run into specific error messages along the way—I'll help you troubleshoot further!
备注:内容来源于stack exchange,提问作者Claude Mutela

