In this guide, 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 the Initial Server Setup with Ubuntu 22.04.
Now follow the steps below to complete this guide.
Check 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:
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.
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.
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
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:
Output ● ntp.service - Network Time Service Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: e> Active: active (running) since Sat 2022-09-03 08:43:47 CEST; 6s ago Docs: man:ntpd(8) Process: 3084 ExecStart=/usr/lib/ntp/ntp-systemd-wrapper (code=exited, stat> Main PID: 3104 (ntpd) Tasks: 2 (limit: 2282) Memory: 1.3M CGroup: /system.slice/ntp.service └─3104 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 112:119
To get more information about the status of ntpd, you can use the following command:
Your output should similar to this:
Output remote refid st t when poll reach delay offset jitter ============================================================================== 0.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 1.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 2.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 3.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 ntp.ubuntu.com .POOL. 16 p - 64 0 0.000 0.000 0.000 ...
Your output will be different but you should see the default Ubuntu pool servers plus a few others.
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 times 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
Then, start the timesyncd with the following command:
sudo systemctl start systemd-timesyncd
Verify that 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:
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 the “NTP service: active” means that the timesyncd is enabled and running.
At this point, you learn to view the system time, change time zones, work with ntpd and switch to timesyncd on Ubuntu 22.04.
Hope you enjoy it.
You may 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