Synchronizing Time with NTP Using Ntpdate in Linux

PowerADM.com / Linux / Synchronizing Time with NTP Using Ntpdate in Linux

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.

Note. Most modern Linux distributions (starting with CentOS/Rocky 8 and Debian 11) use chrony as the default time synchronization package, which replaces ntpd in most scenarios.

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

Install the ntpdate package on Linux

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
Visit http://www.pool.ntp.org/ to find the nearest public NTP server address for time sync.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *