How to Resolve “temporary failure in name resolution” Error


Domain Name resolution is the phenomenon where the IP addresses are translated/resolved into human-readable names and vice versa. DNS (Domain Name System) manages the database where the domain names are resolved/mapped with the IP addresses. Whenever any connection is requested by domain name, the DNS translates it into the IP address and then connects you with that.

While accessing any website or internet, you might have come across the “temporary failure in name resolution”. This error does not allow your system to translate/go through DNS. In short, you won’t be able to work. That’s how dangerous this error is.

This post will address the reasons and the possible solutions to fix it.

Outline:

How to Resolve “temporary failure in name resolution” Error

In Ubuntu, the domain name resolution depends on multiple factors, internet/network not working, resolv.conf file, system-reloved service, firewall ports (43 and 53), or DNS Cache. Any of these, if misconfigured, results in “temporary failure in name resolution”.

All the above-stated factors are addressed here. How do these factors contribute to invoking a “temporary failure in name resolution” error and also the solution to each reason.

Let’s start with the basic one that needs to be dealt with priority:

Reason 1: Network-Related Issues

You might be wondering, why network? It is about DNS. The final result of the resolver library depends on the internet connection. If the internet/network is not stable, then you might also get “temporary failure in name resolution”.

Solution: Check the Internet Connection and Fix it

First, Restart your NetworkManager and check its status:

sudo systemctl restart NetworkManager

sudo systemctl status NetworkManager

You must check the internet connectivity that you are receiving from the ISP, i.e., restart the router, and check the WIFI/Ethernet working properly.

Note: If this has not fixed the networking then check that you might be using the static IP address which is not set/configured properly. In such a case, your Networking service will be disabled. Check out this post to correctly configure the Static IP address on Ubuntu.

Reason 2: Misconfigured resolv.conf File

This is the main configuration file of your DNS. This file contains the nameservers your resolver library will interact with to resolve the IP addresses and domain names. If your resolver library cannot get a response from your nameservers, you will get “temporary failure in name resolution”. Similarly, the permissions of this file also matter which allows/blocks the specific user to read/write or own the file.

Solution: Reconfigure the resolv.conf File

The resolv.conf file is available at the “/etc/resolv.conf” location, where you will find the nameserver your system looks for whenever a DNS is triggered. By default, Ubuntu has the loopback address in this file which then redirects to the DNS.

If the redirection is not working through the loopback address (local machine), you can directly use the recommended DNS (here we are using Google’s DNS 8.8.8.8). To do so, open the “/etc/resolv.conf” file in any editor and replace the loopback address with 8.8.8.8:

Save and exit out of the editor. Access any web address, i.e., we accessed linuxgenie.net:

In our case, the DNS is now being accessed correctly.

Optional: Configure the Permission for the resolv.conf File

If setting/changing the DNS in the “/etc/resolv” file has not worked. You must look for the permissions (recommended is 644) and ownership (must be the root) of the file. If the permissions and the owner of the resolv.conf file is not set, you might not be able to access the correct DNS. here are the commands to configure the “/etc/resolv.conf” file for the correct owner and permissions:

sudo chown root:root /etc/resolv.conf
sudo chmod 644 /etc/resolv.conf

Reason 3: Systemd-Resolved Service Not Responding

When a user types and wishes to visit the website. The systemd-resolved service finds the cache in the previously resolved caches. Then it ensures the data integrity using Domain Name System Security Extension (DNSSE). The systemd-resolved service loads the configured DNS and if it is not correctly configured, you will get the “temporary failure in name resolution”.

Solution: Fix/Reconfigure the Systemd-Resolved Service

The systemd-resolved service gets you to the configured DNS. Let’s check how it can be fixed:

Configure(Restart) the Systemd-Service

First, you need to review the current configurations of the systemd-resolved using the command:

sudo systemctl status systemd-resolved

As in our case, upon checking the status, it has shown an error. Now, restart the service and check its status:

sudo systemctl restart systemd-resolved

sudo systemctl status systemd-resolved

Note: If the error is not fixed in your case, you need to add the DNS to the resolved.conf file.

Add the DNS to the “resolved.conf”

Open the file in any editor:

sudo nano /etc/systemd/resolved.conf

Clearly mention the DNS address and the Fallback DNS. The Fallback DNS is also referred to as the emergency DNS used when the primary DNS is not working. Doing so, your system has two options for DNS:

[Resolve]
DNS=8.8.8.8
FallbackDNS=8.8.4.4

Note: Restart the systemd-resolved service to check the changes.

Reason 4: Firewall Restrictions

DNS is configured for Ports 53/UDP and 43/TCP. The DNS queries are addressed via Port 53/UDP. However, if the response time for UDP increases then DNS acquires TCP support. If these ports are not configured/opened, the DNS won’t be resolved hence the name resolution error occurs.

Solution: Allow Traffic Through Port 43/TCP and 53/UDP

Here, you need to allow the recommended ports. Use the command as per your system.

For Debian/Ubuntu-based distributions (that manages the firewall using the ufw utility):

sudo ufw allow 43/tcp
sudo ufw allow 53/udp
sudo ufw reload

For CentOS/Fedora/RHEL-inspired Linux distributions:

sudo firewall-cmd --add-port=43/tcp --permanent
sudo firewall-cmd --add-port=53/udp --permanent

Reason 5: Overflooded DNS Cache

Your system keeps the record of your DNS up to some time. If the DNS cache is flooded, your firewall starts blocking the DNS request, which ultimately leads to “temporary failure in name resolution”.

Solution: Flush the DNS Cache

Ubuntu 22.04 comes with the resolvectl command to manage the DNS cache. The below command flushes the DNS cache using the resolvectl command:

sudo resolvectl flush-caches

Verify the status/the DNS cache has been flushed or not:

sudo resolvectl statistics

Note; For Older Ubuntu (20.04)

The following command also does the same. It flushes the DNS cache and all other caches associated with the “systemd-resolved”:

sudo systemd-resolve --flush-caches

That’s how you can fix the “temporary failure in name resolution”.

Bottom Line

To resolve the “temporary failure in name resolution” error, you need to either fix your internet connection, configure the resolv.conf file/resolved.conf files set the firewall rules, or flush the DNS cache. You just need to diagnose where the problem is and then apply the respective solution. If you are unsure, then start from solution 1 and keep on following the other solutions until you get rid of the “temporary failure in name resolution” error.

This post has listed all the possible reasons that invoke the “temporary failure in the name resolution” error and its potential solutions.

Print Friendly, PDF & Email
Categories