You just got your new CentOS dedicated server, and you notice that times in your logs aren’t quite right. You check the time from the command line (run
date), and find that the timezone is set to US Eastern or some other timezone. How do you get this changed?
Unfortunately, this is not an easy thing to figure out. Fortunately though, it’s not hard to do with the right directions.
Please note that you have to have root access to be able to make the changes detailed below.
There are a series of time zone files located at
/usr/share/zoneinfo. Select the appropriate named timezone for your location. For my location, Oklahoma, USA, I actually have two that I can select from:
US/Central. Make note of the appropriate folder and file for your timezone.
The active timezone used on your system is in the
/etc/localtime file. The default will vary depending on your server host but often seems to be EST or EDT (depending on the time of year you are checking). We simply need to replace this file with the file we selected in the previous step.
Now, I say replace, but I actually recommend creating a link to the pertinent file rather than actually making a copy. Let me explain the reasoning for this quickly.
A crucial part of the timezone shift calculations is the daylight savings calculations. Many people don’t realize this, but the daylight savings days were changed in 2007. When this change happened, all servers needed to be updated with new zoneinfo files.
If your server has an automated process to update these files when daylight savings calculations change, your
/usr/share/zoneinfo files will be updated but the
/etc/localtime file will not be. So, if you simply made a copy of the file, you’ll have to know when these updates come out and manually copy the file over. If you create a link, everything will take care of itself.
Enough of the banter. On with the show.
First, make a backup of the existing localtime file. It’s always good practice to make backups of original config files.
[[email protected] ~]$ sudo mv /etc/localtime /etc/localtime.bak
Next, create the link:
[[email protected] ~]$ sudo ln -sf /usr/share/zoneinfo/America/Chicago /etc/localtime
Make sure to replace
America/Chicago with the directory (if your zone has one) and filename of the timezone you wish to use.
Now you just need to test your change. Run
date from the command line, and ensure that the appropriate time, date, and timezone are reported.