How to fix W: Failed to fetch URL Temporary failure resolving 'hostname' in APT
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.
Quick fix
Fixes W: Failed to fetch URL Temporary failure resolving 'hostname'
# Ping Google's public DNS server
ping -c 4 8.8.8.8- Verify internet connectivity first
- Check current DNS configuration
- Add DNS servers manually (temporary fix)
- Configure DNS permanently (systemd-resolved)
# Ping Google's public DNS serverping -c 4 8.8.8.8W: Failed to fetch URL Temporary failure resolving 'hostname'
What this error means
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.
Typical symptoms
- apt update fails with hostname resolution errors
- apt install commands hang or fail at the 'Fetching' stage
- DNS works for some services but not for apt repositories
- Error message includes 'W: Failed to fetch URL' followed by the hostname
- ping command can reach numeric IP addresses but fails on domain names
Common causes
- DNS servers are not configured or are unreachable
- The systemd-resolved service is not running or not properly configured
- /etc/resolv.conf is empty or has incorrect nameserver entries
- Network interface is not properly configured or connected
- Firewall or proxy is blocking DNS port 53 (UDP/TCP)
- Running inside a container (Docker, LXC) without proper DNS configuration
- Network timeout or temporary DNS service disruption
How to fix "W: Failed to fetch URL Temporary failure resolving 'hostname'"
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 dockerAdvanced notes
IPv6 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>Frequently asked questions
- What does "W: Failed to fetch URL Temporary failure resolving 'hostname'" mean?
- 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.
- How do I fix "W: Failed to fetch URL Temporary failure resolving 'hostname'"?
- 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.
- What causes "W: Failed to fetch URL Temporary failure resolving 'hostname'"?
- DNS servers are not configured or are unreachable The systemd-resolved service is not running or not properly configured /etc/resolv.conf is empty or has incorrect nameserver entries
- Is the "W: Failed to fetch URL Temporary failure resolving 'hostname'" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.