Simple NTP Setup On Your Linux Servers

The Network Time Protocol (NTP) runs over port 123 UDP at transport Layera and is used to synchronize a computer’s time with another computer- usually a centralized time server. Not all clocks run at exactly at same speed. After a long enough period, the time of one clock will either end up ahead or behind another, causing what's called a "time drift". This situation can lead to inconsistent time issues, especially on servers. Issues like wrong times in log files, for cron jobs, for servers resources or databases replicatation etc. The NTP server package are already available from official CentOS repositories and can be installed using the following command.

LinuxSuit ~#  yum install ntp

When the package is successfully installed it's time to configure the NTP server. NTP is configured and controlled via a control file called conveniently called "ntp.conf," and you can find it in /etc/ntp.conf directory. NTP configuration is usually comprised of two parts. First is list of servers for our NTP to sync time with and second is list of networks that are allowed to query our server for time synchronization . For first part, we are going to add a server list provided by You can choose your Continent , then search for your Country and a list of NTP servers will be provided. Then you just need to copy+paste that list into the configuration file. It should look something like this


For 2nd part we are going to allow our local network to query our server and localhost to get full access to query or modify.

restrict mask nomodify notrap

We also can specify the drift file and the log file location in our configuration.

driftfile /var/lib/ntp/ntp.drift
logfile /var/log/ntp.log

When the configuration is finished, save and close the configuration file, then restart the ntp service.

LinuxSuit ~# service ntp restart

That's basically it. Your NTP should be set up, ensuring that your server is synchronized with your regional time allowing you to avoid time-sensitive errors. Just in case you were wondering, ServerSuit does offer NTP already preconfigured to just add to your servers whenever you might need it. Not that it's hard to set up, but we got a whole set of software available, also preconfigured, so why not include NTP? 

That's it for this article. Our next one will cover disk performance monitoring, so look out for that in the near future!

Until next time! 

April 28 2016

Add or review comments

Please leave your comment

Existing comments

Comments 1

Richard Turner
Good article. It's a little amazing that, up until recent years, most Linux distributions didn't set up NTP by default as part of the installation process. Even more amazing was that commercial UNIXes for big iron didn't bother to having that configured either. I *still* go into sites and find that they have no time service set up and, if they do, aren't setting up the actual NTP client, instead relying on `ntpdate' to poll some router to set the date/time when the system is booting. Then they wonder why timestamps on various systems tend to deviate after systems are up for weeks and months. One nit: It still makes sense to set up a single NTP server on your network (plus a backup or two--to form a local pool--depending on how big the local network is). There's really little need for the rest of the servers and workstations to be going out to the internet and hitting higher tier servers.