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:
By entering the user’s password, we will already be root users.
Once logged in as root user, we must update the system. To this end, we write:
apt update && apt -y upgrade
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
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:
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.
And we proceed to change the timezone:
timedatectl set-timezone America/Caracas
After that, we run the timedatectl command again:
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
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
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:
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
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:
but to do the above procedure, we must stop the ntp service:
sytemctl stop ntp
sytemctl start ntp
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.