How To Set Up Time Synchronization on Ubuntu?

Time synchronization is an important part of maintaining a healthy Linux system. It ensures that all system clocks are accurate and in sync with each other. There are a few different ways to set up time synchronization on Ubuntu.

In this article, we will cover how to use the timedatectl and timesyncd tools, as well as how to switch to ntpd. We will also go over some troubleshooting tips in case you run into any issues.

Before you begin this guide, you should have a basic understanding of the Linux command line. You will also need to have sudo privileges on your system.

Navigating basic time commands

The first thing we need to do is take a look at some of the basic time commands that are available on Linux. The date command will print the current date and time to the terminal:

date

Thu Apr 12 18:21:29 UTC 2018

The hwclock command will print the Hardware Clock, which is also known as the BIOS Clock. This is the clock that is used when the system is powered off:

hwclock --show

Thu 12 Apr 2018 06:21:29 PM UTC -0.064143 seconds

The timedatectl command is a newer tool that can be used to view and change the system time and date. It can also be used to enable or disable the network time synchronization:

timedatectl

Local time: Thu 2018-04-12 18:24:51 UTC
Universal time: Thu 2018-04-12 18:24:51 UTC
RTC time: Thu 2018-04-12 18:24:51
Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no

The timesyncd service is used to sync the system clock with a remote NTP server. This service is enabled by default on Ubuntu.

Also check: How to Use the Linux watch Command

Configuring timedatectl and timesyncd

The timedatectl command can be used to configure the system time and date. By default, the system time is set to UTC. If you want to change it to your local time zone, you can use the following command:

sudo timedatectl set-timezone America/New_York

You can also use the timedatectl command to enable or disable the network time synchronization. This can be done with the following command:

sudo timedatectl set-ntp true

The timesyncd service will now sync the system clock with a remote NTP server.

Switching to ntpd

If you want more control over the time synchronization, you can switch to using the ntpd service. This service can be installed with the apt command:

sudo apt install ntp

Once the service is installed, you can start it with the following command:

sudo systemctl start ntp

You can also enable the service to start automatically at boot:

sudo systemctl enable ntp

The ntpd service will now sync the system clock with a remote NTP server.

Setting up time synchronization

Now that we have covered the basics, let’s go over how to set up time synchronization on Ubuntu. There are a few different ways to do this, so we will cover the most common methods.

Using timedatectl command

The first way is to use the timedatectl command. This command can be used to view and change the system time and date. It can also be used to enable or disable the network time synchronization. To use this command, you will need to know the IP address of a remote NTP server. You can use the following command to set the NTP server:

sudo timedatectl set-ntp server.ntp.org

Using the ntpdate command

The second way to set up time synchronization is to use the ntpdate command. This command can be used to sync the system clock with a remote NTP server. To use this command, you will need to know the IP address of a remote NTP server. You can use the following command to set the NTP server:

sudo ntpdate server.ntp.org

Using the chrony service

The third way to set up time synchronization is to use the chrony service. This service can be installed with the following command:

sudo apt install chrony

Once the service is installed, you can start it with the following command:

sudo systemctl start chrony

You can also enable the service to start automatically at boot:

sudo systemctl enable chrony

Using the systemd-timesyncd service

The fourth way to set up time synchronization is to use the systemd-timesyncd service. This service is enabled by default on Ubuntu. To use this service, you will need to know the IP address of a remote NTP server. You can use the following command to set the NTP server:

sudo timedatectl set-ntp server.ntp.org

Using the ntpd service

The fifth and final way to set up time synchronization is to use the ntpd service. This service can be installed with the following command:

sudo apt install ntp

Once the service is installed, you can start it with the following command:

sudo systemctl start ntp

You can also enable the service to start automatically at boot:

sudo systemctl enable ntp

The ntpd service will now sync the system clock with a remote NTP server.

Conclusion

In this article, we have covered how to set up time synchronization on Ubuntu. We have also gone over some troubleshooting tips in case you run into any issues.