Network Time Protocol (NTP) is used to automatically synchronize computer system clocks over a network. It uses UTC (Coordinated Universal Time) for this purpose. It is important to synchronize time on all systems of a network for accurate timestamps, proper logging and other time-dependent activities. In this article, we will learn how to synchronize time with NTP in Linux.
How to Synchronize Time with NTP in Linux
Here are the steps to synchronize time with NTP in Linux. We will use Chrony package for this purpose. It is available for most Linux systems and consists of chronyd daemon service and chronyc command line tool to monitor and manager chronyd.
Chrony is a powerful NTP implementation used in many cases. It can be installed as a client (on server) and configured to refer to a universal clock such as GPS receiver, or be manually configured with input time. It can also be configured as peer to peer to service, where chrony is installed on all systems in the network.
1. Install Chrony in Linux
Open terminal and run the following command to install Chrony in Linux server.
$ sudo apt-get install chrony [On Debian/Ubuntu] $ sudo yum install chrony [On CentOS/RHEL] $ sudo dnf install chrony [On Fedora 22+]
Once chrony is installed, run the following commands to start and enable it to run automatically during system boot.
# systemctl enable --now chronyd # systemctl status chronyd
You can always run the following command to check if chrony is up & running.
# chronyc activity
2. Check Chrony Synchronization
You can run the following command to check list of servers available, status and offsets from local clock and source. Using -v option shows description for each source.
# chronyc sources OR # chronyc sources -v
If you want to see some more useful information about the sources, use the following command.
# chronyc sourcestats OR # chronyc sourcestats -v
To check chronyc tracking, run the following command.
# chronyc tracking
3. Configuring Chrony Time Sources
The main chrony configuration file is located at /etc/chrony.conf (CentOS/RHEL/Fedora) or /etc/chrony/chrony.conf (Ubuntu/Debian).
By default, chrony uses a certain set of servers to fetch UTC time information and synchronize clocks on network. If you want to add another server, open configuration file in text editor.
# vim /etc/chrony.conf OR # vim /etc/chrony/chrony.conf
Here is an example to add several servers.
server 0.europe.pool.ntp.org iburst server 1.europe.pool.ntp.org iburst server 2.europe.pool.ntp.org ibusrt server 3.europe.pool.ntp.org ibusrt
You can use website ntppool.org to find servers. Here is a command to add a pool of servers instead of single servers as shown above.
pool 0.pool.ntp.org burst
Once you have made the required changes, save and close the file, and restart server.
$ sudo systemctl restart chrony OR # systemctl restart chronyd
Once you have updated chrony configuration file, run the following command to restart the service.
In this article, we have learnt how to synchronize time with NTP.
How to Enable Confirmation for rm Command
How to Share Linux Terminal Session With Others
How to Use WhoIs Command in Linux
How to Extract & Copy Files from ISO Image
Tools to Scan Linux for Viruses & Malware