This error occurs when apt cannot resolve the domain name for package repositories due to DNS configuration issues or network connectivity problems. Common causes include missing DNS servers, network interface misconfiguration, or systemd-resolved service issues.
When apt attempts to fetch packages from repositories, it needs to resolve the repository's hostname (e.g., archive.ubuntu.com) to an IP address. This error means the system's DNS resolver cannot translate the hostname into an IP address. This is typically a network configuration issue rather than a problem with apt itself. The error can occur during 'apt update' or when installing packages.
Before troubleshooting DNS, confirm your network connection is working:
# Ping Google's public DNS server
ping -c 4 8.8.8.8If this fails, your system has no internet connection. Check your network cable, WiFi, or contact your ISP.
If the ping succeeds but apt still fails, you have a DNS-specific issue.
View what DNS servers your system is currently configured to use:
cat /etc/resolv.confYou should see at least one nameserver line. If the file is empty or missing, that's your problem.
On newer Ubuntu/Debian systems (18.04+), DNS is managed by systemd-resolved. Check its status:
sudo systemctl status systemd-resolvedYou should see active (running) in the output.
As a quick fix, add Google's public DNS servers:
sudo tee /etc/resolv.conf > /dev/null << EOF
nameserver 8.8.8.8
nameserver 8.8.4.4
EOFThen test:
apt updateNote: This change may not persist after reboot if systemd-resolved rewrites the file.
For Ubuntu 18.04+ systems using systemd-resolved, edit the resolver configuration:
sudo nano /etc/systemd/resolved.confUncomment or add these lines:
[Resolve]
DNS=8.8.8.8 8.8.4.4
FallbackDNS=1.1.1.1 1.0.0.1Save the file (Ctrl+X, then Y, then Enter).
Restart the service:
sudo systemctl restart systemd-resolvedVerify the fix:
systemd-resolve --status
apt updateOn systems using NetworkManager or older Debian/Ubuntu versions:
sudo nano /etc/resolv.confAdd Google's DNS servers:
nameserver 8.8.8.8
nameserver 8.8.4.4Make the file immutable to prevent it from being overwritten:
sudo chattr +i /etc/resolv.confTo later undo this: sudo chattr -i /etc/resolv.conf
Verify that DNS is now working:
# Test DNS resolution
nslookup archive.ubuntu.com
# Or use host command
host archive.ubuntu.com
# Or use dig
dig archive.ubuntu.comYou should see the IP address in the output. If this succeeds, apt should now work:
sudo apt update
sudo apt install -y <package-name>If this error occurs inside a Docker container, configure Docker's DNS settings.
Temporary fix (for one container):
docker run --dns 8.8.8.8 --dns 8.8.4.4 <image-name>Permanent fix (edit Docker daemon config):
sudo nano /etc/docker/daemon.jsonAdd or modify:
{
"dns": ["8.8.8.8", "8.8.4.4"]
}Restart Docker:
sudo systemctl restart dockerIPv6 Issues: If your system has IPv6 misconfigured, apt may prefer IPv6 and fail when only IPv4 DNS works. Temporarily disable IPv6 to test:
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo apt update
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0Systemd-resolved with netplan: On Ubuntu 20.04+, network configuration uses netplan. To configure DNS through netplan instead of editing resolved.conf:
sudo nano /etc/netplan/00-installer-config.yamlAdd under the network interface:
nameservers:
addresses: [8.8.8.8, 8.8.4.4]Apply: sudo netplan apply
Alternate public DNS: If Google's DNS doesn't work in your region, try Cloudflare (1.1.1.1) or Quad9 (9.9.9.9).
Persistent /etc/resolv.conf: If using systemd-resolved, symlink the dynamic config:
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.confNetwork Manager: If using NetworkManager, you can configure DNS through the GUI or:
nmcli con mod <connection-name> ipv4.dns "8.8.8.8 8.8.4.4"
nmcli con up <connection-name>dpkg: serious warning: files list file for package 'package-name' contains empty filename
How to fix "files list file contains empty filename" in APT
E: Sub-process /usr/bin/dpkg returned an error code (2)
How to fix "Sub-process /usr/bin/dpkg returned an error code (2)" in APT
dpkg-divert: error: rename involves overwriting 'path' with different file
How to fix dpkg-divert rename conflicts in APT
E: Sub-process /usr/bin/dpkg returned an error code (1) during kernel installation
How to fix "dpkg returned an error code (1)" in APT kernel installation
dpkg: dependency problems prevent configuration of triggers
dpkg: dependency problems prevent configuration of triggers in apt