Troubleshooting & Comparisons

How to Fix DNS Not Resolving Issues on Linux

Discover how to troubleshoot and resolve DNS not resolving errors on Linux systems effectively.

4 min read

Discover how to troubleshoot and resolve DNS not resolving issues on Linux systems effectively.

Symptom of DNS Not Resolving

A DNS resolution issue manifests through clear symptoms that interrupt normal internet operation. Common signs include:

  • Error message: 'Temporary failure in name resolution' appears when attempting to use domain names.
  • Connectivity issues: Domain-based services such as websites, package managers, or APIs fail to function properly.
  • IP reachability: Systems can still ping IP addresses directly but fail with domain names.

These symptoms indicate issues with DNS configuration or functionality, rather than broader network problems.

Confirming the Network is Operational

Before focusing on DNS, it's crucial to differentiate between DNS and network errors.

steps

  1. Open a terminal.
  2. Ping a known IP address:
    bash
    ping 8.8.8.8
    • Getting successful replies confirms the network is stable.
    • No reply indicates a broader connectivity issue requiring investigation.
  3. DNS troubleshooting begins only if IP connectivity is confirmed.

Check the System’s DNS Configuration

The next step involves verifying where Linux is directing DNS queries.

View /etc/resolv.conf

cat /etc/resolv.conf
# Expected output should include the DNS resolver:
# nameserver 127.0.0.53

This file defines the system's DNS settings. A common configuration on Linux uses 127.0.0.53 (systemd-resolved). If misconfigured, DNS will fail.

Resolving the Problem

Follow these steps to correct DNS issues once identified:

steps

  1. Restart systemd-resolved:
    bash
    sudo systemctl start systemd-resolved
  2. Verify DNS servers using systemd-resolved:
    bash
    resolvectl status
    • Confirm the list of DNS servers. If empty or incorrect, DNS resolution won't work.
  3. Temporarily set a known DNS server:
    bash
    sudo resolvectl dns eth0 8.8.8.8
    • Replace eth0 with your network interface name. Use a public DNS server like Google (8.8.8.8) or Cloudflare (1.1.1.1).
  4. Test DNS resolution:
    bash
    resolvectl query google.com
    ping google.com
    • These commands validate whether DNS is now functional.
  5. Optional permanent configuration:
    • Editing system files for persistent changes is beyond this guide but enables settings retention after reboot.

Common Mistakes in DNS Troubleshooting

Avoid these frequent missteps when fixing DNS-related issues:

Importance of Systemd-resolved Service

The systemd-resolved service is integral to DNS resolution on modern Linux distributions. If the service fails or stops unexpectedly, DNS resolution breaks.

Check its status with:

Check systemd-resolved service status

sudo systemctl status systemd-resolved
# Restart if necessary using:
sudo systemctl restart systemd-resolved

This service handles local DNS queries and manages resolver configuration. Ensuring it's correctly configured and operational is foundational to a stable DNS setup.

Next Steps

DNS troubleshooting requires a structured approach, starting with diagnostics, addressing immediate issues, and implementing long-term solutions.

FAQ

How can I fix 'Temporary failure in name resolution' permanently?

To fix this permanently, configure your DNS settings via your network manager or the systemd-resolve configuration files. Avoid direct editing of resolv.conf.

Why does my /etc/resolv.conf reset after reboot?

On systems using systemd-resolved, resolv.conf is auto-generated during boot. Modify DNS using resolvectl or configure persistent settings through the network manager.

What should I do if restarting systemd-resolved fails to fix DNS?

If restarting systemd-resolved does not help, ensure valid DNS servers are specified through resolvectl, or test alternate servers like Google DNS (8.8.8.8) or Cloudflare DNS (1.1.1.1).

Does DNS affect my ability to reach websites?

Yes, DNS resolves domain names to IP addresses, which are essential for connecting to websites. Without functioning DNS, only IP-based connections work.


Official reference: resolv.conf manual page.