ntpdate – Set date and time using Network Time Protocol (NTP)

The ntpdate command is used to set the date and time in a Linux system using the Network Time Protocol (NTP). NTP is a protocol used to synchronize the clock of a computer system to a reference time source, such as a time server on the internet or a local network. The ntpdate command is typically used to synchronize the clock of a Linux system with a remote NTP server.

Overview

The syntax of the ntpdate command is as follows:

ntpdate [options] server

Where server is the hostname or IP address of the NTP server to synchronize with.

For example, to synchronize the clock of a Linux system with the NTP server at time.google.com, you would use the following command:

sudo ntpdate time.google.com

This will set the date and time on the system to the current time as reported by the NTP server.

Specific use cases

  • Synchronizing the clock of a Linux system with an NTP server on the internet or a local network.
  • Ensuring that the clock of a Linux system is accurate for time-sensitive applications, such as logging or database transactions.

Examples

  • sudo ntpdate time.google.com: Synchronize the clock of the system with the NTP server at time.google.com.
  • sudo ntpdate -u pool.ntp.org: Synchronize the clock of the system with a random NTP server from the pool.ntp.org pool.

Options

The following options are available for the ntpdate command:

Option Description
-b Force the time to be stepped using the settimeofday() system call, rather than slewed (default) using the adjtime() system call.
-d Increase the debug level, producing more output about the NTP server response.
-q Query the NTP server, but do not set the time.
-u Use an unprivileged port to query the NTP server.

Troubleshooting tips

  • If the system clock is not being set correctly, ensure that the NTP server is reachable and responding to requests. Use the -d option to increase the debug level and check the output for errors or warnings.
  • If the system clock is being set to the wrong time, ensure that the correct timezone is set on the system. Use the timedatectl command to view or set the timezone.

Notes

  • The ntpdate command has been deprecated in favor of the ntpd daemon, which provides continuous clock synchronization rather than one-time synchronization.