Fix out of sync system time on Ubuntu

ubuntu_logo_81x81Today I noticed that my system time is more than a minute slower than the correct time in my timezone. I do not have ntp installed on my system. The delta in time might have been caused by a dying CMOS battery. To set the correct time, I ran the usual:

$ sudo dpkg-reconfigure tzdata

I selected the correct geographic area and timezone but the lag remained. I realized that I need to install ntp and issued:

$ sudo apt-get install ntp

Then started the service:

$ sudo service ntp start

Lag prevails! I was puzzled for a while. Finally I decided to change the default Ubuntu time servers and add different ones in /etc/ntp.conf:



Restarted NTP service:

$ sudo service ntp restart

Voila! I got the correct time! Turns out the Ubuntu time servers might be running slower for my timezone! Finally I synced the system time to my hardware:

$ sudo hwclock --systohc --localtime

A quicker way to get the correct time is to use ntpdate:

$ sudo apt-get install ntpdate
$ sudo ntpdate

If you get the folowing error:

the NTP socket is in use, exiting

Stop the ntp service:

$ sudo service ntp stop

Leave a Reply

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