ntpdc Command in Linux



The ntpdc command is used to query the ntpd daemon about its current state and to request changes in that state. The ntpd daemon is responsible for maintaining the system time in sync with internet time servers using the Network Time Protocol (NTP).

The program can be run in two main modes: interactive mode and command line argument mode. In interactive mode, users input commands directly; whereas in command line argument mode, commands are specified as arguments when starting ntpdc.

Read this tutorial to get a good understanding of the ntpdc command and how to apply it in practice.

Table of Contents

Here is a comprehensive guide to the options available with the ntpdc command −

Introduction of ntpdc Command

Through the ntpdc interface, users can access extensive state and statistical information about the ntpd daemon. Additionally, almost all configuration options that can be set at startup using ntpd's configuration file can also be adjusted at runtime using ntpdc.

If one or more request options are included on the command line when ntpdc is executed, these requests are sent to the NTP servers running on the specified hosts (or on localhost by default if no hosts are specified). If no request options are provided, ntpdc will read commands from standard input and execute them on the first specified host or localhost by default.

ntpdc uses NTP mode 7 packets to communicate with the NTP server. This allows it to query any compatible server on the network that permits such queries. However, because NTP is a UDP protocol, communication can be unreliable, especially over long network distances.

ntpdc does not attempt to retransmit requests and will timeout if there is no response from the remote host within a suitable timeframe. Besides that, the operation of ntpdc is specific to the particular implementation of the ntpd daemon and is expected to work with the current and some previous versions of the daemon.

Requests from a remote ntpdc program that affect the state of the local server must be authenticated. This requires both the remote program and local server to share a common key and key identifier.

Syntax of ntpdc Command

The basic syntax for the ntpdc command is as follows −

ntpdc [options] [host] [...]

ntpdc Command Options

The following options allow you to tailor the behavior of ntpdc to suit your specific needs −

Tag Description
-4 Forces DNS resolution of the following host names on the command line to the IPv4 namespace.
-6 Forces DNS resolution of the following host names on the command line to the IPv6 namespace.
-c command 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). Multiple -c options may be given.
-d Turns on debugging mode. This option may occur more than once to increase the level of debugging.
-i Forces ntpdc to operate in interactive mode. Prompts will be written to the standard output and commands read from the standard input.
-l Obtains a list of peers known to the server(s). This switch is equivalent to -c listpeers.
-n Outputs all host addresses in dotted-quad numeric format rather than converting to canonical host names.
-p Prints a list of peers known to the server as well as a summary of their state. This is equivalent to -c peers.
-s Prints a list of peers known to the server as well as a summary of their state, but in a slightly different format than the -p switch. This is equivalent to -c dmpeers.

Examples of ntpdc Command in Linux

The following examples and commands should help you effectively use ntpdc to manage and query your NTP servers −

Querying System Information

To get system information of the NTP server, use the following command −

sudo ntpdc -c sysinfo example.com

This command queries the specified NTP server hostname and retrieves detailed information about its system status.

List All Peers Known to the NTP Server

To view a list of peers known to the NTP server, you can use the following command −

sudo ntpdc -l example.com

This command requests a brief list of peers that the server is maintaining state for, showing potential synchronization candidates.

Showing Peer Details

To obtain a detailed list of peer variables, you can use the following command −

sudo ntpdc -c peers hostname

This provides a summary of the state of each peer, including information like polling interval, reachability, and estimated delay.

Run ntpdc in Interactive Mode

To enter interactive mode and execute multiple commands directly, simply run −

sudo ntpdc -i

Interactive Command for Help

Once you're in interactive mode, you can type the help command to get a list of all available commands or detailed information about a specific command −

help

If you want information about a specific command, include the command keyword. For instance, if you want help with the peers command, you can simply type −

help peers

This will provide you with function and usage information about the peers command.

View Peers' State Summary

To display a summary of the state of peers known to the server, use the "-p" flag −

sudo ntpdc -p example.com

This command shows a list of peers along with their current state (e.g., whether they are synchronized or unreachable). It's useful for seeing how each peer is performing in terms of time synchronization.

Print Peers' State in a Different Format

To print a peer list with a slightly different format, you can simply use the "-s" flag −

sudo ntpdc -s example.com

This command provides a summary of peer states, but in a different format than the "-p" flag. It's useful when you need a different view of the synchronization status or need to compare with other output formats.

Force DNS Resolution to IPv4

To force DNS resolution to use the IPv4 namespace, you can use the following command −

sudo ntpdc -4 example.com

The -4 flag ensures that DNS resolution will use IPv4 addresses instead of potentially using IPv6.

Force DNS Resolution to IPv6

To force DNS resolution to use the IPv6 namespace, you can simply run −

sudo ntpdc -6 example.com

The -6 flag forces the resolution of the host to the IPv6 namespace. This is useful if you're working in a network that uses only IPv6 addresses or need to prioritize IPv6.

Enable Debugging Mode

To enable debugging and view more detailed information, use the "-d" flag −

sudo ntpdc -d example.com

This command enables debugging mode, which provides additional output related to the inner workings of ntpdc and the ntpd daemon.

Query ntpd with Multiple Commands

To run multiple commands at once, you can use the following command −

sudo ntpdc -c "peers" -c "sysinfo"

The "-c" flag can be used multiple times to specify different commands. In this case, it will show the list of peers (peers) and the system information (sysinfo).

Conclusion

The ntpdc command is an invaluable tool for administrators and users who need to interact with and manage the NTP (Network Time Protocol) daemon. Whether you're troubleshooting time synchronization issues, checking the state of peers, or adjusting settings on the fly, ntpdc provides a flexible and robust interface to access detailed information about the NTP system.

However, as of this writing, ntpdc has been deprecated and removed from many distributions in favor of more modern and actively maintained tools like ntpq, which provide functionality for querying the status of NTP servers and retrieving detailed peer information.

Advertisements