adplus-dvertising
10.5 C
Amsterdam
angeloma
Senior Writer and partner

A NTP Server by installing Chrony on Ubuntu 20.04

Hello, friends. In this post, we’ll show you how to set up an NTP server by installing Chrony on Ubuntu 20.04

An NTP server is important because it allows all devices on a network to be synchronized via a clock. That is, they all have the same time and time zone. This may seem unimportant, but the correct functioning of many services depends on proper time settings.

Now, there is a tool called Chrony that allows us to quickly deploy an NTP server.

According to the Chrony website:

Chrony is a versatile implementation of the Network Time Protocol (NTP). It can synchronize the system clock with NTP servers, reference clocks (e.g. GPS receiver), and manual input using wristwatch and keyboard. It can also operate as an NTPv4 (RFC 5905) server and peer to provide a time service to other computers in the network.

Fortunately, it has good support for many Linux distributions and Ubuntu is no exception.

Chrony on Ubuntu 20.04

Before starting, the server must have the time zone set correctly.

So, open a terminal or connect via SSH.

sudo timedatectl set-timezone Europe/Berlin

Replace Europe/Berlin with the correct timezone for your server.

To check the changes, run the command timedatectl.

Output:

               Local time: Wed 2021-05-12 21:13:11 CEST
           Universal time: Wed 2021-05-12 19:13:11 UTC 
                 RTC time: Wed 2021-05-12 19:13:12     
System clock synchronized: yes                         
              NTP service: active                      
                Time zone: Europe/Berlin (CEST, +0200) 
          RTC in local TZ: no 

Now we can install the chrony package from the official Ubuntu 20.04 repositories.

sudo apt update
sudo apt install chrony
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  systemd-timesyncd
The following NEW packages will be installed:
  chrony
0 upgraded, 1 newly installed, 1 to remove and 11 not upgraded.
Need to get 220 kB of archives.
After this operation, 290 kB of additional disk space will be used.
Do you want to continue? [Y/n]

The program is quite lightweight so the installation will take almost no time at all.

So, start the Chrony service and have it start with the system.

sudo systemctl start chronyd
sudo systemctl enable chronyd

Check the status of the service

sudo systemctl status chronyd
● chrony.service - chrony, an NTP client/server
     Loaded: loaded (/lib/systemd/system/chrony.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-05-12 21:16:25 CEST; 1min 36s ago
       Docs: man:chronyd(8)
             man:chronyc(1)
             man:chrony.conf(5)
   Main PID: 1815 (chronyd)
      Tasks: 2 (limit: 2286)
     Memory: 1.0M
     CGroup: /system.slice/chrony.service
             ├─1815 /usr/sbin/chronyd -F -1
             └─1816 /usr/sbin/chronyd -F -1

May 12 21:16:25 osradar systemd[1]: Starting chrony, an NTP client/server...
May 12 21:16:25 osradar chronyd[1815]: chronyd version 3.5 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +SECHASH +IPV6 -DEBUG)
May 12 21:16:25 osradar chronyd[1815]: Initial frequency -38.890 ppm
May 12 21:16:25 osradar chronyd[1815]: Loaded seccomp filter
May 12 21:16:25 osradar systemd[1]: Started chrony, an NTP client/server.
May 12 21:16:32 osradar chronyd[1815]: Selected source 2001:67c:1560:8003::c7
May 12 21:17:38 osradar chronyd[1815]: Selected source 2001:1600:4:1::123

And you will know that the service is running correctly.

Configuring Chrony on Ubuntu 20.04

Now that we have the service installed, we need to configure it. The Chorny configuration file is /etc/chrony/chrony.conf which we need to modify but first make a backup of it.

sudo cp /etc/chrony/chrony/chrony.conf `/etc/chrony/chrony.conf.bak

And now edit it:

sudo nano /etc/chrony/chrony.conf

And set the nearest NTP servers

server [NTP server]

Then save the changes and close the editor.

Now do the synchronization

sudo timedatectl set-ntp true

After that, restart the Chrony service.

sudo systemctl restart chronyd

Then, test the changes by checking the Chrony sources

chronyc sources

Output

210 Number of sources = 8
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^- golem.canonical.com           2   6    37     5  +6082us[+6082us] +/-   54ms
^- chilipepper.canonical.com     2   6    67     3   +313us[ +313us] +/-   47ms
^- alphyn.canonical.com          2   6    37     5   +892us[ +892us] +/-  119ms
^+ pugot.canonical.com           2   6    37     4  +1452us[+1452us] +/-   71ms
^* 25000-021.cloud.services>     2   6    37     6   +881us[  -83us] +/-   48ms
^- ns1.luns.net.uk               2   6    37     4  +2533us[+2533us] +/-   67ms
^+ 2a01:4f8:c2c:3d20::1          3   6    37     4  -1651us[-1651us] +/-   93ms
^+ time02.nevondo.com            2   6    37     4  +1028us[+1028us] +/-   43ms

So, everything is correct.

Note: I am uing the default server. In this output, you will see the server that you added.

Configuring the Chrony Client

Now it’s time to do the client configuration. Regardless of the Linux distribution you use, you have to set the Timezone correctly.

sudo timedatectl set-timezone Europe/Berlin

Proceed now to install the client on your distribution.

For example, on CentOS it would be

sudo dnf install chony

Or on Debian based distributions:

sudo apt install chrony

Next, you have to configure Chrony to serve the server you have configured.

sudo nano /etc/chrony/chrony.conf

And add the Chrony server:

server chrony-server-ip

Save the changes and close the editor. Now synchronise your computer with the created NTP server.

sudo timedatectl set-ntp true

You can also verify the changes by running

chronyc sources

So, enjoy it.

Conclusion

An NTP server is a simple tool to set up but it will help you to keep everything in order on your network. This step is essential for many computer systems.

- Advertisement -

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Donate to Osradar

Latest article