Setting up an NTP Server on Ubuntu using Chrony

In this tutorial, we will show you how to set up an NTP server on your Ubuntu system using Chrony.

Ubuntu NTP Server using Chrony

NTP stands for Network Time Protocol, and it is a way for operating systems like Ubuntu to keep their time synchronized.

While modern computing systems often have a real-time clock built into the motherboard, this timer can often drift over time. Synchronizing this time with super-accurate atomic clocks allows us to reduce this drift and keep the clocks all in sync.

These NTP servers are split into various tiers. The first tier is the highly accurate atomic clocks, and the second and third tiers are additional servers that feed data from the atomic clocks and spread the processing time.

Setting your Ubuntu server up as an NTP server allows it to act as one of these second or third-tier time servers.

To make your Ubuntu system an NTP server, we will use Chrony. While there are various solutions for setting up an NTP server, Chrony offers faster and more accurate time synchronization.

How to set up an NTP Server on Ubuntu

Over the following sections, we will walk you through the process of setting up an NTP server on your Ubuntu system.

If you use a desktop flavor of Ubuntu, you must open the terminal before continuing. You can open the terminal by pressing CTRL + ALT + T on your keyboard.

Installing the Chrony NTP Server

1. Your first step is to ensure that your Ubuntu system is up to date. To do this, run the following two commands within the terminal.

The first command will update the package list cache. The second will upgrade any out-of-date packages to the latest release.

sudo apt update
sudo apt upgrade -y

2. Once Ubuntu is up to date, we can move on to installing the Chrony NTP daemon on our system.

Luckily, Chrony is available through the official Ubuntu repository and can be installed by running the following command within the terminal.

sudo apt install chrony

Configuring the Chrony NTP Server on Ubuntu

3. Before running an NTP server on our Ubuntu system, we must modify the configuration of the Chrony software we just installed.

You can begin editing the config for Chrony by using the nano text editor by running the command below.

sudo nano /etc/chrony/chrony.conf

4. By default, Chrony is set to only act as an NTP client. This means it will only receive and update the time on your device.

To allow outside access to Chrony and allow others to use your Ubuntu device as an NTP server, you will want to add the “allow” directive to this file.

This directive can be written in serveral different ways. If you want anyone to have access to your NTP server, simply type in “allow“.

allow

Alternatively, Chrony does allow you to restrict access to particular IP addresses or subnets. For example, to lock access to the IP address “192.168.0.3“, you would use the following.

Chrony has support for multiple allow directives, just ensure each one is on a new line.

allow 192.168.0.3

Saving and Restarting Chrony

5. After allowing access to your NTP server, you can save and quit by pressing CTRL + X, Y, and then ENTER.

7. For all of your changes to take effect, you must restart the Chronyd service by running the following command within the terminal

Once the service restarts, you can connect to and use your Ubuntu device as an NTP server.

sudo systemctl restart chrony

Allowing the Chrony NTP Server through the Ubuntu Firewall

8. If you have the Ubuntu firewall configured on your system, then you will need to allow NTP through it before you can begin to use it.

The protocol that NTP uses is port 123 and can be allowed using UFW by using the following command.

sudo ufw allow 123/udp

Conclusion

Hopefully, you will have learned how to set up Chrony on your Ubuntu device as an NTP server.

Setting up this NTP client is relatively simple, and it only takes a few slight changes to get it to act as a server.

Please feel free to leave a comment below if you have had any issues with getting this timing protocol server to work.

If you liked this guide, we highly recommend investigating the many other Ubuntu tutorials we have on offer.

Leave a Reply

Your email address will not be published. Required fields are marked *