One of the most useful commands in Linux is NTP (Network Time Protocol) which is responsible for automatically synchronizing the time of our network server and this is a delicate point when we talk about a computer in productive environments since a bad synchronization The time may affect various tasks and more if the computer is a server..
The team can allow the system clock to use Coordinated Universal Time (UTC) instead of local time to be much more in line with the required time. As administrators , the classic way of synchronizing the time is by using the ntpdate command, which is responsible for configuring the system time from an established NTP time server.
We will analyze how to make use of NTP in Linux..
1. How to install NTP on Linux
By default, in most Linux distributions the NTP command is not installed, for its installation we will execute the following:
sudo apt-get install ntpdate (Debian / Ubuntu) sudo yum install ntpdate (CentOS / RHEL) sudo dnf install ntpdate (Fedora)
2. How to use NTP on Linux
Step 1
Time, to use NTP we can execute the following:
sudo ntpdate co.pool.ntp.org
Thus we establish said server as an NTP server.
Step 2
If we want to check the server and not configure the clock or use a port without privileges to send packets and to avoid firewalls, we must execute the ntpdate command next to the -qu parameter:
sudo ntpdate -qu co.pool.ntp.org
Step 3
The entire list of available NTP server groups can be found in the following link:
NTP server
There, on the right side, we find each of the world regions:
Step 4
By clicking on a continent, and its respective country, we can see the servers available to configure:
In the most recent Linux distributions, which have Systemd, it will be possible to synchronize the time through the timesyncd.conf file, just open the file with some editor to adjust it like this:
sudo nano /etc/systemd/timesyncd.conf
Step 5
There we must uncomment the following lines under [Time] and add the server as necessary:
NTP = server 0.south-america.pool.ntp.org FallbackNTP = ntp.ubuntu.com 0.arch.pool.ntp.org
We save the changes using the Ctrl + O keys and exit it using the Ctrl + X keys..
Step 6
Then, it will be necessary to activate the change of NTP server by executing the following:
sudo timedatectl set-ntp true timedatectl status
It's that simple to add an NTP server on Linux for everything related to time synchronization.