How to Fix “Temporary failure in name resolution” on Hetzner Cloud

DNS problem

Hi everyone! Today I want to share a story about a problem with my VPS on Hetzner Cloud. Sometimes, my server could not open any websites. When I tried to ping google.com, I saw this error:

ping: google.com: Temporary failure in name resolution.

But the internet was working! I could ping 8.8.8.8 (Google IP), but I could not use domain names. This is a DNS problem. Here is how I found and fixed it.

Step 1: Check the DNS resolver status

First, I checked my DNS settings with this command:

$ sudo resolvectl status
Global
       Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: stub

Link 2 (eth0)
Current Scopes: none
     Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

In my case, the section “DNS Servers” was empty. My server forgot where to ask for IP addresses. This happens sometimes when the server updates its network settings via DHCP.

Step 2: The temporary fix

To quickly fix the issue you can specify DNS servers manually like

$ sudo resolvectl dns eth0 8.8.8.8 1.1.1.
$ sudo resolvectl domain eth0 "~."

$ ping google.com
PING google.com (142.251.13.100) 56(84) bytes of data.
64 bytes from wt-in-f100.1e100.net (142.251.13.100): icmp_seq=1 ttl=112 time=4.46 ms
64 bytes from wt-in-f100.1e100.net (142.251.13.100): icmp_seq=2 ttl=112 time=7.72 ms

Step 3: The Fix (Permanent)

To fix this permanently, we need to tell the server to always use specific DNS servers (like Google or Cloudflare).

In my case with Ubuntu we’re using Netplan.

Open your netplan config file:

$ sudo nano /etc/netplan/01-netcfg.yaml

Add the nameservers block under your interface (eth0). It should look like this:

network:
  version: 2
  ethernets:
    eth0:
      dhcp4: true
      # our nameservers
      nameservers:
        addresses: [8.8.8.8, 1.1.1.1]

Apply the changes:

$ sudo netplan apply

Step 4: Fix resolv.conf (optional)

You can also specify the nameservers directly in your resolv.conf

Open your resolv.conf file:

sudo nano /etc/systemd/resolved.conf

Append or update DNS servers

[Resolve]
# ...
DNS=8.8.8.8 1.1.1.1
FallbackDNS=8.8.4.4

Apply the changes

$ sudo systemctl restart systemd-resolved

Step 5: Check the result

Now, run the status command again:

$ resolvectl status eth0

root@c1hz:~# resolvectl status eth0
Link 2 (eth0)
    Current Scopes: DNS
         Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 8.8.8.8
       DNS Servers: 8.8.8.8 1.1.1.1
        DNS Domain: ~.

Try to ping google.com again

$ ping google.com
PING google.com (142.251.20.138) 56(84) bytes of data.
64 bytes from bx-in-f138.1e100.net (142.251.20.138): icmp_seq=1 ttl=112 time=4.60 ms
64 bytes from bx-in-f138.1e100.net (142.251.20.138): icmp_seq=2 ttl=112 time=4.24 ms

You May Also Like

About the Author: vo