blog posts

Set or Change Time zone on CentOS 7

How to Change Time Zone in CentOS 7

Setting the correct time zone on your CentOS server is essential for accurate logging, reporting, and automated processes like cron jobs. This guide explains how to review, set, and manage the time zone in CentOS 7 step-by-step.

Access Your Server and CentOS via SSH

To begin, connect to your server via SSH. Use the following command:

Replace user with your username and your_server_ip with your server’s IP address.

Step 1: Check Current Time Zone

You can check your server’s current time and time zone using the date or timedatectl commands.

Example output:

Alternatively, use timedatectl:

Example output:

Step 2: List Available Time Zones

To list all available time zones:

This will display a comprehensive list of supported time zones in alphabetical order. Use grep to refine your search. For instance, to search for Pacific time zones:

Step 3: Set the Time Zone

Once you’ve identified the desired time zone, use the following command to set it:

Replace <Time_Zone> with the desired time zone, such as America/Chicago or Asia/Dubai.

Example:

After setting, verify the new time zone with:

Step 4: Set the System Date and Time (Optional)

To manually set the date and time, use the following format:

Example:

Verify the updated date and time with:

Step 5: Configure the Hardware Clock

The hardware clock (RTC) operates even when the system is powered off. To check if it’s using the local time zone:

Output:

To set the hardware clock to the local time zone:

To revert this setting:

Step 6: Enable NTP Synchronization

Network Time Protocol (NTP) synchronizes system time with remote servers. If not already installed, first install NTP:

To enable NTP synchronization:

To disable it:

Verify NTP synchronization status:

Best Practices

  1. Double-check the impact of time zone changes on server applications, especially cron jobs and logs.
  2. Use NTP synchronization to maintain accurate system time.
  3. Document the changes for future reference or audits.

Following these steps ensures your server’s time zone is configured correctly for smooth operations.

How to Change Time Zone in CentOS 7

conclusion

correctly setting the time zone on your CentOS 7 server is essential for ensuring accurate logging, smooth operation of automated tasks like cron jobs, and effective server management. By following the outlined steps—from checking the current time zone to enabling NTP synchronization—you can ensure that your server maintains the correct time, ultimately enhancing system reliability and preventing potential issues. Always verify your changes and consider any impact they may have on applications running on your server. Utilizing NTP synchronization is a recommended best practice to keep your server’s time accurate.