How to Set Timezone and Sync Server Time with NTP in Linux

How to Sync Server Time with NTP in Linux Using Systemd

In this article we will learn what the NTP is, how to sync your server time and date using systemd-timesyncd network time service, and how to set the timezone in Linux.

You can easily keep your system’s date and time accurate by using NTP (Network Time Protocol). It lets you to synchronize computer clocks through network connections and keep them accurate. Basically a client requests the current time from a remote server, and uses it to set its own clock.

How to synchronize time with NTP using systemd

The majority of Linux distributions have adopted systemd, and with it comes the systemd-timesyncd daemon. That means you have an NTP client already preinstalled, and there is no need to run the full-fledged ntpd daemon anymore. The built-in systemd-timesyncd can do the basic time synchronization job just fine.

To check the current status of time and time configuration via timedatectl and timesyncd, run the following command.

timedatectl status
               Local time: Thu 2021-05-13 15:44:11 UTC
           Universal time: Thu 2021-05-13 15:44:11 UTC
                 RTC time: Thu 2021-05-13 15:44:10
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

If you see NTP service: active in the output, then your computer clock is automatically periodically adjusted through NTP.

If you see NTP service: inactive, run the following command to enable NTP time synchronization.

timedatectl set-ntp true

That’s all you have to do. Once that’s done, everything should be in place and time should be kept correctly.

In addition, timesyncd itself is still a normal service, so you can check its status also more in detail via.

systemctl status systemd-timesyncd
systemd-timesyncd.service - Network Time Synchronization
      Loaded: loaded (/usr/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled) 
      Active: active (running) since Thu 2021-05-13 18:55:18 EEST; 3min 23s ago

If it is disabled, you can start and make systemd-timesyncd service active like this:

systemctl start systemd-timesyncd
systemctl enable systemd-timesyncd

How to change timezone

Before changing your time zone, start by using timedatectl to find out the currently set time zone.

               Local time: Thu 2021-05-13 16:59:32 UTC
           Universal time: Thu 2021-05-13 16:59:32 UTC
                 RTC time: Thu 2021-05-13 16:59:31
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: inactive
          RTC in local TZ: no

Now let’s list all the available time zones, so you know the exact name of the time zone you’ll use on your system.

timedatectl list-timezones

The list of time zones is quite large. You do need to know the official time-zone name for your location. Say you want to change the time zone to New York.

timedatectl set-timezone America/New_York

This command creates a symbolic link for the time zone you choose from /usr/share/zoneinfo/ to /etc/localtime.

In addition, you can skip the command shown above, create this symbolic link manually and achieve the same result.

ln -s /usr/share/zoneinfo/America/New_York /etc/localtime

1 Comment

Leave a Reply

Your email address will not be published.

Latest from Tutorials