To configure a Linux computer as a basic NTP client, we need to go through the following steps:
Installing the NTP package
For CentOs, RedHat and Fedora distributions
yum install ntp
For Ubuntu and Debian distributions
apt-get install ntp
or
sudo apt-get install ntp
Configuring the NTP service
With your favorite text editor, make sure these lines are present in the file /etc/ntp.conf
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
It is also wise to make sure the log file is established:
logfile /var/log/ntp.log
Server addresses vary according to the Linux distribution. You can use the default ones or specify your own time server or a public NTP server of your preference. You can find a list of public ntp servers in this link: http://support.ntp.org/bin/view/Servers/NTPPoolServers.
It is recommended than more than one ntp server is present for redundancy in case one of the servers fail.
You might have noticed the word iburst in every line. The iburst option reduces the time in the initial synchronization and it is the default option.
The specified servers are used in a round-robin fashion. If you wish you to use one server above others, add the options prefer at the end of the server line like this:
server 0.centos.pool.ntp.org prefer
Starting the NTP Service
For CentOs and RHEL/RedHat distributions
/etc/init.d/ntpd start
or
service ntpd start
For Debian and Ubuntu distributions (notice there’s a d missing)
/etc/init.d/ntp start
or
service ntp start
For Fedora and CentOS/Redhat/RHEL 7 distributions
systemctl start ntpd.service
The system will start synchronizing.
Verifying the NTP operation
Enter the command:
# ntpq -p
And you’ll see an output similar as the follow:
Values will be moving through time. The entry marked with the * is the server currently in use. If you see errors or no server association in a few minutes, probably the NTP service has not started. Review the log file to obtain more information.
Sync the local clock with the NTP server for the first time
Issue the following command:
ntpdate –u 18.26.4.105 -> or any server your computer is syncing to
Make the NTP service start when the computer boots
To add the ntp service to the list of daemons which start at startup:
For CentOs and RHEL/RedHat distributions
chkconfig ntpd on
For Debian and Ubuntu distributions (notice there’s a d missing)
systemctl enable ntp.service
o for Debian Jessie (Debian 8)
systemctl enable ntp
For Fedora and CentOS/Redhat/RHEL 7 distributions
systemctl enable ntpd
I know, I know, I wish everybody could standardize. Feel free to comment with any possible correction or suggestions to this post.