Hosting Linux

How to Setup NTP on ubuntu

Want to have your server sync to a public time clock so it can keep accurate time? Here is how it’s done:

First, you need to make sure you have the time zone setup as you like. I set all of my servers to my timezone, regardless of where the server actually is. This makes finding information in logs easier. Many people specify UTC or GMT time. This is a considered best practice, especially for enterprise level servers. Most of our customers are smaller and have only 1 or 2 regions, so we will use our time zone (because we troubleshoot their issues and it makes it easier on us).

Specify Time Zone

(1:99)# dpkg-reconfigure tzdata
Current default time zone: 'America/Chicago'
Local time is now:      Thu Feb  5 04:30:44 CST 2015.
Universal Time is now:  Thu Feb  5 10:30:44 UTC 2015.


Set Approximate Initial Time

(1:99)# /bin/date MMDDHHMMCCYY
(1:99)# /bin/date 020504312015
Thu Feb  5 04:31:00 CST 2015

Update the NTP pool

We add 3 NTP servers to the pool so it can check more reliably

(1:101)# ntpdate
 5 Feb 04:35:34 ntpdate[2890]: adjust time server offset 62.967271 sec
(1:101)# ntpdate
 5 Feb 04:36:18 ntpdate[2897]: adjust time server offset -0.004201 sec
(1:102)# ntpdate
 5 Feb 04:36:59 ntpdate[2903]: adjust time server offset 0.001515 sec

Update System Clock

This doesn’t work on a virtual machine or VPS, but on a standalone, it does:

hwclock --systohc --utc

Verify NTP is working

You can install the ntp client, though this isn’t required:

(1:106)# apt-get install ntp
(1:106)# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
============================================================================== .ACTS.           1 u    3   64    1   73.392   -2.196   0.000    3 u    2   64    1  162.693   -1.093   0.000
 lyla.preshweb.c  3 u    1   64    1  161.516    1.594   0.000   2 u    -   64    1   54.421   -1.160   0.000
 golem.canonical .INIT.          16 u    -   64    0    0.000    0.000   0.000

Or you can simply look at your syslogs:

(1:108)# cat /var/log/syslog | grep ntp



Services will need to update logs with the new time, and the most reliable way to do this is to reboot the server.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.