Usually, the only time I make a change to the timezone setting of the operating system is during the installation time. But it may happen that a change to that setting is necessary. There are several ways to do this, but, as usual, there is only one Right Way™ to set the timezone info in your Linux distribution. I investigated it for a while and I think I have figured out how to do it right using command-line utilities on Fedora and all RHEL rebuilds (CentOS, Scientific Linux, etc). I am quite certain that many people miss this piece of information, so I describe it in detail right below.
The procedure must be performed by root.
First of all, you need to edit the /etc/sysconfig/clock file:
Please, read the notes below for more information about the settings above.
Then run the tzdata-update utility. This copies the correct zonefile to /etc/localtime:
Finally, update the system time by either running ntpd or the ntpdate utility. Both are part of the
ntp RPM package, so if this is not installed, just use “
yum install ntp” to get it installed.
/usr/sbin/ntpdate -b pool.ntp.org
This will make sure your time is correct.
You can set a cronjob to update the system’s time using ntpdate, like this:
# # Update the system time # 55 23 * * * root /usr/sbin/ntpdate -4 -b pool.ntp.org 2>&1 >> /var/log/ntpdate.log
Here are some notes about the configuration of the timezone:
- You can find the valid timezones by changing to the
/usr/share/zoneinfo/directory. From there, any relative path to a timezone file is a valid timezone. For example, “Etc/GMT“, “Europe/Athens“, “America/New_York” et cetera.
- GMT and UTC time are practically the same and they both refer to the Greenwich Mean Time, so setting the timezone to “Etc/UTC” or “Etc/GMT” is practically the same.
/etc/sysconfig/clockyou can set whether the hardware clock is set to UTC/GMT time or to Local Time. I am not sure in what way the hardware clock gets involved is the time of the Operating System. But, anyway, if you know how the hardware clock is configured, set this accordingly to true or false. Usually, if I set the OS to use GMT time, I also set this to true regardless of the actual hardware clock configuration. More info on this is still needed.
/etc/sysconfig/clockyou may see the options ARC=false and SRM=false. These change the way the “epoch” is assumed by the console on Alpha systems and have no effect if you do not use such a platform. Delete them or leave as is, unless you know you need to set one of them to true.
- In order to set the correct timezone, you could just create a symlink at
/etc/localtimepointing to the correct timezone file in
/usr/share/zoneinfo/. Then again, this would render the system configuration file
/etc/sysconfig/clock(and thus all other applications that use it) useless and ineffective, so this method is generally not recommended.
Setting your server to use the correct time is very important. Generally, I hate it when I see web sites or other services having incorrect time. This reveals the web server or the web application administrator’s laziness or inability to properly configure the time. I hope this guide will help get rid of this issue.
How to change the Timezone by George Notaras is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Copyright © 2009 - Some Rights Reserved