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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. How to Re-Create the Yum Cache and/or Force a Fetch of the Package List of the Enabled Repositories
  2. “Could not resolve proxy: https; Unknown error” – error with ‘yum update’
  3. 7 Useful Find Command Examples to Locate files to remove when a filesystem is full
  4. “Couldn’t find device with uuid [UUID]” – error whith pvs command
  5. LVM Configuration : Logical Volume (LV) Operations/Utilities
  6. elinks Command Examples in Linux
  7. egrep Command Examples in Linux
  8. Audit Log And Messages File Not Rotating on CentOS/RHEL
  9. How to restrict ssh logins by user and client address on CentOS/RHEL
  10. UNIX / Linux : how to force user to change their password on next login after password has reset

You May Also Like

Primary Sidebar

Recent Posts

  • vgextend Command Examples in Linux
  • setpci command – configure PCI device
  • db_load command – generate db database
  • bsdtar command – Read and write tape archive files

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright