Linux users, particularly system administrators and developers, may occasionally encounter the frustrating error message: “Temporary failure in name resolution.” This issue typically means that the system is having trouble resolving hostnames into IP addresses using DNS (Domain Name System) services. Without proper DNS resolution, connecting to websites, remote repositories, or other services becomes impossible.
TL;DR (Too long, didn’t read)
The error “Temporary failure in name resolution” usually indicates a DNS issue. Most often, it’s related to misconfigured /etc/resolv.conf, network interface issues, or problems with systemd-resolved. Ensuring correct DNS settings, restarting network services, or using a static DNS entry (like Google’s 8.8.8.8) can resolve the problem. Follow the step-by-step guide below to troubleshoot thoroughly.
Common Causes of the “Temporary Failure in Name Resolution” Error
There are multiple root causes that can result in this error. Before diving into fixes, it’s important to understand what typically causes the issue:
- DNS server misconfiguration
- Corrupted or missing /etc/resolv.conf file
- Issues with systemd-resolved
- Incorrect network manager settings
- No active internet connection or broken interface
Step-by-Step Fixes
1. Check Network Connection
Before troubleshooting deeper, verify that the network connection is up:
ping -c 4 8.8.8.8
If the ping works, you’re connected to the internet, and the issue lies in DNS. If not, resolve network connectivity issues first.
2. Inspect and Fix /etc/resolv.conf
This file tells your system which DNS servers to use. Check if it exists and is properly configured:
cat /etc/resolv.conf
If the file is missing entries or looks empty/corrupted, manually add valid DNS servers:
sudo nano /etc/resolv.conf
Insert the following content:
nameserver 8.8.8.8
nameserver 1.1.1.1
Note: These are Google and Cloudflare DNS servers, both of which are public and reliable.
3. Prevent /etc/resolv.conf from Being Overwritten
In many systems, resolv.conf is auto-generated. To prevent your changes from being overwritten:
sudo chattr +i /etc/resolv.conf
This locks the file from being altered. Use sudo chattr -i to unlock it if needed later.
4. Restart Network Services
After changes, you may need to restart networking services to apply them:
sudo systemctl restart NetworkManager
Or for systems using traditional networking.service:
sudo systemctl restart networking
5. Flush DNS Cache
Flushing the DNS cache can help in case cached DNS entries are stale or corrupted:
sudo systemd-resolve --flush-caches
To verify cached nameservers, run:
systemd-resolve --statistics
6. Use systemd-resolved (for systemd-based systems)
Many modern Linux distributions use systemd-resolved. Make sure it’s running:
sudo systemctl enable systemd-resolved
sudo systemctl start systemd-resolved
Create a symbolic link for /etc/resolv.conf if it’s not automatically linked to /run/systemd/resolve/stub-resolv.conf:
sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
7. Disable IPv6 (Optional)
Sometimes DNS-related issues stem from IPv6 misbehavior, especially on older systems. To disable it temporarily:
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
To make it permanent, add the following lines to /etc/sysctl.conf.
8. Set Static DNS in Network Configuration Files
For users managing servers or using static IP configurations, editing network configuration files directly is another option.
On Debian/Ubuntu:
Edit /etc/network/interfaces and add:
dns-nameservers 8.8.8.8 1.1.1.1
On RHEL/CentOS:
Edit the interface script under /etc/sysconfig/network-scripts/ifcfg-eth0 and add:
DNS1=8.8.8.8
DNS2=1.1.1.1
9. Check Firewall or Proxy Settings
Firewalls and proxies — whether set up on the system or the network — can block DNS. Tools like ufw or iptables can be used to review and modify rules:
sudo iptables -L -n
If DNS traffic (often UDP port 53) is blocked, allow it using your firewall tool.
10. Try Alternative DNS Tools
If the issue persists, tools like dig and nslookup are useful for pinpointing what’s wrong:
dig google.com
nslookup google.com
If these tools return errors similar to “no servers could be reached,” DNS is still misconfigured or blocked.
Tips and Best Practices
- Always test connectivity with both IP addresses and domain names to isolate DNS-specific failures.
- Back up configuration files like resolv.conf before making changes.
- For scripting and automation, use permanent configurations over temporary workarounds.
- Use monitoring tools to detect DNS resolution issues early.
Conclusion
The “Temporary failure in name resolution” error is fairly common and often solvable by ensuring correct DNS configuration, restoring or modifying the /etc/resolv.conf file, restarting affected services, or checking network interfaces. By diagnosing step by step, it becomes much easier to trace the problem back to its source and apply the right remedy efficiently.
Frequently Asked Questions (FAQ)
- Q: What causes the “Temporary failure in name resolution” error in Linux?
- A: It’s usually caused by incorrect or missing DNS configuration in /etc/resolv.conf or network interface issues.
- Q: How do I manually set DNS in Linux?
- A: Edit
/etc/resolv.confand add lines likenameserver 8.8.8.8. Lock the file afterward usingchattr +ito prevent overwrites. - Q: Why does my /etc/resolv.conf keep changing?
- A: Network managers or systemd services regenerate it. Use
chattr +ior configure your network manager properly to set fixed DNS rules. - Q: Is using Google DNS (8.8.8.8) safe?
- A: Yes, it’s widely used and considered reliable. Alternatives include

