The time in Linux, and in any operating system, is essential so that many internal processes of the system and applications can be used correctly, the cause is that some misconfiguration at the time level can create synchronization conflicts that in the end It will affect operations such as data backups, data downloads, updates and more..
NTP (Network Time Protocol) is a protocol available to use time synchronization services through thousands of servers worldwide so that the various time zones can be in real time, to be taken into account that NTP clients and servers are synchronized based on the Coordinated Universal Time (UTC) time scale and hence the importance of activating and using this synchronization in Linux.
TechnoWikis will explain to you how we can synchronize the time in Linux to an NTP server in a simple way..
To stay up to date, remember to subscribe to our YouTube channel! SUBSCRIBE
How to sync Linux time with NTP server
Step 1
The first thing will be to validate if our system has active synchronization, we open the terminal and validate the current state of the time:
timedatectl
Step 2
We find details like:
- Local, universal and RTC time
- Clock system synchronization status
Step 3
If it is necessary to activate the synchronization with NTP, we execute the following:
sudo timedatectl set-ntp true
Step 4
NTP events can be accessed by running the following:
sudo cat /var/log/syslog | grep ntp
step 5
We have applied the filter using grep so that the ntp results are displayed:
Step 6
Now let's install the NTP client:
sudo apt install ntpdate
Step 7
ntpdate gives us the ability to set the date and time via NTP and this is achieved by performing a scan of the NTP servers which can be entered as server arguments and must be run as root.
The ntpdate command can be run manually or by using a script.
Now let's install NTP as a "daemon" for local work:
sudo apt install ntp
step 8
We confirm the process:
step 9
If we use Fedora we must execute:
sudo dnf install ntp
sudo pacman -S ntp
sudo zypper install ntp
step 10
We enable the NTP service:
sudo systemctl enable ntp
step 11
We start the service so that it loads together with the system:
sudo systemctl start ntp
step 12
We check if the computer communicates with a time server:
ntpstat
step 13
The ntpstat command shows us the synchronization status of the network time, there we find with which server it has been synchronized (78.112.15.178) on what level (3), how long the synchronization took (109 ms) and how often the process (64 sec).
We will now use ntpq to list the active time servers:
ntpq -p
step 14
The ntpq utility allows us to monitor the ntpd operations of the NTP daemon and thus know its performance, it can be executed in interactive mode or using command line arguments.
ntpq makes use of NTP mode 6 packets in order to establish contact with the NTP server and thus is ideal for synchronizing with any compatible server on the network that is available.
Some parameters available with ntpq are:
- -4: Force DNS resolution to use IPv4 names
- -6: force resolution to make use of IPv6 names
- -c: is an interactive format command and can be added to the list of commands executed on the indicated hosts
- -d: activate debugging mode
- -Yo. force ntpq to work in interactive mode
- -n – Display all host addresses in dotted-four numeric format
- -p: prints a list of peers known to the server and a summary of them
step 15
We can run "ntpq" to access the console and then enter "?" to see the various options:
step 16
Now we will make use of Chrony, Chrony is an implementation of the NTP protocol with which it is possible:
- synchronize the system clock using a manual time entry
- synchronize system clock using NTP servers
step 17
chrony is composed of chronyd, this is a daemon that runs in user space and there is also chronyc which is a command line program to monitor the performance of chronyd and adjust parameters if necessary, we install the Chrony daemon:
sudo apt install chrony
step 18
Confirm the process:
step 19
To validate the time servers we run. Precise data from the servers accessed for synchronization is displayed there.
chronycsources
TechnoWikis has explained to you how to synchronize the time in Linux with NTP in a functional way so that you can put it into practice.