How to Use ntpdate to Sync Time in Linux?

Installing ntpdate Utility in Linux

Most Linux distributions do not include the ntpdate command by default. Run the following command to install it:

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

It is recommended that you utilise the nearest accessible NTP server from your region for time synchronisation. On the Internet, you may get a list of public NTP server pools for various areas.

As a result of the synchronisation done by the ntpdate programme, 54 seconds were added to the local system time.

You can now start the NTP server:

#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

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.

Leave a Reply

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

Enter Captcha Here :