How to use the command sntpd (with examples)
- Osx
- December 25, 2023
sntpd is an SNTP server that should not be invoked manually. It is responsible for synchronizing the system’s clock with a time server. Below are examples of different use cases for the sntpd command.
Use case 1: Start the daemon
Code:
sntpd
Motivation: Starting the sntpd daemon allows the system to synchronize its clock with a time server. This ensures that the system time is accurate, which is important for various applications and services that rely on accurate time.
Explanation: The command sntpd
is used to start the sntpd daemon. When invoked without any arguments, the daemon starts running and automatically synchronizes the system’s clock with a time server.
Example output:
sntpd: daemon started successfully
Use case 2: Overwrite existing state with the local clock (stratum 1)
Code:
sntpd -L
Motivation: This use case is useful when running a master/primary server without synchronizing with another (higher stratum) server. By overwriting the existing state with the local clock, the system will act as a stratum 1 server, providing accurate time to other servers in the network.
Explanation: The -L
option is used to overwrite the existing state of the sntpd with the local clock. This sets the system time as the reference for other servers in the network. It is typically used when the system is acting as a stratum 1 server.
Example output:
sntpd: local clock set as stratum 1 server
Use case 3: Use a custom file for the SNTP state
Code:
sntpd -z path/to/state.bin
Motivation: Sometimes, it is necessary to use a custom file for the SNTP state instead of the default file location. This use case allows you to specify the path to the custom file.
Explanation: The -z
option is used to specify the path to a custom file for the SNTP state. By providing a file path as an argument, you can use a specific file for storing the SNTP state instead of the default file location.
Example output:
sntpd: using custom file 'path/to/state.bin' for SNTP state
Conclusion:
The sntpd command is a powerful tool for managing the synchronization of the system’s clock with a time server. By understanding the different use cases and options available, you can ensure accurate time synchronization for your system.