Published: July 6, 2026 | Last updated: July 6, 2026
TL;DR
- The error means DNS resolution failed — your system can’t find the IP address for the hostname you entered (Veeble Hosting, 2024).
- The most common cause is missing or incorrect DNS servers in
/etc/resolv.conf(Huawei Cloud, 2025). - On Ubuntu, check systemd-resolved with
systemctl status systemd-resolvedand verify/etc/resolv.confpoints to 127.0.0.53 (CSDN, 2025). - On CentOS/RHEL, add
nameserver 8.8.8.8to/etc/resolv.confor configure DNS via NetworkManager (Volcengine, 2026). - On Windows, flush DNS cache with
ipconfig /flushdnsand verify your network adapter’s DNS settings (Wiki.ncmir.ucsd.edu, 2026). - If
pingworks with IP addresses but not hostnames, the issue is definitely DNS-related, not a network outage (Baeldung, 2024).
What Causes the “Name or Service Not Known” Error?
This error occurs when your system’s DNS resolver cannot find a mapping between a hostname and an IP address (Baeldung, 2024). The ping command itself works fine — the problem is the name resolution step that happens before ping sends any packets.
The three most common root causes are (Huawei Cloud, 2025):
- Missing or incorrect DNS server addresses in
/etc/resolv.conf— this file tells your system which DNS servers to query - Missing DNS entries in
/etc/nsswitch.conf— this file controls the order of name resolution sources (files, DNS, etc.) - Missing or corrupted DNS library files — such as
/lib64/libnss_dns.so.2on some systems
If you can ping an IP address (like ping 8.8.8.8) but not a hostname (like ping google.com), you have a DNS resolution problem, not a network connectivity problem (Ask Ubuntu, 2022).
Fix for Ubuntu: “Name or Service Not Known” Error
Ubuntu uses systemd-resolved for DNS resolution, with /etc/resolv.conf typically pointing to 127.0.0.53 (the local systemd-resolved stub resolver) (CSDN, 2025). Here are the fixes in order of complexity.
Fix 1: Check systemd-resolved Status
First, verify that the systemd-resolved service is running:
systemctl status systemd-resolved
If it’s not running, start it with:
sudo systemctl start systemd-resolved
sudo systemctl enable systemd-resolved
Also check that /etc/resolv.conf points to 127.0.0.53 (CSDN, 2025). If it doesn’t, you may need to recreate the symlink:
sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
Fix 2: Restart NetworkManager
If NetworkManager is interfering with DNS settings, restart it:
sudo systemctl restart NetworkManager
Fix 3: Configure DNS with netplan (Ubuntu 18.04+)
For Ubuntu versions using netplan (18.04 and newer), add DNS servers to your netplan configuration (CSDN, 2025):
- Edit the netplan configuration file (usually in
/etc/netplan/):
sudo nano /etc/netplan/01-netcfg.yaml
- Add or modify the DNS section:
network:
version: 2
ethernets:
eth0:
dhcp4: true
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
- Apply the changes:
sudo netplan apply
Fix 4: Check /etc/nsswitch.conf
Ensure that dns is included in the hosts line of /etc/nsswitch.conf (Huawei Cloud, 2025). The line should look like:
hosts: files dns
If dns is missing, add it.
Fix for CentOS 7: “Name or Service Not Known” Error
CentOS 7 and other RHEL-based distributions have similar DNS configuration files. Here’s how to fix the error.
Fix 1: Add DNS Servers to /etc/resolv.conf
The quickest fix is to manually add DNS servers to /etc/resolv.conf (Volcengine, 2026; Huawei Cloud, 2025):
sudo nano /etc/resolv.conf
Add these lines:
nameserver 8.8.8.8
nameserver 8.8.4.4
Save the file and test with ping google.com.
Important: On CentOS 7, NetworkManager may overwrite /etc/resolv.conf on reboot. To prevent this, add dns=none to /etc/NetworkManager/NetworkManager.conf under the [main] section (Volcengine, 2026):
[main]
dns=none
Then restart NetworkManager:
sudo systemctl restart NetworkManager
Fix 2: Configure DNS via nmcli
If you’re using NetworkManager, you can set DNS servers with nmcli:
nmcli con mod "YourConnectionName" ipv4.dns "8.8.8.8 8.8.4.4"
nmcli con down "YourConnectionName"
nmcli con up "YourConnectionName"
Fix 3: Check Static IP Configuration
If you’re using a static IP, verify that BOOTPROTO is set correctly in your network interface configuration file (/etc/sysconfig/network-scripts/ifcfg-eth0) (Cloud.baidu.com, 2024). The file should have:
BOOTPROTO=static
ONBOOT=yes
IPADDR=your_static_ip
NETMASK=your_netmask
GATEWAY=your_gateway
DNS1=8.8.8.8
DNS2=8.8.4.4
Fix 4: Check /etc/nsswitch.conf
As with Ubuntu, ensure that /etc/nsswitch.conf includes dns in the hosts line:
hosts: files dns
Fix for Windows: “Name or Service Not Known” Error
On Windows, the error appears as “Name or service not known” when using ping or other network tools. Here’s how to fix it.
Fix 1: Flush the DNS Cache
Flushing the DNS cache removes outdated or corrupted DNS entries (Wiki.ncmir.ucsd.edu, 2026):
- Open Command Prompt as Administrator (search for “cmd”, right-click, select “Run as administrator”)
- Type the following command and press Enter:
ipconfig /flushdns
- You should see: “Successfully flushed the DNS Resolver Cache.”
Fix 2: Verify DNS Settings in Network Adapter
- Open Control Panel > Network and Internet > Network and Sharing Center
- Click “Change adapter settings”
- Right-click your active network adapter and select “Properties”
- Select “Internet Protocol Version 4 (TCP/IPv4)” and click “Properties”
- Ensure DNS server addresses are set correctly — either “Obtain DNS server address automatically” or enter manual DNS servers (8.8.8.8 and 8.8.4.4)
- Click OK and restart your computer
Fix 3: Verify ping.exe Exists
If you get “‘ping’ is not recognized as an internal or external command,” check that ping.exe exists in C:\Windows\System32 (Confluence.zwcad.com, 2026). If not, you may need to restore it from another Windows installation or run System File Checker:
sfc /scannow
Fix for Linux: General Troubleshooting Steps
These fixes apply to most Linux distributions, including Ubuntu, CentOS, Debian, and Fedora.
Fix 1: Check /etc/resolv.conf
This file contains your DNS server addresses. If it’s empty or contains incorrect addresses, add valid DNS servers (Huawei Cloud, 2025):
nameserver 8.8.8.8
nameserver 8.8.4.4
Fix 2: Verify Network Connectivity
Test whether your network connection is working at all:
ping 8.8.8.8
If this works but ping google.com fails, you have a DNS problem, not a network problem (Veeble Hosting, 2024).
Fix 3: Check /etc/nsswitch.conf
Ensure the hosts line includes dns:
hosts: files dns
If dns is missing, add it and save the file (Huawei Cloud, 2025).
Fix 4: Check the Hosts File
The /etc/hosts file can override DNS lookups for specific hostnames. Check if the hostname you’re trying to ping is incorrectly mapped (Yisu.com, 2025):
cat /etc/hosts
If you see an entry for the hostname pointing to an incorrect IP address, edit the file with sudo nano /etc/hosts and remove or correct the entry.
Fix 5: Verify DNS Library Files
On some systems, the DNS library file may be missing or corrupted. Check for /lib64/libnss_dns.so.2 (Huawei Cloud, 2025). If it’s missing, you may need to reinstall the glibc package:
sudo yum reinstall glibc # For CentOS/RHEL
sudo apt install --reinstall libc6 # For Ubuntu/Debian
Fix 6: Restart the Network Service
Sometimes a simple restart of the network service resolves the issue:
sudo systemctl restart networking # For older systems
sudo systemctl restart NetworkManager # For systems using NetworkManager
FTP: “Name or Service Not Known” Error
The same DNS resolution error can occur when using FTP commands. If you see ftp: ftp://hostname: Name or service not known, the FTP client cannot resolve the hostname to an IP address (Linode, 2023).
Fixes for FTP Errors
1. Verify the hostname is correct. Check for typos in the FTP server address. The error ftp: ftp://ftp.drupal.org: Name or service not known indicates the hostname couldn’t be resolved (Linode, 2023).
2. Use the IP address directly. If DNS is the problem, try using the server’s IP address instead of the hostname:
ftp 192.168.1.100
3. Check DNS configuration. Apply the same DNS fixes mentioned above — the FTP client uses the same system DNS resolver as ping.
4. Consider using sftp or scp. If FTP continues to fail, these protocols use SSH and may work with different network configurations (Fedora Project, 2010).
Troubleshooting Table
| Problem | Cause | Fix |
|---|---|---|
ping google.com: Name or service not known | DNS resolver can’t find google.com (Veeble Hosting, 2024) | Check /etc/resolv.conf and add DNS servers (Huawei Cloud, 2025) |
ping 8.8.8.8 works, ping google.com fails | DNS issue, not network issue (Ask Ubuntu, 2022) | Fix DNS configuration (Huawei Cloud, 2025) |
ping works on Ubuntu but hostnames fail | systemd-resolved not running (CSDN, 2025) | Start systemd-resolved: sudo systemctl start systemd-resolved |
/etc/resolv.conf keeps getting overwritten | NetworkManager overriding DNS settings (Volcengine, 2026) | Add dns=none to /etc/NetworkManager/NetworkManager.conf |
Name or service not known on Windows | DNS cache corrupted (Wiki.ncmir.ucsd.edu, 2026) | Run ipconfig /flushdns as Administrator |
ftp: Name or service not known | FTP client can’t resolve hostname (Linode, 2023) | Use server IP address instead of hostname, or fix DNS |
hosts: files dns missing from nsswitch.conf | DNS entries removed from name resolution order (Huawei Cloud, 2025) | Add dns to hosts line in /etc/nsswitch.conf |
Missing /lib64/libnss_dns.so.2 | DNS library file corrupted or missing (Huawei Cloud, 2025) | Reinstall glibc package |
Frequently Asked Questions
What does “Name or service not known” mean when pinging?
It means your system’s DNS resolver cannot find an IP address for the hostname you entered. The ping command itself works — the problem is that your computer doesn’t know where to send the packets because it can’t translate the name to an address (Baeldung, 2024; Veeble Hosting, 2024).
Why can I ping an IP address but not a hostname?
This is a classic sign of a DNS configuration problem. Your network connection is working (hence pinging IP addresses works), but your system doesn’t have the right DNS server addresses or configuration to resolve hostnames (Ask Ubuntu, 2022).
How do I fix “Name or service not known” on Ubuntu?
Check if systemd-resolved is running: systemctl status systemd-resolved. If not, start it with sudo systemctl start systemd-resolved. Verify /etc/resolv.conf points to 127.0.0.53. If using netplan, add DNS servers to your netplan configuration and run sudo netplan apply (CSDN, 2025).
How do I fix “Name or service not known” on CentOS 7?
Add nameserver 8.8.8.8 and nameserver 8.8.4.4 to /etc/resolv.conf. If NetworkManager overwrites the file, add dns=none to /etc/NetworkManager/NetworkManager.conf and restart NetworkManager (Volcengine, 2026). You can also use nmcli to set DNS servers (Huawei Cloud, 2025).
How do I fix “Name or service not known” on Windows?
Open Command Prompt as Administrator and run ipconfig /flushdns to clear the DNS cache. Also check your network adapter’s DNS settings in Control Panel to ensure they’re correct (Wiki.ncmir.ucsd.edu, 2026).
What should I check in /etc/resolv.conf?
The file should contain at least one valid nameserver entry. For example:
nameserver 8.8.8.8
nameserver 8.8.4.4
If the file is empty or contains incorrect addresses, add these lines. If the file is overwritten on reboot, check your network management tool (NetworkManager, systemd-resolved, etc.) (Huawei Cloud, 2025).
What is /etc/nsswitch.conf and why does it matter?
/etc/nsswitch.conf controls the order in which your system looks up information like hostnames. The hosts line should include files (check /etc/hosts first) and dns (query DNS servers). If dns is missing, your system won’t use DNS for name resolution at all (Huawei Cloud, 2025).
Why do I get “Name or service not known” when using FTP?
The FTP client uses the same system DNS resolver as ping. If the FTP server’s hostname can’t be resolved, you’ll see this error. Try using the server’s IP address instead of the hostname, or fix your DNS configuration (Linode, 2023; Fedora Project, 2010).
Key Takeaways
- The “Name or service not known” error means DNS resolution failed — your system can’t find an IP address for the hostname (Veeble Hosting, 2024).
- If
pingworks with IP addresses but not hostnames, the issue is DNS-related, not a network outage (Ask Ubuntu, 2022). - On Linux, check
/etc/resolv.conffor valid DNS servers (like 8.8.8.8) and ensure/etc/nsswitch.confincludesdnsin the hosts line (Huawei Cloud, 2025). - On Ubuntu, verify
systemd-resolvedis running and/etc/resolv.confpoints to 127.0.0.53 (CSDN, 2025). - On CentOS/RHEL, add DNS servers to
/etc/resolv.confand prevent NetworkManager from overwriting it withdns=none(Volcengine, 2026). - On Windows, flush the DNS cache with
ipconfig /flushdnsas Administrator (Wiki.ncmir.ucsd.edu, 2026). - For FTP errors, try using the server’s IP address instead of the hostname, or apply the same DNS fixes (Linode, 2023).