HomeLinuxHow to Solve “Name or Service Not Known” Error on Linux?

How to Solve “Name or Service Not Known” Error on Linux?

If you’ve worked with Linux systems, you might have encountered the error message: “name or service not known.” This is a common issue, especially when accessing network services or pinging an external domain. In this guide, we’ll break down why this happens and how to fix it, all explained in simple terms.

What Does “Name or Service Not Known” Error Mean?
This error typically points to a problem with DNS resolution. When you see messages like:
hostname: name or service not known
ping: google.com: Name or service not known

It means your system is unable to translate the domain name (like google.com) into an IP address, which is needed to connect to the website or service.

Check Your Internet Connection

Ensure your machine is connected to the internet. Run:

ping -c 4 8.8.8.8

If this command returns responses, your internet connection is likely fine.

Verify DNS Configuration

Your system’s DNS settings are usually found in the /etc/resolv.conf file. Check if the file has valid DNS servers:

cat /etc/resolv.conf

Look for lines like:

nameserver 8.8.8.8
nameserver 8.8.4.4

If you don’t see valid entries, you can add Google’s public DNS servers by editing the file:

sudo nano /etc/resolv.conf

Add:

nameserver 8.8.8.8
nameserver 8.8.4.4

Save and exit the file.

Note: If your system uses a network manager, changes to /etc/resolv.conf might get overwritten. Make sure to check your network manager settings.

Test with a Different Domain

Try pinging another domain to see if the problem is consistent:

ping -c 4 example.com

If you still see the “Name or service not known” error, the issue might be with your DNS setup.

Restart Your Network Service

Sometimes, a simple restart can solve network configuration issues:

sudo systemctl restart NetworkManager

Or, if you’re using a different service:

sudo service networking restart

Double-Check Your Hostname

For issues related to the “hostname: name or service not known” error, ensure your hostname is configured properly:

hostnamectl

If it shows an incorrect or empty hostname, set it using:

sudo hostnamectl set-hostname your-new-hostname

The “Name or service not known” error can be annoying, but you can fix it by referring to this knowledge base without much effort. Now that you know how to troubleshoot this issue, you can keep your system running without interruptions and continue your work seamlessly… 😊

Scroll to Top