How to Use ntpdate to Sync Time in Linux?

Ntpdate is a console utility that can be used as an NTP client in various Linux distros to synchronize the local time of a host with the global time on an NTP server.

Installing ntpdate Utility in Linux

The ntpdate command is not installed by default in most Linux distributions. To install it, run the command below:

On Debian/Ubuntu:

#apt-get install ntpdate


#yum install ntpdate


On Fedora-like distors:

#dnf install ntpdate

You can check the local host time with the NTP server with the command:

#/usr/sbin/ntpdate -q

The command will return something like this:

server x.x.x.x, stratum 2, offset 54.126055, delay 0.03915

server x.x.x.x, stratum 2, offset 54.129242, delay 0.02861

server x.x.x.x, stratum 2, offset 54.126370, delay 0.02370

server x.x.x.x, stratum 2, offset 54.126370, delay 0.02185

10 Jul 12:00:01 ntpdate[33412]: adjust time server x.x.x.x offset 54.126370 sec

Offset is the time difference with specified NTP server in seconds. In our example, time on the current Linux host is 54 seconds ahead than on the reference NTP servers.

Stop the ntp service:

#service ntp stop

To synchronize time on a host with an NTP server once, run the following command:

#/usr/sbin/ntpdate –bs

10 Jul 12:00:41 ntpdate[22349]: adjust time server [] offset 54.231123 sec

For time synchronization, it is advisable to use the closest available NTP server from your region. A list of public NTP server pools for different regions is available on Internet.

READ ALSO  How to Install Google Chrome on Linux?

The ntpdate utility performed synchronization, as a result, 54 seconds were added to the local system time.

Now you can start the NTP service:

#service ntp start

To synchronize the time automatically once a day, you can create a scheduled task:

#crontab -e
#00 1 * * * /usr/sbin/ntpdate

To automatically synchronize on Linux boot, use the command:

#crontab -e
#@reboot /usr/sbin/ntpdate

Ntpdate Does Not Synchronize Time

If after the time synchronization with the NTP server command (for example, #ntpdate, you are getting the error:

11 Jul 16:05:44 ntpdate[21301]: no server suitable for synchronization found

This means that the NTP server is unavailable (although you can access Internet from the host). It is possible that UDP port 123 is blocked (check if the incoming and outgoing traffic for port UDP/123 is allowed on your Internet access gateway). In this case, you can try to synchronize the time with the help of the unprivileged port (–u key):

#ntpdate -u

11 Jul 16:20:14 ntpdate[22359]: step time server [] offset 14.195031 sec

Another common ntpdate error looks like this:

11 Jul 16:41:02 ntpdate[22359]: the NTP socket is in use, exiting

ntpdate Linux

This error means that UDP port 123 is busy by another program. As a rule, it is used by the ntp daemon.

You can stop the ntp service in Linux like this:

service ntpd stop

Now you can synchronize time using ntpdate.

READ ALSO  How to Check Network Usage on Linux?
Cyril Kardashevsky

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.