Howto setup and change the timezone on CentOS 7 Linux systems
In this mini post, I’ll show you how to set or change the time zone on Linux systems (RPM Family “Redhat /CentOS /Scientific Linux releases 7/6/5 and earlier – Fedora Linux”). Setting up the correct time zone for your Linux server is a simple but very important task. All your Linux machines must be have the correct time zone to facilitate the administrations and monitoring tasks. Setting up the correct time zone is a critical task for Linux machines that serving e-commerce applications and payment methods.
If you forgot to set the proper timezone or your Linux systems timezone is pointing to the wrong timezone, here I’ll show you how to set and change your Linux server’s timezone.
There are several different ways to manage time in Linux. This quick tip will show you how to quickly change the local time to the correct time zone for the server.
Changing The Current Timezone Using /etc/localtime File.
This method is available in all Linux distros “All Linux families RPM, Debian, Suse, etc…”. Simply all I need to do is replacing the existing localtime file in “/etc/localtime” with the correct time zone file from any directory in “/usr/share/zoneinfo/“.
For this example, assume that your current timezone is EET “Africa/Cairo” as shown below:
# date Fri Oct 7 14:27:50 EET 2016
Now, you want to change it to JST “Asia/Tokyo“, All the required from you is replacing the existing “/etc/localtime” file with “/usr/share/zoneinfo/Asia/Tokyo” as the following:
# rm /etc/localtime # cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
Now, check the new time zone for your server, run the following command:
# date Fri Oct 7 21:45:43 JST 2016
Perfect !!, My server has the correct timezone and it save to monitor and serving e-commerce applications on it.
Here’s a listing for all timezone files in “/usr/share/zoneinfo/“, run the following command:
# ls -F /usr/share/zoneinfo/ Africa/ Australia/ Cuba Etc/ GMT-0 Indian/ Kwajalein MST7MDT Portugal ROC US/ America/ Brazil/ EET Europe/ GMT+0 Iran Libya Navajo posix/ ROK UTC Antarctica/ Canada/ Egypt GB Greenwich iso3166.tab MET NZ posixrules Singapore WET Arctic/ CET Eire GB-Eire Hongkong Israel Mexico/ NZ-CHAT PRC Turkey W-SU Asia/ Chile/ EST GMT HST Jamaica Mideast/ Pacific/ PST8PDT UCT zone.tab Atlantic/ CST6CDT EST5EDT GMT0 Iceland Japan MST Poland right/ Universal Zulu
For other country timezones, browse the “/usr/share/zoneinfo” directory and it’s sub-directories.
Hint: 1.You can use either "cp" or "ln" or "ln -s" to replace the existing /etc/localtime with the correct time zone file from /usr/share/zoneinfo.
Changing The Current Timezone in CentOS 7 / Fedora “Special Case”.
For RPM Linux Family “Redhat /CentOS /Scientific Linux release 7, and the new releases of Fedora” there is a new method to change the timezone besides the above method “the general Linux method“. CentOS 7 has a new command shipped by default with all installation types, which is “timedatectl“, you can use this command for setting up your CentOS 7 timezone.
To get a quick help about using this new command, run the following:
# timedatectl --help timedatectl [OPTIONS...] COMMAND ... Query or change system time and date settings. -h --help Show this help --version Show package version --adjust-system-clock Adjust system clock when changing local RTC mode --no-pager Do not pipe output into a pager -P --privileged Acquire privileges before execution --no-ask-password Do not prompt for password -H --host=[USER@]HOST Operate on remote host Commands: status Show current time settings set-time TIME Set system time set-timezone ZONE Set system timezone list-timezones Show known timezones set-local-rtc BOOL Control whether RTC is in local time set-ntp BOOL Control whether NTP is enabled
To find list of all available time zones, run:
# timedatectl list-timezones
To get a list for certain continent, we use grep, run
# timedatectl list-timezones | grep Asia
The syntax is as follows to set timezone and need to run as root user:
# timedatectl set-timezone time_zone
In this example, set timezone to Asia/Tokyo
# timedatectl set-timezone Asia/Tokyo
Verify the new settings by typing the following two commands:
# date Sat Oct 8 00:24:23 JST 2016 # ls -l /etc/localtime lrwxrwxrwx. 1 root root 32 Oct 8 00:14 /etc/localtime -> ../usr/share/zoneinfo/Asia/Tokyo
If You Appreciate What We Do Here On Mimastech, You Should Consider:
- Stay Connected to: Facebook | Twitter | Google+
- Support us via PayPal Donation
- Subscribe to our email newsletters.
- Tell other sysadmins / friends about Us - Share and Like our posts and services
We are thankful for your never ending support.
[…] up timezone on CentOS / RHEL Linux […]