How to fix W: Failed to fetch URL Temporary failure resolving 'hostname' in APT

APTINTERMEDIATEHIGHUpdated Dec 29, 2025· 527 views

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
  1. Verify internet connectivity first
  2. Check current DNS configuration
  3. Add DNS servers manually (temporary fix)
  4. Configure DNS permanently (systemd-resolved)
apt — error
# Ping Google's public DNS server
ping -c 4 8.8.8.8
W: 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

  1. DNS servers are not configured or are unreachable
  2. The systemd-resolved service is not running or not properly configured
  3. /etc/resolv.conf is empty or has incorrect nameserver entries
  4. Network interface is not properly configured or connected
  5. Firewall or proxy is blocking DNS port 53 (UDP/TCP)
  6. Running inside a container (Docker, LXC) without proper DNS configuration
  7. Network timeout or temporary DNS service disruption

How to fix "W: Failed to fetch URL Temporary failure resolving 'hostname'"

1Verify internet connectivity first

Before troubleshooting DNS, confirm your network connection is working:

bash
# Ping Google's public DNS server
ping -c 4 8.8.8.8

If 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.

2Check current DNS configuration

View what DNS servers your system is currently configured to use:

bash
cat /etc/resolv.conf

You 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:

bash
sudo systemctl status systemd-resolved

You should see active (running) in the output.

3Add DNS servers manually (temporary fix)

As a quick fix, add Google's public DNS servers:

bash
sudo tee /etc/resolv.conf > /dev/null << EOF
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF

Then test:

bash
apt update

Note: This change may not persist after reboot if systemd-resolved rewrites the file.

4Configure DNS permanently (systemd-resolved)

For Ubuntu 18.04+ systems using systemd-resolved, edit the resolver configuration:

bash
sudo nano /etc/systemd/resolved.conf

Uncomment or add these lines:

ini
[Resolve]
DNS=8.8.8.8 8.8.4.4
FallbackDNS=1.1.1.1 1.0.0.1

Save the file (Ctrl+X, then Y, then Enter).

Restart the service:

bash
sudo systemctl restart systemd-resolved

Verify the fix:

bash
systemd-resolve --status
apt update
5Configure DNS permanently (older systems)

On systems using NetworkManager or older Debian/Ubuntu versions:

bash
sudo nano /etc/resolv.conf

Add Google's DNS servers:

bash
nameserver 8.8.8.8
nameserver 8.8.4.4

Make the file immutable to prevent it from being overwritten:

bash
sudo chattr +i /etc/resolv.conf

To later undo this: sudo chattr -i /etc/resolv.conf

6Test DNS resolution

Verify that DNS is now working:

bash
# Test DNS resolution
nslookup archive.ubuntu.com

# Or use host command
host archive.ubuntu.com

# Or use dig
dig archive.ubuntu.com

You should see the IP address in the output. If this succeeds, apt should now work:

bash
sudo apt update
sudo apt install -y <package-name>
7Fix DNS in Docker containers

If this error occurs inside a Docker container, configure Docker's DNS settings.

Temporary fix (for one container):

bash
docker run --dns 8.8.8.8 --dns 8.8.4.4 <image-name>

Permanent fix (edit Docker daemon config):

bash
sudo nano /etc/docker/daemon.json

Add or modify:

json
{
  "dns": ["8.8.8.8", "8.8.4.4"]
}

Restart Docker:

bash
sudo systemctl restart docker

Advanced 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:

bash
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo apt update
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0

Systemd-resolved with netplan: On Ubuntu 20.04+, network configuration uses netplan. To configure DNS through netplan instead of editing resolved.conf:

bash
sudo nano /etc/netplan/00-installer-config.yaml

Add under the network interface:

yaml
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:

bash
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

Network Manager: If using NetworkManager, you can configure DNS through the GUI or:

bash
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.

Official resources & further reading