How-to

How to Set Up Chrony on Ubuntu 18.04

What is Chrony?

Chrony is another implementation of the Network Time Protocol (NTP). It’s used to synchronize time and clocks from different NTP servers, reference clocks, and manual input.

Chrony can be used as an NTPv4 server (the RFC 5905), which provides a time service to other computers in the network. It’s provides two different programs, the chronyd which is the service daemon and the chronyc the command-line interface for configuring Chrony.

What we will do?

In this tutorial, you will learn how to set up Chrony on Ubuntu 18.04 Server. You will learn how to install and configure Chrony as an NTP Server. Also, using the Chrony as NTP Client.

Prerequisites

For this tutorial, make sure you have got a Ubuntu 18.04 server with root privileges.

Below is the tutorial about the Ubuntu 18.04 server installation.

Install Ubuntu 18.04 Server

Before going any further, log in to your Ubuntu server and type the sudo command to get the root privileges on your system.

sudo su

Step 1 – Install Chrony on Ubuntu 18.04 Server

First, you will install Chrony and it’s dependencies on the Ubuntu system. And by default, the chrony packages are available on the official Ubuntu repository.

Update the Ubuntu repository and install chrony using the apt command below.

apt update
apt install chrony

After that, start the chrony service and add it to the system boot.

systemctl start chrony
systemctl enable chrony

The chrony service is up and running, check it using the command below.

chronyc activity

As a result, you’ve installed Chrony on Ubuntu 18.04 Server.

Install Chrony on Ubuntu 18.04

Step 2 – Set Up Chrony NTP Server

After installing Chrony, you will change the default NTP pool of chrony and set up chrony as an NTP server.

By default, the chrony configuration ‘chrony.conf’ are located at the ‘/etc/chrony’ directory. Edit the chrony configuration ‘/etc/chrony/chrony.conf’ using vim editor.

vim /etc/chrony/chrony.conf

– Change Default NTP Pool

The NTP Pool is a collection of computer servers provided by volunteers to provide highly accurate time synchronization via the Network Time Protocol (NTP) to clients worldwide.

It’s recommended to use the NTP pool nearest to your zone, you can find the NTP pool based on your zone here.

Now change the default NTP pool with your nearest zone and make the configuration as below.

pool 0.jp.pool.ntp.org iburst maxsources 2
pool 1.jp.pool.ntp.org iburst maxsources 2
pool 2.jp.pool.ntp.org iburst maxsources 2
pool 3.jp.pool.ntp.org iburst maxsources 2

Save and close.

As a result, you’ve changed the default NTP pool with your nearest zone.

– Set Up NTP Server with Chrony

Next, you will make the server as an NTP server for all clients on the same local network.

Add the following configuration and change the server IP addresses with your own.

allow 10.5.5.0/24
allow 10.5.5.3

Save and close.

Now restart the chrony service with the command below.

systemctl restart chrony

As a result, you’ve created an NTP server for your local network with Chrony.

Change Default Pool and Set up NTP Server

Step 3 – Setup NTP Client with Chrony

In this step, you will set up an NTP client with Chrony, ane makes sure you have got the chrony packages installed on your client machines.

To set up the NTP client, edit the chrony configuration ‘/etc/chrony/chrony.conf’ using vim editor.

vim /etc/chrony/chrony.conf

Now change the default NTP pool with the configuration and below, and change the NTP server IP address with your own.

server 10.5.5.21 prefer iburst

Save and close.

After that, restart the Chrony service.

systemctl restart chrony

As a result, you’ve set up and NTP client using Chrony on the Ubuntu system.

Set Up NTP Client on Ubuntu System with Chrony

Step 4 – Testing

In this step, you will learn the ‘chronyc’ command to check the NTP server and clients.

– Check Time Sources for NTP

To check the current sources of the NTP server used by the chronyd service, use the ‘sources’ option as below.

chronyc sources

Below is the result you will get.

Check Sources of NTP Server

For details status, add the ‘-v’ option (as verbose).

chronyc sources -v

Below are the details of NTP sources.

Check Sources of NTP Server Details

Additionally, below are the result of the same command on the NTP Client machine.

Check Sources of NTP Server Details

– Check Clients Connected to the NTP Server

As you run the NTP server for your local network clients, check clients’ IP addresses which connected to the NTP server using the ‘chronyc’ command below.

chronyc clients

As a result, your clients have been connected to the local NTP server which you just set up on top.

Checking Chrony Client

Finally, you’ve successfully set up both the NTP server and client using Chrony on Ubuntu 18.04 Server.

Write A Comment