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:

#server 0.ubuntu.pool.ntp.org
#server 1.ubuntu.pool.ntp.org
#server 2.ubuntu.pool.ntp.org
#server 3.ubuntu.pool.ntp.org

server 0.in.pool.ntp.org
server 0.asia.pool.ntp.org
server 2.asia.pool.ntp.org

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

If you get the folowing error:

the NTP socket is in use, exiting

Stop the ntp service:

$ sudo service ntp stop

Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s