How to change the Timezone

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.

Configuration

The procedure must be performed by root.

First of all, you need to edit the /etc/sysconfig/clock file:

ZONE="Etc/GMT"
UTC=true

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:

/usr/sbin/tzdata-update

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

Notes

Here are some notes about the configuration of the timezone:

  1. 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.
  2. 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.
  3. In /etc/sysconfig/clock you 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.
  4. In /etc/sysconfig/clock you 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.
  5. In order to set the correct timezone, you could just create a symlink at /etc/localtime pointing 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.

Final thoughts

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

4 responses on “How to change the Timezone

  1. Daniel Permalink →

    Do you know if Fedora 11 resets the system time automatically after reboot? It seems to be happening for my server, which is a virtual server living in a cloud computing environment.

  2. George Notaras Post authorPermalink →

    Hi Daniel. I have used Fedora until release 10, but I really doubt that anything might have changed in the 11th release regarding the time setting.

    I believe that the time reset you experience might be related to the virtualization technology that is used as it happens with Xen guests, which actually sync the time with Domain0. To overcome this the “/proc/sys/xen/independent_wallclock” kernel option must be enabled:

    echo 1 > /proc/sys/xen/independent_wallclock
    

    Please, also read this thread on the Xen mailing list.

    But I do not know what happens with other virtualization technologies.

  3. Daniel Permalink →

    Yes.. you are right. I figured that out after a while.. Actually the option of changing “wallclock” file is only available if I administer the Xen systems myself. As a user of the virtualisation service, I have to work-around it in other ways.. but thanks anyway…

  4. Altax Permalink →

    Thanks for giving the details on changing the timezone. Very useful and informative post.