Ubuntu Server更新时出现es.archive.ubuntu.com解析失败DNS问题求助
Hey there, I’ve dealt with this exact DNS issue a few times on Ubuntu servers without resolvconf, so let’s walk through the fixes step by step.
First: Verify Your /etc/network/interfaces Config
First off, double-check that your DNS settings are correctly added in /etc/network/interfaces. You should have a dns-nameservers line under your network interface block, like this:
Example valid config snippet:
auto eth0 iface eth0 inet static address 192.168.1.100 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 8.8.8.8 8.8.4.4 # Google Public DNS servers
If this line is missing or has invalid DNS addresses, add correct ones first.
Step 1: Temporary DNS Fix (Test If It Works)
Since you don’t have resolvconf, Ubuntu won’t automatically populate /etc/resolv.conf from your interfaces file. Let’s manually set it up to test:
- Back up your empty resolv.conf first:
sudo cp /etc/resolv.conf /etc/resolv.conf.bak - Edit the file with a text editor:
sudo nano /etc/resolv.conf - Add these lines (use any reliable DNS servers you prefer):
nameserver 8.8.8.8 nameserver 8.8.4.4 - Save and exit (Ctrl+O, Enter, then Ctrl+X in nano).
- Test if resolution works:
ping es.archive.ubuntu.com
If you get responses, the DNS issue is resolved temporarily. Now let’s make this permanent.
Step 2: Permanent Fix (Prevent resolv.conf From Being Overwritten)
Ubuntu might use tools like systemd-resolved that overwrite /etc/resolv.conf automatically. Here’s how to lock in your static DNS:
- Check if systemd-resolved is running:
systemctl status systemd-resolved - If it’s active, disable and stop it:
sudo systemctl disable --now systemd-resolved - If
/etc/resolv.confis a symbolic link (common with systemd-resolved), remove it:sudo rm /etc/resolv.conf - Recreate the static resolv.conf file with your DNS servers (same as step 1):
sudo nano /etc/resolv.conf - Make the file immutable so no service can overwrite it:
sudo chattr +i /etc/resolv.conf
Step 3: Reload Network Settings
Finally, restart your network service to ensure all changes take effect:
sudo systemctl restart networking # Or for older Ubuntu versions: # sudo /etc/init.d/networking restart
Test the update command again:
sudo apt update
It should now resolve the repository URL without errors.
内容的提问来源于stack exchange,提问作者Yus

