Set Up Time Synchronization on Ubuntu 22.04

In this guide from the Orcacore website, we want to teach you How To Set Up Time Synchronization on Ubuntu 22.04. In modern computer networks, time synchronization is critical because every aspect of managing, securing, planning, and debugging a network involves determining when events happen. Time also provides the only frame of reference between all devices on the web. Accommodating log files between these devices without synchronized time is difficult, even impossible.

The Network Time Protocol (NTP) has long been the leader in time-setting software. Some companies solve the problem of synchronizing their networks by using NTP to go out on the Internet to get time from a public Internet Time Server. 

Steps To Set Up Time Synchronization on Ubuntu 22.04

To set up time synchronization, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on the Initial Server Setup with Ubuntu 22.04.

Now follow the steps below to complete this guide.

1. Check Current Time Zone And Clock on Ubuntu 22.04

The most basic command to find out the time on your server is “date”. Any user can run the following command to check the date and time on Ubuntu 22.04:

sudo date
Example Output
Sat 03 Sep 2022 08:37:54 AM CEST

Note: Most often, your server will default to the UTC time zone. UTC is Coordinated Universal Time, the time at zero degrees longitude. Also, using Universal Time reduces confusion when your infrastructure spans multiple time zones.

Change Time Zone on Ubuntu

If you have requirements and need to change the time zone on Ubuntu 22.04, you can use the “timedatectl” command.

First, list the available time zones on Ubuntu 22.04 with the following command:

sudo timedatectl list-timezones

In your output, you will see a list of available time zones on Ubuntu 22.04.

When you find the correct time zone, use the following command to set the time zone:

sudo timedatectl set-timezone America/New_York

Remember to replace the time zone you have found in the list.

Now that you know how to check the time zone and clock on Ubuntu 22.04, let’s install and start NTP.

2. Install NTP and Check the ntpd staus on Ubuntu 22.04

To install NTP on your server, you can use the following command:

sudo apt install ntp -y

Then, restart your service with the following command:

sudo systemctl restart ntp

Verify that the service is active and running on your server:

sudo systemctl status ntp

In your output, you will see:

ntp service - Network Time Service

To get more information about the status of ntpd, you can use the following command:

ntpq -p

Your output should be similar to this:

Check status of ntpd

Your output will be different, but you should see the default Ubuntu pool servers plus a few others.

3. Replace ntpd with systemd-timesyncd on Ubuntu 22.04

You can use systemd’s built-in timesyncd component to replace the ntpd. timesyncd is more integrated with systemd than ntpd.

It doesn’t support running as a time server, and it is slightly less sophisticated in the techniques it uses to keep your Ubuntu 22.04 time in sync.

If you are running complex real-time distributed systems, you may want to stay with ntpd.

First, you should uninstall ntpd with the following command to use timesyncd:

sudo apt purge ntp -y

Then, start the timesyncd with the following command:

sudo systemctl start systemd-timesyncd

Verify that the service is active and running:

sudo systemctl status systemd-timesyncd
Output
● systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; ve>
     Active: active (running) since Sat 2022-09-03 08:47:31 CEST; 20s ago
       Docs: man:systemd-timesyncd.service(8)
   Main PID: 3339 (systemd-timesyn)
     Status: "Initial synchronization to time server [2620:2d:4000:1::3f]:123 (>
      Tasks: 2 (limit: 2282)
     Memory: 1.3M
     CGroup: /system.slice/systemd-timesyncd.service
             └─3339 /lib/systemd/systemd-timesyncd

Now you can use the timedatectl command to print out systemd’s current understanding of the time on Ubuntu 22.04:

timedatectl
Output
 Local time: Sat 2022-09-03 08:49:01 CEST
           Universal time: Sat 2022-09-03 06:49:01 UTC
                 RTC time: Sat 2022-09-03 06:49:01
                Time zone: Europe/Berlin (CEST, +0200)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

System clock synchronized: yes” means that the time on Ubuntu 22.04 has been successfully synced, and “NTP service: active” means that timesyncd is enabled and running.

Conclusion

At this point, you have learned to view the system time, change time zones, work with ntpd, and switch to timesyncd on Ubuntu 22.04.

Hope you enjoy it. Please subscribe to us on Facebook, X, and YouTube.

You may also be interested in these articles:

Install and Configure NTP Server and Client on Ubuntu 22.04

Set up and Use Anaconda on Ubuntu 22.04

How To Install XAMPP on Ubuntu 22.04

Share your love

Stay informed and not overwhelmed, subscribe now!