How to Sync Linux Time With NTP Server
One of the essential things that users need to ensure on their Linux system is that the clock is in sync with the correct time. Accurate timekeeping is critical for many applications, including security, authentication, and logging.
The Network Time Protocol (NTP) is a standard protocol that allows computers to synchronize their clocks with a reference time source. In this article, we will show you how to configure your Linux system to synchronize its time with an NTP server.
1. Install NTP
The first step is to install the NTP package on your Linux system. In most cases, you can install NTP using your system’s package manager. For example, on Ubuntu, you can use the following command:
sudo apt-get install ntp
On CentOS or Fedora, you can use the following command:
sudo yum install ntp
2. Configure NTP
Once NTP is installed, you need to configure it to sync the system time with an NTP server. The configuration file for NTP is located at /etc/ntp.conf.
Open the file with a text editor such as Nano or Vim:
sudo nano /etc/ntp.conf
In the configuration file, you will see a list of NTP servers that the system will try to synchronize with by default. You can add or remove NTP servers as needed.
For example, if you want to synchronize your system time with time.nist.gov, add the following line to the configuration file:
server time.nist.gov
Save and close the configuration file.
3. Start and enable NTP
After you have configured NTP, start the NTP daemon and enable it to start automatically at boot time:
sudo systemctl start ntpd
sudo systemctl enable ntpd
4. Verify NTP synchronization
To verify that your Linux system is synchronizing its time correctly with the NTP server run the following command:
ntpq -p
This command will display the list of NTP servers that your system is currently synchronizing with, the NTP version, and the current offset between your system clock and the reference clock.
Conclusion
In summary, synchronizing your Linux system time with an NTP server is easy and straightforward. By following the steps outlined above, you can ensure that your Linux system is always accurate and in sync with the correct time reference. Accurate timekeeping is essential for many applications and services, and it’s worth taking time to configure NTP correctly.