# What Does “Name or Service Not Known” Mean and How To Fix It

> In this post, we will explore what this message means, what could cause this message, and different solutions to those issues.

- Author: [CJ Saathoff](https://www.namehero.com/blog/author/cj-saathoff/)
- Published: 2024-11-19
- Updated: 2024-11-19
- Category: [Linux Command Line](https://www.namehero.com/blog/category/linux-command-line/)
- Web page: https://www.namehero.com/blog/what-does-name-or-service-not-known-mean-and-how-to-fix-it/

[![](https://blogcdn.namehero.com/blog/wp-content/uploads/2024/11/18085423/servicemean-1024x576.jpg)](https://blogcdn.namehero.com/blog/wp-content/uploads/2024/11/18085423/servicemean.jpg)

Have you encountered the following error message “Name or Service Not Known” while working on your Linux system? If so you have come to the right place. In this post, we will explore what this message means, what could cause this message, and different solutions to those issues.

## Understanding The Error Message

This error occurs because a hostname or service name is unable to be resolved to an IP or port respectively.

For example, if you try to ping domain names that don’t exist such as:

```

cj@example:~$ ping nonexistentdomain.example
ping: nonexistentdomain.example: Name or service not known

```

Typically, with this error message, you will see the application, the hostname, or the service, followed by the error message.

## Identifying The Root Cause

Context is important in narrowing down the root cause:

1. The error occurs when making a network connection and is being used to represent the hostname or domain of a specific host then this would be considered a DNS issue.
2. The error occurs when being used to reference a port rather than a host then it would be considered an issue related to service name resolution.

## Cause 1: DNS Issues

The most common cause of this error message is DNS (domain name resolution) related issues. DNS records are how a domain name is translated to IP addresses.

Before we jump in ask yourself do you expect this hostname to be valid, could it be that it is misspelled, or invalid? For external domains do you have a working internet connection, do you have working DNS servers configured, have you checked the domain name using an online DNS checker, does it resolve for the rest of the internet?

Excluding the above this should leave DNS configuration issues or local DNS records issues.

First, confirm that your machine’s DNS configured is set up as foreseen. To do that run the command below to check /etc/resolv.conf and systemd-resolved:

```

{ echo "=== /etc/resolv.conf ==="; cat /etc/resolv.conf | grep '^nameserver'; echo "=== NetworkManager ==="; nmcli device show | grep 'IP4.DNS'; echo "=== systemd-resolved ==="; resolvectl status | grep "DNS Servers" -A2; } 2>/dev/null

```

For local issues where DNS is set up on the host itself, you can add the record to your systems host file which is located at /etc/hosts using the following syntax:

IP Address + space + the domain

```

 203.0.113.119 hostfileexample.local

```

Note: be aware that to edit the /etc/hosts file you will need root or sudo permissions.

## Cause 2: Service Name Resolution

If the name being mentioned is referring to a service name these are specified in /etc/services and map specific service names to port number and protocol.

To resolve issues with service names either add a new entry in that file or directly specify the port and protocol directly.

## Did You Know?

Have you ever wondered how many files are checked every time a DNS lookup is made on your system? Even if you haven’t, it is intriguing to think about, isn’t it? The below strace command which counts the files opened for both the ping command and dig commands:

```

strace -e trace=file ping -c 4 namehero.com 2>&amp;1 | grep open | wc -l

```

```

strace -e trace=file dig namehero.com 2>&amp;1 | grep open | wc -l

```

## Additional Links

Done reading and looking for more, why not check these out?

- [The Dig Command](https://www.namehero.com/blog/the-linux-dig-command-what-you-need-to-know/)
- [How to Flush Linux DNS Cache](https://www.namehero.com/blog/understanding-dns-cache-how-to-flush-dns-on-linux/)
- [How to configure A Static IP On Ubuntu](https://www.namehero.com/blog/how-to-configure-static-ip-address-in-ubuntu/)

## Related posts

- [How To Fix Could Not Get Lock /var/lib/dpkg/lock-frontend Error On Debian And Ubuntu](https://www.namehero.com/blog/how-to-fix-could-not-get-lock-var-lib-dpkg-lock-frontend-error-on-debian-and-ubuntu/)
- [How To Fix ERR_NAME_NOT_RESOLVED: A Quick Guide](https://www.namehero.com/blog/how-to-fix-err_name_not_resolved-a-quick-guide/)
- [How to Fix the “DNS Server Not Responding” Error](https://www.namehero.com/blog/how-to-fix-the-dns-server-not-responding-error/)
- [What Is ERR_CERT_COMMON_NAME_INVALID, And How Can You Fix It?](https://www.namehero.com/blog/what-is-err_cert_common_name_invalid-and-how-can-you-fix-it/)
