How to synchronize your server's date and time

From Cosmin's Wiki

Jump to: navigation, search

Home > Linux how to's > How to synchronize your server's date and time

Having the correct date and time on your server is quite important, especially when you're using analysing for example Apache logs. So, here is the simple procedure on how to achieve this.


Configuring the timezone

First, you need to correctly configure the timezone you're in. For this, on Debian etch you have several tools: tzconfig or tzselect. Personally I prefer using tzconfig as it also tells me the current timezone of my server, and if I need to change it, I can do so:

> tzconfig
Your current time zone is set to Europe/Bucharest
Do you want to change that? [n]: y
Please enter the number of the geographic area in which you live:
        1) Africa                       7) Australia
        2) America                      8) Europe
        3) US time zones                9) Indian Ocean
        4) Canada time zones            10) Pacific Ocean
        5) Asia                         11) Use System V style time zones
        6) Atlantic Ocean               12) None of the above
Then you will be shown a list of cities which represent the time zone
in which they are located. You should choose a city in your time zone.
Number: 8
Amsterdam Andorra Athens Belfast Belgrade Berlin Bratislava Brussels
Bucharest Budapest Chisinau Copenhagen Dublin Gibraltar Guernsey Helsinki
Isle_of_Man Istanbul Jersey Kaliningrad Kiev Lisbon Ljubljana London
Luxembourg Madrid Malta Mariehamn Minsk Monaco Moscow Nicosia Oslo Paris
Podgorica Prague Riga Rome Samara San_Marino Sarajevo Simferopol Skopje
Sofia Stockholm Tallinn Tirane Tiraspol Uzhgorod Vaduz Vatican Vienna
Vilnius Volgograd Warsaw Zagreb Zaporozhye Zurich
Please enter the name of one of these cities or zones
You just need to type enough letters to resolve ambiguities
Press Enter to view all of them again
Name: [] Bucharest
Your default time zone is set to 'Europe/Bucharest'.
Local time is now:      Thu Sep 11 12:20:32 EEST 2008.
Universal Time is now:  Thu Sep 11 09:20:32 UTC 2008.

You can now check the current date/time with

> date

Configuring the date/time

Using ntpdate

Install the package with:

> aptitude install ntpdate

ntpdate sets the local date and time by polling the Network Time Protocol (NTP) server(s) given as the server arguments to determine the correct time. It must be run as root on the local host. With ntpdate you can choose yourself the moment you want to update the server's date and time. However, you need to know an internet time server with which you want to do the synchronization. For finding such a server just go to and choose the public NTP server closest to you. Once you have it, update the date/time on your server like this:

> ntpdate

Note: The functionality of this program is now available in the ntpd program. After a suitable period of mourning, the ntpdate program is to be retired from this distribution.

Using openntpd

openntpd is the OpenBSD NTP daemon which runs on your server and keeps your time always in sync. Moreover, you don't need to bother with public NTP servers - it is automatically done for you. So, basically, all you need to do is:

> aptitude install openntpd

and you're done.