How to force a clock update using ntp?

Instead of ntpdate (which is deprecated), use ntpd:

sudo service ntp stop
sudo ntpd -gq
sudo service ntp start

The -gq tells the ntp daemon to correct the time regardless of the offset (g) and exit immediately (q) after setting the time.


Probably the ntp service is running, that's why ntpdate can't open the socket (port 123 UDP) and connect to ntp server.

Try from command line:

sudo service ntp stop
sudo ntpdate -s time.nist.gov
sudo service ntp start

If you want to put this in /etc/rc.local use the following:

( /etc/init.d/ntp stop
until ping -nq -c3 8.8.8.8; do
   echo "Waiting for network..."
done
ntpdate -s time.nist.gov
/etc/init.d/ntp start )&

Use sntp to set the time immediately. For example:

sudo sntp -s 24.56.178.140

The numbers after -s can be any ntp time server, that one is NIST in Ft. Collins, Colorado.

Tags:

Ntp