How to use the command 'ntpq' (with examples)

How to use the command 'ntpq' (with examples)

The ’ntpq’ command is used to query the Network Time Protocol (NTP) daemon. It provides information about NTP peers, system variables, and can be used in interactive or debugging mode. The command helps in troubleshooting and managing NTP configurations.

Use case 1: Start ’ntpq’ in interactive mode

Code:

ntpq --interactive

Motivation: Starting ’ntpq’ in interactive mode allows the user to directly interact with the NTP daemon. This is useful when real-time monitoring and analysis of NTP peers and system variables are required.

Explanation: The ‘–interactive’ flag launches the ’ntpq’ command in interactive mode, providing a prompt for entering various commands to query the NTP daemon.

Example output:

ntpq 4.3.0a@1.1902-o Fri Nov 23 19:51:07 UTC 2018 (1)

ntpq>

Use case 2: Print a list of NTP peers

Code:

ntpq --peers

Motivation: Printing a list of NTP peers provides information about the active time synchronization sources in the NTP network. This helps in verifying the connectivity and health of the NTP infrastructure.

Explanation: The ‘–peers’ flag instructs ’ntpq’ to display a list of NTP peers.

Example output:

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp1.example.co .GPS.            1 u    3   64    3    1.234   -0.567   0.123
 ntp2.example.co .WWV.            1 u   43   64    3    0.987   -0.321   0.098

Use case 3: Print a list of NTP peers without resolving hostnames from IP addresses

Code:

ntpq --numeric --peers

Motivation: Printing a list of NTP peers without resolving hostnames is useful when dealing with large-scale NTP networks where resolving hostnames might cause delays or require additional resources.

Explanation: The ‘–numeric’ flag ensures that ’ntpq’ displays the IP addresses of NTP peers instead of resolving their hostnames. This provides a quicker and more efficient way to view the connections.

Example output:

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*192.168.1.10    .GPS.            1 u    3   64    3    1.234   -0.567   0.123
 192.168.1.20    .WWV.            1 u   43   64    3    0.987   -0.321   0.098

Use case 4: Use ’ntpq’ in debugging mode

Code:

ntpq --debug-level

Motivation: Using ’ntpq’ in debugging mode provides detailed information about the NTP peers, synchronization status, and other troubleshooting details. This is useful when diagnosing synchronization issues or investigating performance problems.

Explanation: The ‘–debug-level’ flag activates the debugging mode in ’ntpq’, which increases the verbosity of the output by providing additional details and information.

Example output:

Proto Local Address          Foreign Address        State
ntp    192.168.1.100:123     192.168.1.10:123       syncing
             reach           delay       offset      jitter  ...
     1  0.04764   -0.11108   0.01029

Use case 5: Print NTP system variables values

Code:

ntpq --command=rv

Motivation: Printing NTP system variables values helps in understanding the configuration and behavior of the NTP daemon. This information is useful for troubleshooting and verifying the accuracy of time synchronization.

Explanation: The ‘–command=rv’ flag instructs ’ntpq’ to display the values of NTP system variables using the ‘rv’ command.

Example output:

associd=0 status=037f leap_none, sync_uhf_radio, 3 events, event_peer/strat_clr,
version="ntpq 4.3.0a@1.1902-o Fri Nov 23 19:51:07 UTC 2018 (1)", processor="x86_64",
system="Linux/4.19.0-10-amd64", leap=00, stratum=1, precision=-23, rootdelay=0.000,
rootdisp=0.010, refid=GPS, reftime=de405940.794e2486  Sat, Dec 18 2021 20:00:48.473,
rec=de405cc2.45b9e3c9  Sat, Dec 18 2021 20:09:30.274, reach=002, unreach=0, hmode=3,
pmode=4, hpoll=6, ppoll=6, flash=00 ok, keyid=0, ttl=0, offset=0.012, delay=0.000,
dispersion=157.019, jitter=0.072, reftime=de405cc2.45b9e3c9  Sat, Dec 18 2021 20:09:30.275,
org=de405cc2.0b6be6c7  Sat, Dec 18 2021 20:09:30.043, rec=de405cc2.45b9e532
 Sat, Dec 18 2021 20:09:30.274, xmt=de405cc2.5f7e04cc  Sat, Dec 18 2021 20:09:30.371,
filtdelay=     0.00    0.03    0.00    0.00    0.00    0.00    0.00    0.00,
filtoffset=   0.00   -0.07    0.00    0.00    0.00    0.00    0.00    0.00,
filtdisp=    0.03    0.03    0.03    0.03    0.03    0.03    0.03    0.03

Conclusion:

The ’ntpq’ command is a powerful tool for querying an NTP daemon. It provides various use cases, such as starting ’ntpq’ in interactive mode, printing a list of NTP peers, using the command in debugging mode, and displaying NTP system variables’ values. These use cases assist in troubleshooting, monitoring, and managing NTP configurations, ensuring accurate time synchronization in a network.

Tags :

Related Posts

Accessing Cockpit Pages with cockpit-desktop (with examples)

Accessing Cockpit Pages with cockpit-desktop (with examples)

Introduction Cockpit is a web-based graphical interface for Linux systems management.

Read More
How to use the command 'kdeconnect-cli' (with examples)

How to use the command 'kdeconnect-cli' (with examples)

KDE Connect is a project that aims to seamlessly integrate your devices.

Read More
How to use the command 'ddev' (with examples)

How to use the command 'ddev' (with examples)

The ‘ddev’ command is a container-based local development tool specifically designed for PHP environments.

Read More