In Linux, NTP (Network Time Protocol) is a protocol used to synchronize the clock on a computer with a reference time source over the network. The NTP ensures that the clock on the computer is accurate and consistent with other time sources on the network.
This guide will offer the step-by-step procedure to update the clock forcefully using the NTP in Linux.
Method 1: Using the ntpdate Command
The NTP protocol is designed to be highly accurate and reliable and can synchronize clocks with an accuracy of a few milliseconds or less. To force a clock update utilizing NTP in Linux, execute the “ntpdate” command. It queries an NTP server and sets the system clock accordingly.
Here are the steps to force a clock update using NTP in Linux:
Prerequisite: Install the ntpdate Package
To install the ntpdate package, run the “ntpdate” command on the current system:
$ sudo apt install ntpdate # Ubuntu, LinuxMint and Debian $ sudo yum install ntp # CentOS $ sudo dnf install ntp # Fedora
The output shows that the “ntpdate” package has been installed in the system.
Step 1: Update the Clock Using an NTP Server
Users can use different servers such as “NTP”, “Chrony”, “PTP,” and many more. But, the “NTP” is a widely-used time server pool that provides accurate time synchronization for computers and other devices connected to the internet. To update the clock via the NTP server, utilize the “ntpdate” command by specifying the server “pool.ntp.org” to get the current time:
$ sudo ntpdate pool.ntp.org
The output shows that the NTP server “pool.ntp.org” has got the current time.
Step 2: Restart the NTP Daemon Service
To restart the NTP services, utilize the “systemctl” command with the “restart” option by specifying the “ntp” as below:
$ sudo systemctl restart ntp
In this way, the ntp services have been restarted.
Step 3: Check System Time
Once the command has been completed, use the “date” command to check the time on the system:
It presents the current date and time.
Method 2: Using the ntpd service
To configure the system to periodically update the clock using the NTP daemon (service). The step-by-step instructions to force a clock update using NTP:
Step 1: Install the NTP Daemon
To install the NTP daemon, use the “ntp” package command with the “install” utility in the following command:
$ sudo apt install ntp # Debian/Ubuntu $ sudo yum install ntp # CentOS $ sudo dnf install ntp # Fedora
The output shows that the ntp package has been installed with all dependencies.
Step 2: Start the NTP Daemon
Once installed, start the NTP daemon utilizing the below command:
$ sudo service ntp start
It starts the NTP daemon and configures it to update the clock on the system periodically automatically.
Users can also start the NTP daemon via the “/etc/init.d/ntp” configuration file with the “start” utility as below:
$ sudo /etc/init.d/ntp start
The output shows that ntp.services have been started. It runs in the background of a Linux system and continuously adjusts the system clock to maintain accuracy.
To force a clock update using the NTP server, use the “ntpdate” command and “ntpd” service. Both these methods synchronize the time on the system with the time on a reliable external time source, such as an NTP server. It has various applications, such as scheduling tasks, logging events, and authenticating network transactions.
This guide has illustrated all feasible methods to force a clock update using an NTP server.