For many people, computer clocks in your devices, network machines, and servers are generally accurate. But that’s not true! These clocks are manually maintained and backed by batteries which over time drift the clock, especially in the older machines.
So why is accurate time so important? Having exact time on your machine is quite significant because of several reasons. Many aspects of your computer activity are linked with time. Perfectly synched time is crucial for tracking security-related issues; troubleshooting can become quite difficult if the timestamps in log files are incorrect. Even for financial services, keeping accurate time is critical.
Many companies solve time-related issues by connecting their networks with NTP. So what is NTP? Let’s dig into it first:
What is NTP
The full form of NTP is “Network Time Protocol”, which has been one of the most authentic ways to synchronize the clock over a network. If your system uses NTP, you don’t need to check and set your time manually. It automatically updates the clock every time the device reboots. It is an extremely accurate way to update the clock of your device. Since the internet is everywhere, NTP is being used by every modern computer.
How to Enable NTP Synchronization on Linux
Most of the Linux distributions are using “systemd”, which comes with NTP for clock synchronization. To verify this, use the command given below:
It indicates that NTP is active. If, for some reasons, it is not active, then use the below-mentioned command to enable it:
How to Enable NTP for Linux Distributions without “systemd”
But what if your distribution does not come with “systemd”? Well, in that case, you can install NTP.
For Debien based distros, use:
For Fedora:
For Arch Linux:
For Red Hot and CentOS:
If you are installing NTP on a distribution that supports “systemd”, then you need to disable the NTP service of “systemd”:
How to Start NTP
Once the installation is completed, NTP will be active by default. But if it is inactive, then use:
To keep it enable upon rebooting use:
How to Check the Status of NTP
To check the status of NTP use:
How to Check NTP Stats
To check NTP stats, use the command:
How to Monitor NTP Daemon
To monitor the NTP daemon, we will use the “ntpq” utility with the “-p” flag:
How to Modify the “ntp.conf” File
You can modify the NTP configuration file according to your preference. To open the files, use:
Or if you have vim installed, then use:
It can be seen in the image below that different default server systems are synchronized with time.
You can keep the default settings, but if you want to add another pool directive, then visit NTP pools and add the lines in the configuration file following the syntax mentioned below:
For instance, you can find NTP pools of United States from here:
How to Implement NTP on Linux Using Chrony
There is another modern tool to implement NTP on the latest Linux distributions. Firstly, let’s check how to install it on various distributions.
For Debian based distros, use:
For Red Hot and CentOS, use:
For Fedora:
To enable the chrony daemon, use:
Now, verify it by checking the status:
To check information about sources and other stats, use:
For detailed output, use the “-v” option with the above command:
To check the name of the server to which our computer is currently synchronized, use:
To check and modify the configuration file, use:
The above command is for Debian and Ubuntu, for Red Hot, Fedora, and CentOS, use:
Conclusion
Synchronization of time is essential to determine some specific activity of a computer. Every modern system comes with some mechanism that automatically sets the time of the machine; NTP (Network Time Protocol) is one of them.
In this write-up, we learned how to sync time with the NTP server. If your distribution is “systemd” based, your clock is already synced with NTP. We also discussed installing and enabling NTP service for the distributions that are not based on “systemd”. There is another utility for NTP configuration called “Chrony”, which has some additional features but essentially does the same job.