Fix "Temporary Failure in Name Resolution" on Linux

By 

•

Published on

•

8 min read

A network switch with an unplugged Ethernet cable beside the words Temporary Failure in Name Resolution

You run apt update or try to ping a host, and Linux reports that it could not resolve the name.

output
ping: example.com: Temporary failure in name resolution

APT reports the same failure as Temporary failure resolving 'archive.ubuntu.com', and SSH as ssh: Could not resolve hostname github.com: Temporary failure in name resolution.

The system resolver could not return an address for the hostname. The same lookup may work on another attempt. A DNS server might have timed out, returned a server failure, or been unreachable through your current connection.

This guide shows how to check where the lookup failed and fix the DNS settings for the connection you are using. We tested the system resolver examples on Ubuntu 26.04.1 LTS.

Test the System Resolver

Run getent ahosts from the same machine or container where you saw the error. Use the failing hostname first, then try a hostname you expect to resolve.

Terminal
getent ahosts archive.ubuntu.com
getent ahosts example.com

getent ahosts uses the system’s hostname lookup settings, which can include /etc/hosts and DNS. It prints addresses on success. If the lookup fails, getent prints nothing and exits with status 2. If only one name fails, check its spelling and whether it requires a VPN or a particular DNS server. If both fail, check the network and the configured resolver.

Check the Network by IP Address

Use the ip command to see which route Linux would use to reach a public IPv4 address. On an IPv6-only network, use an IPv6 destination with ip -6 route get instead.

Terminal
ip route get 1.1.1.1
ping -c 2 -W 2 1.1.1.1

A route shows that Linux knows where to send the packets. A ping reply shows that this destination is reachable over ICMP. Some networks block ICMP, so a timeout alone leaves the result inconclusive. If Linux reports that the network is unreachable, check the interface, gateway, or VPN route before changing DNS settings.

Check Who Manages DNS

Start by looking at /etc/resolv.conf and checking whether systemd-resolved is active.

Terminal
ls -l /etc/resolv.conf
cat /etc/resolv.conf
systemctl is-active systemd-resolved

On a typical Ubuntu installation, /etc/resolv.conf points to /run/systemd/resolve/stub-resolv.conf and lists 127.0.0.53. That address belongs to the local systemd-resolved stub. To see where it sends queries, check the global and per-interface DNS settings.

Terminal
resolvectl status
resolvectl query example.com

On our test system, the interface section of resolvectl status looks like this:

output
Link 2 (enp0s1)
    Current Scopes: DNS
         Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 10.0.2.3
       DNS Servers: 10.0.2.3
     Default Route: yes

Look for DNS Servers under the interface that should resolve the name. A DNS Domain line appears only when the connection sets a search domain. A VPN may have its own DNS servers and domains. If the stub is configured but the service is inactive, check why it stopped .

Other setups use a different symlink or list upstream DNS servers directly. If NetworkManager, a DHCP client, or another service writes the file, make persistent changes in that service’s configuration. If you maintain a static /etc/resolv.conf yourself, check its nameserver entries.

Query the DNS Server Directly

If dig is already installed, send a query to the server your connection uses. Replace 10.0.2.3 with the address you found above.

Terminal
dig @10.0.2.3 example.com +time=2 +tries=1

The default query asks for an IPv4 address. Add AAAA after the hostname to check for IPv6. Read the status: field and look for an address in the answer section. A working lookup shows NOERROR and an address. NXDOMAIN means the server reports that the name does not exist. SERVFAIL means the server could not complete the lookup.

When the server does not answer at all, dig reports a communications error that ends in timed out, followed by:

output
;; no servers could be reached

In that case, check the route to that server and whether DNS traffic is allowed on that connection.

If dig returns an address for the failing name but getent ahosts does not, check which resolver and search domains the system uses. For a public hostname, you can also compare the answer with one from a public resolver. Use the network’s DNS server for internal names. If dig is missing and your package manager cannot resolve its repositories, continue with getent and, on systems that use it, resolvectl.

Repair the systemd-resolved Stub

If your system uses the local stub and the service is inactive, check its status and recent logs.

Terminal
systemctl status systemd-resolved
sudo journalctl -u systemd-resolved -n 30 --no-pager

If the service was stopped on a system that uses it, start it with sudo systemctl start systemd-resolved and test the lookup again.

If the service is active and your installation normally uses stub mode, a missing or broken symlink can keep applications from reaching the stub. Save a copy of the existing file or link if there is one. Then restore the link only if the service is active and the stub file exists.

Terminal
systemctl is-active --quiet systemd-resolved &&
  test -f /run/systemd/resolve/stub-resolv.conf &&
  sudo ln -sfnT /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf

