The ntpdate command is a simple client for synchronizing the local system clock with a remote NTP server. It allows you to verify that your host has the correct time and, if necessary, synchronize the time with the NTP source. Although the ntpdate tool is deprecated, it is often used in simple cases where it is necessary to check the accuracy of the time on a Linux host or to manually synchronize the time once.
The ntpdate package is available in most standard Linux repositories. To install the ntpdate client, run:
On Debian/Ubuntu:
#apt-get install ntpdate
On CentOS/RHEL/Fedora:
#dnf install ntpdate
Compare the host’s current local time offset to any public NTP server:
#ntpdate -q 0.de.pool.ntp.org
The command will return a response similar to this:
server XX, stratum 3, offset -0.001678, delay 0.09354 server XX, stratum 3, offset -0.002948, delay 0.09235 server XX, stratum 2, offset -0.003413, delay 0.09418 server XX, stratum 2, offset +0.000915, delay 0.10155 5 Dec 09:58:43 ntpdate[116859]: adjust time server 176.9.42.91 offset -0.003413 sec
The offset value is the time difference between the local time and the clock on the NTP server. If you want to synchronize the time with the NTP server only once, run the command:
#/usr/sbin/ntpdate -bs 0.de.pool.ntp.org
To synchronize the time automatically once a day at 1:00 a.m., you can create a crontab job:
#crontab -e
00 1 * * * /usr/sbin/ntpdate 0.ca.pool.ntp.org
For automatic time sync at Linux boot:
#crontab -e
@reboot /usr/sbin/ntpdate 0.ca.pool.ntp.org
An error may occur when synchronizing the time:
ntpdate[21301]: no server suitable for synchronization found
This means that the NTP server is not available. By default, the standard NTP port (UDP 123) is used for time synchronization. In this case, try to sync time using an unprivileged port (–u switch):
#ntpdate -u pool.ntp.org
Another common ntpdate error:
ntpdate[22359]:: the NTP socket is in use, exiting
This error means that UDP port 123 is being used by another app (service). It is typically used by the ntpd or chronyd daemons.
This requires stopping the ntpd
(or chronyd
)service in Linux:
# systemctl stop ntpd
Now sync the time with ntpdate and run the time service.