Set Time Zone on CentOS 7

Checking the Current Timezone

In CentOS and other modern Linux distros, you can use the timedatectl command to display and set the current system’s time and timezone.

timedatectl

The output below shows that the system’s timezone is set to UTC:

Local time: Wed 2019-02-06 22:43:42 UTC
Universal time: Wed 2019-02-06 22:43:42 UTC
RTC time: Wed 2019-02-06 22:43:42
Time zone: Etc/UTC (UTC, +0000)
NTP enabled: no
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

The system timezone is configured by symlinking /etc/localtime to a binary timezone identifier in the /usr/share/zoneinfo directory. So, another option to check the timezone is to show the path the symlink points to using the ls command:

ls -l /etc/localtime
lrwxrwxrwx. 1 root root 29 Dec 11 09:25 /etc/localtime -> ../usr/share/zoneinfo/Etc/UTC

Changing Timezone in CentOS

Before changing the timezone, you’ll need to find out the long name for the timezone you want to use. The timezone naming convention usually uses a “Region/City” format.

To list all available time zones, you can either list the files in the /usr/share/zoneinfo directory or use the timedatectl command.

timedatectl list-timezones
...
America/Tijuana
America/Toronto
America/Tortola
America/Vancouver
America/Whitehorse
America/Winnipeg
...

Once you identify which time zone is accurate to your location, run the following command as sudo user:

Read more

Share

Installing NTP Service and change timezone in CentOS 6 / CentOS 7

Let’s install NTP service first:

yum install ntp

Configure NTP services by updating the following section (only if appropriate):

nano /etc/ntp.conf

And by commenting on the sections:

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst

In my case I used the following National Time Server of Bangladesh:

server bsti1.time.gov.bd
server bsti2.time.gov.bd

save and restart the ntp service.

Change Timezone on a CentOS 6 and 7

How do I see the current time zone on CentOS Linux?

Type the date command or the ls command:

$ date
$ ls -l /etc/localtime

Another option is to type the following command on systemd based distro such as CentOS 7 to see timezone along with the grep command and timedatectl command:

Read more

Share