• 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. chattr Command Examples to Change File Attributes (Make files immutable)
  2. How to use execl (example included)
  3. Choosing SSSD or Winbind & Samba for Active Directory Integration in CentOS/RHEL
  4. How the BASH Shell load its configuration files in Linux
  5. Basic “ls” Command examples in Linux
  6. Windows Active Directory Account Shows Inconsistent UID/GID In Different Linux SSSD Clients (CentOS/RHEL)
  7. Linux OS Service ‘anacron’
  8. nmcli radio Command Examples in Linux
  9. lrzip: command not found
  10. How to use fdisk to partition a disk in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • powertop Command Examples in Linux
  • powertop: command not found
  • powerstat: command not found
  • powerstat Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright