• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

“ntpq -pn” command returns with error “Name or service not known”

by admin

The Problem

Executing the command “ntpq -pn” returns with the error:

# ntpq -p
Name or service not known

In some cases, you may also encounter an error shown below:

# ntpq -pn
Servname not supported for ai_socktype

The Solution

The “Name or service not known” error will be seen if the system cannot resolve “localhost” for the ntpq command. Make sure we have pointer to “127.0.0.1 localhost” in /etc/hosts file.

1. Fix the /etc/hosts file to map 127.0.0.1 to localhost, i.e., there must be a line in /etc/hosts that begins with “127.0.0.1” and contains “localhost”.

Note that it is perfectly fine if this line contains additional host aliases in addition to localhost. Example:

# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain myserver myserver.mydomain
Note that there are countless other programs that will also error-out or behave erratically if the 127.0.0.1 –> localhost mapping is removed from /etc/hosts.

That said, in RHEL6, the name “localhost” maps to both 127.0.0.1 and the IPv6 loopback ::1, so while removing the 127.0.0.1 line in RHEL6 would be a bad idea, it would likely not cause ntpq to fail.

2. Also make sure we have pointer to ntp in /etc/services file.

# vi /etc/services
ntp             123/tcp
ntp             123/udp                         # Network Time Protocol

Filed Under: Linux

Some more articles you might also be interested in …

  1. Unmounting a Windows Share Fails in Linux
  2. “git remote” Command Examples
  3. Which network ports are reserved by the Linux Operating System?
  4. grap Command Examples
  5. qm start Command Examples in Linux
  6. How to uninstall virtualbox software package from Ubuntu
  7. v4l2-ctl Command Examples in Linux
  8. kexec: command not found
  9. rsync Command Examples in Linux
  10. eyeD3 Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright