Linux  ·  high  ·  Day-to-day operations

Name resolution fails but the network is up

Pings to an IP work and pings to a name do not. On systemd machines /etc/resolv.conf is often a symlink to a stub resolver, which changes where to look.

What you see

curl and apt fail with "Temporary failure in name resolution". `ping 1.1.1.1` works, `ping google.com` does not.

What is actually wrong

No nameserver configured, a stub resolver that has no upstream, a VPN or container that rewrote resolv.conf, or search domains resolving names to the wrong place.

Codes and articles

Temporary failure in name resolutionName or service not knownSERVFAILNXDOMAINresolv.conf

Fixes (2)

Fix systemd-resolved's upstream
Shell as root20 minuteslow riskreversible

resolv.conf points at 127.0.0.53. The real configuration is not in that file.

  1. Ask resolved what it is actually using per interface.

    Shell
    resolvectl status

    Editing /etc/resolv.conf on a resolved system is pointless — it is generated, and your edit is overwritten on the next network change. This command shows the configuration that matters.

  2. Test resolution through the stub and directly, to separate the two.

    Shell
    resolvectl query example.comdig +short example.com @1.1.1.1
  3. If the upstream is empty or wrong, set it on the interface.

    Shell
    sudo resolvectl dns eth0 10.0.0.10 10.0.0.11sudo resolvectl domain eth0 example.local
  4. Make it permanent in the network configuration rather than at runtime. On Ubuntu with netplan:

    Shell
    sudo nano /etc/netplan/01-netcfg.yamlsudo netplan apply
  5. Flush the cache and re-test.

    Shell
    sudo resolvectl flush-cachesgetent hosts example.com
  6. Confirm the symlink is intact — a VPN client that replaced it with a static file causes intermittent failures.

    Shell
    ls -l /etc/resolv.conf
Confirm it workedNames resolve and resolvectl shows the expected servers.
Shell
resolvectl status | grep -A3 'Current DNS'
If you need to undo itsudo resolvectl revert eth0 undoes runtime changes to that interface.
Repair a plain resolv.conf setup
Shell as root20 minuteslow riskreversible

The machine is not using the systemd stub.

  1. Look at the current configuration and the resolution order.

    Shell
    cat /etc/resolv.confgrep '^hosts' /etc/nsswitch.conf
  2. Test the nameserver directly to see whether it is the server or the client.

    Shell
    dig +short example.com @10.0.0.10dig +short example.com @1.1.1.1
  3. Add a working nameserver.

    Shell
    printf 'nameserver 10.0.0.10\nnameserver 1.1.1.1\nsearch example.local\noptions timeout:2 attempts:2\n' | sudo tee /etc/resolv.conf

    The timeout and attempts options matter more than they look: the defaults are 5 seconds and 2 attempts per server, so one dead nameserver stalls every lookup for ten seconds.

  4. Stop NetworkManager or dhclient overwriting it, if that is what keeps happening.

    Shell
    grep -r 'dns=' /etc/NetworkManager/NetworkManager.conf
  5. Make it immutable only as a last resort, and remember you did.

    Shell
    sudo chattr +i /etc/resolv.conf

    This will confuse the next person badly, including you in six months. Prefer configuring the thing that rewrites the file.

Confirm it workedNames resolve consistently after a network restart.
Shell
getent hosts example.com && curl -sS -o /dev/null -w '%{http_code}\n' https://example.com
If you need to undo itsudo chattr -i /etc/resolv.conf, then restore the previous contents.

Where this stops. This write-up was written and checked by hand. It says what each step changes, how to confirm it worked and how to reverse it, and anything destructive is flagged before you reach it. If it does not match what your machine is doing, search the Support Centre for the exact code or message — and when something needs a person, get in touch.