ntpdate time server

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

On CentOS/RHEL:

#yum install ntpdate

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 0.de.pool.ntp.org

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 0.de.pool.ntp.org

10 Jul 12:00:41 ntpdate[22349]: adjust time server [81.7.16.52] 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 here.

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 0.ca.pool.ntp.org

To automatically synchronize on Linux boot, use the command:

#crontab -e
#@reboot /usr/sbin/ntpdate 0.ca.pool.ntp.org

Ntpdate Does Not Synchronize Time

If after the time synchronization with the NTP server command (for example, #ntpdate 0.ca.pool.ntp.org), 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 0.ca.pool.ntp.org

11 Jul 16:20:14 ntpdate[22359]: step time server [205.206.70.7] 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.

You may also like:

Configuring SSH Key-Based Authentication on Linux The Internet is full of manuals on how to configure the SSH key-based authentication on a Linux server. Every time we have to do this, we were searchi...
How to Reset Root Password in MySQL and MariaDB? In older versions of MySQL, if you forgot or lost the root password for MySQL, you could view the current password in the my.cnf file. In modern versi...

Add Your Comment