Installing ntpdate Utility in Linux
Most Linux distributions do not include the ntpdate command by default. Run the following command to install it:
#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 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: 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: adjust time server [184.108.40.206] 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 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: 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: step time server [220.127.116.11] offset 14.195031 sec
Another common ntpdate error looks like this:
11 Jul 16:41:02 ntpdate: 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.