Table of Contents
In this article, we will look into 10 Practical and Useful ntpq Command examples that can be used in Linux Servers to check the NTP Server stats. ntpq
is an open source and free utility available on Linux Based Servers that monitors the NTP daemon NTPD
and queries its performance. This is one of the frequently used command in most of the Organizations to check the NTP server performance. ntpq
command can be used either in interactive mode or by using command line arguments. You can also make requests to read and write arbitrary variables through ntpq
command. We will see the usage of ntpq
command along with the examples in below section.
SYNOPSIS
ntpq [-46dinp] [-c command] [host] [...]
ntpq command examples in Linux
Also Read: How to Start and Enable SSHD Service in OpenSUSE Linux
Example 1: How to Check ntpq command version
If you want to check ntpq command version then you need to use ntpq --version
command as shown below. As shown in the output, current version is 4.2.6p5
.
[root@localhost ~]# ntpq --version ntpq 4.2.6p5
Example 2: How to Start ntpq Interactive mode Using -i flag
If you want to start ntpq in interactive mode then you need to use ntpq -i
command and then use exit
to get out from the interactive mode.
[root@localhost ~]# ntpq -i ntpq>
-i : Force ntpq to operate in interactive mode. More on ntpq Man Page.
Example 3: How to Print List of Peers Configured Using -p option
If you want to print all the configured NTP Servers then you can use ntpq -p command as shown below.
[root@localhost ~]# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== time.cloudflare 10.35.14.16 3 u 2 64 1 45.245 -6.688 0.000 43.240.66.74 103.134.252.11 3 u 1 64 1 21.120 -6.596 0.000 time.cloudflare .INIT. 16 u - 64 0 0.000 0.000 0.000 139.59.55.93 .INIT. 16 u - 64 0 0.000 0.000 0.000
-p : Print a list of the peers known to the server as well as a summary of their state. More on ntpq Man Page.
Example 4: How to Print List of Configured NTP Servers IP Using -np option
If you want to print the IP address of all the configured NTP Servers then you need to use ntpq -np
command as shown below.
[root@localhost ~]# ntpq -np remote refid st t when poll reach delay offset jitter ============================================================================== +162.159.200.1 10.35.14.16 3 u 60 64 3 42.077 -5.982 0.670 -43.240.66.74 103.134.252.11 3 u 60 64 3 20.911 -6.532 0.847 +162.159.200.123 10.35.14.16 3 u 57 64 3 43.653 -5.755 0.677 *139.59.55.93 17.253.82.253 2 u 57 64 3 5.092 -5.253 1.920
-n : Output all host addresses in dotted-quad numeric format rather than converting to the canonical host names. More on ntpq Man Page.
Example 5: How to Enable Debugging Mode Using -d option
If you are looking to enable debugging with ntpq
command then you need to use -d
option as shown below.
[root@localhost ~]# ntpq -d -np 1 packets reassembled into response remote refid st t when poll reach delay offset jitter ============================================================================== 2 packets reassembled into response 162.159.200.1 10.35.14.16 3 u 27 64 1 44.381 -3.783 0.528 2 packets reassembled into response 43.240.66.74 103.134.252.11 3 u 26 64 1 23.198 -6.443 8.580 2 packets reassembled into response 162.159.200.123 10.35.14.16 3 u 25 64 1 46.449 -4.029 1.229 2 packets reassembled into response 139.59.55.93 17.253.82.253 2 u 24 64 1 6.155 -4.233 2.846
-d : Turn on debugging mode. More on ntpq Man Page.
Example 6: How to Check the System variables values
If you want to check all the set system variables then you need to use ntpq -c rv
command as shown below.
[root@localhost ~]# ntpq -c rv associd=0 status=0618 leap_none, sync_ntp, 1 event, no_sys_peer, version="ntpd 4.2.6p5@1.2349-o Tue Jun 23 15:38:18 UTC 2020 (1)", processor="x86_64", system="Linux/3.10.0-1160.2.2.el7.x86_64", leap=00, stratum=3, precision=-24, rootdelay=45.676, rootdisp=447.740, refid=139.59.55.93, reftime=e3a2e5ba.743cd881 Fri, Jan 8 2021 9:07:54.454, clock=e3a2e66b.b427061e Fri, Jan 8 2021 9:10:51.703, peer=32412, tc=6, mintc=3, offset=-6.041, frequency=-0.040, sys_jitter=0.560, clk_jitter=1.987, clk_wander=0.014
-c : The following argument is interpreted as an interactive format command and is added to the list of commands to be executed on the specified host(s). More on ntpq Man Page.
Example 7: How to Set Output to raw using ntpq command
If you want to set the output of ntpq to raw
then you need to use ntpq -c raw
command as shown below.
[root@localhost ~]# ntpq -c raw Output set to raw
Example 8: How to Add a time interval of 100 milliseconds in timestamps
If you are looking to add a time interval of 100 milliseconds
in timestamps then you need to run ntpq -c "delay 100"
command as shown below.
[root@localhost ~]# ntpq -c "delay 100"
Example 9: How to Check Man Page of ntpq command
If you want to check the man page of ntpq command then you need to use man ntpq
command as shown below.
[root@localhost ~]# man ntpq ntpq(8) System Manager's Manual ntpq(8) NAME ntpq - standard NTP query program SYNOPSIS ntpq [-46dinp] [-c command] [host] [...] DESCRIPTION The ntpq utility program is used to monitor NTP daemon ntpd operations and determine performance. It uses the standard NTP mode 6 control message formats defined in Appendix B of the NTPv3 specification RFC1305. The same formats are used in NTPv4, although some of the variable names have changed and new ones added. The description on this page is for the NTPv4 variables. The program can be run either in interactive mode or controlled using command line arguments. Requests to read and write arbitrary variables can be assem‐ bled, with raw and pretty-printed output options being available. The ntpq can also obtain and print a list of peers in a common format by sending multiple queries to the server.
Example 10: How to Check all the options available with ntpq command
If you want to check all the options available with ntpq command then you need to use ntpq --help
as shown below.
[root@localhost ~]# ntpq --help ntpq - standard NTP query program - Ver. 4.2.6p5 USAGE: ntpq [ -<flag> [<val>] | --<name>[{=| }<val>] ]... [ host ...] Flg Arg Option-Name Description -4 no ipv4 Force IPv4 DNS name resolution - prohibits the option 'ipv6' -6 no ipv6 Force IPv6 DNS name resolution - prohibits the option 'ipv4' -c Str command run a command and exit - may appear multiple times -d no debug-level Increase output debug message level - may appear multiple times -D Str set-debug-level Set the output debug message level - may appear multiple times -p no peers Print a list of the peers - prohibits the option 'interactive'
Popular Recommendations:-
How to Start / Stop / Restart Network Service in OpenSUSE Linux
How to Check Stateful and Stateless Pods in Kubernetes Cluster
3 Easy Ways to Check/Find OpenSUSE Linux Version
6 Easy Steps to Setup and Manage Log rotation Using logrotate in Linux
Migrate CentOS 8 to CentOS Stream 8 in 6 Easy Steps
26 iostat, vmstat and mpstat command examples to Monitor Linux Performance
Practical Steps to Install iostat and mpstat command on Linux(RHEL/CentOS 7/8)