24.9 C
Guru Unix /Linux and GNU supporter

How to install NTP in Ubuntu server 18.04?

Network Time Protocol (NTP) is an Internet protocol for synchronizing computer system clocks through packet routing in networks with variable latency. NTP uses UDP as its transport layer, using port 123.

This server can be a single machine, several machines or a pool of NTP servers. An NTP server, in turn, can synchronize its time with another NTP server by creating a cascading system between NTP servers. The NTP protocol is able to synchronize the time of the equipment with an accuracy of milliseconds.

NTP is one of the oldest internet protocols still in use, developed in 1981 and first described in RFC 778. NTP was originally designed by David L. Mills of the University of Delaware1, who continues to maintain it, along with a team of volunteers.

Get to work!!

In Ubuntu server the root account is usually disabled. We don’t really need to enable it, but we do need to log in as root. To do this, write:

- Advertisement -

              sudo -i

By entering the user’s password, we will already be root users.

1.- Upgrading the System
1.- Root User

Once logged in as root user, we must update the system. To this end, we write:

               apt update &&  apt -y upgrade

2.- Upgrading Ubuntu
2.- Upgrading Ubuntu

This will provide the latest security patches and critical updates.

Next we must install the necessary packages to have an NTP server:

                 apt install ntp ntpdate

3.- Installing ntp
3.- Installing ntp

With these packages installed, we must now make sure that the Timezone of our equipment is according to its physical location, with the timedatectl command we will get the current one:


4.- timedatectl

If you do not have the Timezone correctly defined, then we proceed to change it. In this case I’ll use America/Caracas.

              timedatectl list-timezones | grep -i Caracas

List-timezones is the options that allows to list all the available timezones, combining it with grep we can filter it to quickly locate the right timezone.


5.- Finding right timezone
5.- Finding right timezone

And we proceed to change the timezone:

timedatectl set-timezone America/Caracas

After that, we run the timedatectl command again:

6.- Timedatectl
6.- Timedatectl

Basic configuration of NTP

Next, we must edit the file /etc/ntp.conf indicating the official NTP servers so that our server can synchronize. The active servers can be viewed on the Official NTP website http://www.pool.ntp.org/es/  Normally we must choose one located on our own continent.

In my case I must put in my configuration file, the following servers:

A)  server 0.south-america.pool.ntp.org
  B) server 1.south-america.pool.ntp.org
    C) server 2.south-america.pool.ntp.org
D) server 3.south-america.pool.ntp.org

               nano /etc/ntp.conf

7.- Editing file ntp.conf
7.- Editing file ntp.conf

If you find Ubuntu’s default NTP servers, you can comment on them and add the appropriate ones. Also, don’t forget that they take the word “pool” to the beginning.

We leave the editor and proceed to restart the service for the changes to take effect.

              systemctl restart ntp

8.- Restarting ntp
8.- Restarting ntp

The next step will be to verify if our server is synchronizing with the NTP servers that we place in our configuration file. We write:

              ntpq -p

9.- NTP server running
9.- NTP server running

In the previous image we see how the server is running and synchronizing with the servers placed in the file. Remember that ubuntu also defaults to a backup server.

Of the data shown, the most relevant are Remote, which is the name of the server; refid, which says the ip address of the server; Delay, which gives us the time in milliseconds of the delay between our server and the NTP server.

Configuring the clients

Now we’re going to set up an NTP client that uses the previous server as the primary one. I will use a computer with Debian 9 installed.

Just like on the server, we must install ntp:

apt install ntp

10.- Installing ntp in a client
10.- Installing ntp in a client

Next we must edit the file /etc/ntp.conf and add the ip address of our NTP server.

We can force synchronization with the following command:

               ntpdate ip_ntp_server

but to do the above procedure, we must stop the ntp service:

               sytemctl stop ntp


ntpd ip_ntp_server


               sytemctl start ntp

11.- Forcing Synchronization
11.- Forcing Synchronization

With this we already have NTP correctly configured. Remember that NTP works in a hierarchical fashion so that one server can actually target many. The important thing is that our teams are synchronized with each other, making them all have the same time and date, which is vital to maintaining order and data integrity in computer systems.


- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"


  1. I feel this article is missing some key details. Neither package ntp nor ntpdate is available in ubuntu 18.04 server by default (unless one enables the universe repository). Attempting to follow the above instructions results in ‘Package ‘ntp’ has no installation candidate’.

    Instead time synchronization is handled by default by the systemd service timesyncd. If one wants to install and use ntp and related utilities, one should first disable the timesyncd service, then add the universe repository, and then one can proceed to install ntp as described above.

  2. In clean Ubuntu 18.04 server installation IT IS NO LONGER REQUIRED TO INSTALL NTP PACKAGE separately as systemd has embedded timesynd to sync time via NTP. By default, Ubuntu uses ntp.ubuntu.com pool.


Please enter your comment!
Please enter your name here

Latest article