Run getent ahosts again after restoring the link. If the lookup still fails and the configured DNS server is unreachable, check the connection settings next.

Set the DNS Servers for Your Connection

Change the connection settings after checking that the current server is the problem. The examples use 1.1.1.1 and 1.0.0.1 for public lookups. On a work network or VPN, use the servers assigned for that connection so internal names still resolve.

Test a Temporary Change with resolvectl

On a system that uses systemd-resolved, first record the current DNS servers for the interface. Replace enp0s1 with the interface name shown by resolvectl status.

Terminal
resolvectl dns enp0s1

If the interface lists DNS servers, test a different set and repeat the original lookup.

Terminal
sudo resolvectl dns enp0s1 1.1.1.1 1.0.0.1
getent ahosts example.com

This changes the running resolver settings for that interface. Your network manager can replace them later. To undo the test immediately, run sudo resolvectl dns enp0s1 followed by the original addresses. If the lookup worked with the test servers, save the working settings in the network configuration.

Netplan on Ubuntu Server

On Ubuntu Server with the networkd renderer, edit the existing interface definition under /etc/netplan/. The following example adds DNS servers to an interface that gets its IPv4 address over DHCP. The use-dns: false setting tells Netplan to ignore the DNS servers offered by DHCPv4. Keep the other settings already defined for your interface.

/etc/netplan/50-cloud-init.yamlyaml
network:
  version: 2
  ethernets:
    enp0s1:
      dhcp4: true
      dhcp4-overrides:
        use-dns: false
      nameservers:
        addresses: [1.1.1.1, 1.0.0.1]

Use netplan try to apply the change with a rollback timer. If you are connected over SSH, this gives the system a chance to restore the previous settings if the connection drops.

Terminal
sudo netplan try

Before confirming, check the lookup from a second shell. If the file is generated by cloud-init, check the Netplan guide for where to make persistent changes.

NetworkManager

List active connections with nmcli to get the profile name.

Terminal
nmcli connection show --active

For an IPv4 DHCP connection, set the DNS addresses and ignore the automatic IPv4 DNS settings. That also drops DHCP-provided search domains. If your connection needs them, add them with ipv4.dns-search. Reconnecting can interrupt an SSH session, so apply the change from a local console or another connection.

Terminal
sudo nmcli connection modify "Wired connection 1" ipv4.dns "1.1.1.1 1.0.0.1" ipv4.ignore-auto-dns yes
sudo nmcli connection up "Wired connection 1"

Replace Wired connection 1 with your profile name. If the connection also receives DNS over IPv6, check the IPv6 settings before assuming you have replaced every automatic server. Run getent ahosts for the original hostname to verify the fix.

Troubleshooting

Direct DNS queries work, but applications still cannot resolve names
Check the hosts: line in /etc/nsswitch.conf. It controls the lookup sources and their order. A system may reach DNS through dns or through resolve, which uses systemd-resolved. Compare the line with your distribution’s defaults before changing it. If a stale answer persists after the settings are fixed, flush the DNS cache and retry the lookup.

The firewall blocks DNS to the configured server
If you have confirmed that local UFW rules block the query, allow outbound TCP and UDP on port 53 to the intended resolver. Replace the example address with that server’s IP.

Terminal
sudo ufw allow out to 10.0.2.3 port 53

Run the direct dig query again. If the rule is already in place, check the firewall or routing on the rest of the network path.

DNS fails only inside a Docker container
Inspect /etc/resolv.conf inside the affected container. Docker’s embedded resolver at 127.0.0.11 is expected on a user-defined network.

Terminal
docker exec my-container cat /etc/resolv.conf

Test the name inside the container, for example with docker exec my-container getent ahosts example.com if the image includes getent. If the container needs a different upstream server, recreate it with docker run --dns using a DNS server reachable from that container. The Docker networking documentation explains how containers get their DNS settings.

WSL loses DNS after connecting to a VPN
DNS tunneling is on by default on Windows 11 22H2 and later, so check that your Windows %UserProfile%\.wslconfig does not set dnsTunneling=false under [wsl2]. Tunneling needs WSL to generate /etc/resolv.conf, so remove an existing generateResolvConf=false override from /etc/wsl.conf. Run wsl --shutdown from Windows after saving your work in WSL, then reopen the distro and retry the lookup. See Networking considerations with DNS tunneling in the WSL troubleshooting docs.

Conclusion

Repeat the original command from the same shell, container, or VPN connection where it failed. If public names resolve but an internal name still fails, check which DNS server handles that domain and whether the connection has the right search suffix.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page