Time keeping is an important part of keeping an efficient software. Any service using event based system where the time has to be traced, includes functionalities like authentication, or systems running on distributed platforms, all functionalities like these requires the main system to be upto date with the time stamp of every event that occurred, it works like a time logger.
The service used for this is the Network Time Protocol (NTP), to use the system clock to our advantage with the outside workings of a system. Now this system clock can be an atomic clock, a GPS clock, or any other trusted clock that can work with NTP.
The practical implementation of NTP is NTP Pool Project. The pool consists of time servers that provides access to โ€œtheir timeโ€ for a huge number of clients around the globe. NTP time is the default of many Linux based Operatiing Systems and many of its Applications.
In this article you will learn how to setup NTP on your own server and how to configure it to your use, so the users connected to your server will have the accurate time with them. It is needed because it can help you use the complete bandwidth by knowing about the spare CPU cycles.
Before joining the NTP Pool Project you must fulfil the basic three requirement, and they are:
โฆ Static IP:
Your server must have a static IP address.
โฆ Stable Internet Connection:
Your server must have a permanent and stable internet connection.
โฆ Consistent IP address:
Your IP address most not change, or only changes infrequently (once a year or less).
Step 1 โ€” Installing NTP
Just like always lets just firstly, update your packages:
โฆ sudo yum update
โฆ
Then install NTP:
โฆ sudo yum install ntp
โฆ
Once the installation completes, start the service and configure it so it starts automatically each time the server boots:
โฆ sudo systemctl start ntpd
โฆ
โฆ sudo systemctl enable ntpd
โฆ
If you’ve configured the firewall as specified in the prerequisites, you must allow UDP traffic for the NTP service in order to communicate with the NTP pool:
โฆ sudo firewall-cmd –permanent –add-service=ntp
โฆ
โฆ sudo firewall-cmd –reload
โฆ
For more on FirewallD, refer toย How To Set Up a Firewall Using FirewallD on CentOS 7.
NTP is now installed, but it’s configured to use the default NTP pool time servers. Lets pick some specific time servers instead.
Step 2 โ€” Choosing an Upstream Server
Basically NTP Pool Project has a list of time servers they are Stratum 1 and Stratum 2. Down is the list of servers available for public access under stated restrictions:

โฆ OpenAccess: This time server is open to any client complying with the NTP Poolย โฆ usage recommendations.
โฆ RestrictedAccess: This time server has some access restrictions in addition to the NTP Pool usage recommendations.
โฆ ClosedAccess: This time server is closed or requires prior arrangement.
Visit theย Stratum 1 Time Servers list. You’ll see a list like the following:

The list above should be sorted by ISO code and find one or two servers that are close to you geographically. When the server’sย Access Policyย column statesย OpenAccess, you can use it without issue. If it says “RestrictedAccess”, click to open the entry and read the instructions noted in theย AccessDetailsย field. Often, you’ll find thatย NotificationMessageย is set toย Yes, which means you have to craft an informal email directed to the address provided inย ServerContact, informing the server operator about your desire to use this time server as a time source for your NTP Pool Project member.
Once you’ve identified the servers you’d like to use, click the link for each server in theย ISOย column and copy its host name or IP address. You’ll use these addresses in Step 3.
Next, select three or four servers from theย Stratum 2ย list, following the same process.
Once you have selected your time servers, it’s time to configure your NTP client to use them.
Step 3 โ€” Configuring NTP to Join the Pool
To use your server with the NTP pool, and configure your new time servers, you’ll need to make some modifications to your NTP daemon’s configuration. To do so, edit theย /etc/ntp.confย file:
โฆ sudo vi /etc/ntp.conf
โฆ
First, make sure aย driftfileย is configured. A driftfile stores the frequency offset between the system clock running at its nominal frequency, and the frequency required to remain in synchronization with correct time. It helps to achieve a stable and accurate time. You should find this at the top of your configuration file on a default installation:
/etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift


Next, remove the default time source entries from the configuration. You’re looking for all lines which are of the patternย server 0.centos.pool.ntp.org iburst. If you’re using a default configuration, remove the highlighted lines as shown in the following example:
/etc/ntp.conf

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
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
Replace the lines you removed with the hand-picked servers you selected in the previous step.
/etc/ntp.conf

server ntp_server_hostname_1 iburst
server ntp_server_hostname_2 iburst
server ntp_server_hostname_3 iburst
server ntp_server_hostname_4 iburst
server ntp_server_hostname_5 iburst

We use theย iburstย option for each servers, per the NTP Pool recommendations. That way, if the server is unreachable, this will send a burst of eight packets instead of the usual one packet. Using theย burstoption in the NTP Pool Project is considered abuse as it will send those eight packets every poll interval, whereasย iburstย sends the eight packets only the first time.
Next, make sure the default configuration does not allow management queries. If you don’t, your server could be used in NTP reflection attacks, or could be vulnerable toย ntpqย andย ntpdcย queries that attempt to modify the state of the server. Check that theย noqueryย option is added to the defaultย restrictย lines. Also make sure you add the optionsย kodย andย limitedย as they restrict too eagerly asking clients and enforce rate limiting.
/etc/ntp.conf

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default nomodify notrap nopeer noquery kod limited

# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict ::1
You can find more information about the other options in theย official documentation.
Your NTP daemon configuration file now should look like the following, although your file may have additional comments, which you can safely disregard:
/etc/ntp.conf

driftfile /var/lib/ntp/ntp.drift

restrict default nomodify notrap nopeer noquery kod limited

restrict 127.0.0.1
restrict ::1

server ntp_server_hostname_1 iburst
server ntp_server_hostname_2 iburst
server ntp_server_hostname_3 iburst
server ntp_server_hostname_4 iburst
server ntp_server_hostname_5 iburst
Save the file and exit the editor.
Now restart the NTP service and let your time server synchronize its clock to the upstream servers.
โฆ sudo systemctl restart ntpd
โฆ
After a few minutes, check the health of your time server with theย ntpqย command:
โฆ ntpq -p
โฆ
The output should look similar to this:
Output
remote refid st t when poll reach delay offset jitter
==============================================================================
mizbeaver.udel. .INIT. 16 u – 64 0 0.000 0.000 0.000
montpelier.ilan .GPS. 1 u 25 64 7 55.190 2.121 130.492
+nist1-lnk.binar .ACTS. 1 u 28 64 7 52.728 23.860 3.247
*ntp.okstate.edu .GPS. 1 u 31 64 7 19.708 -8.344 6.853
+ntp.colby.edu .GPS. 1 u 34 64 7 51.518 -5.914 6.669
Theย remoteย column tells you the hostname of the servers the NTP daemon is using, and theย refidย column tells you the source the servers are using. So for Stratum 1 servers, theย refidย field should showย GPS,ย PPS,ย ACTS, orย PTB, and Stratum 2 and higher servers will show the IP address of the upstream server. Theย stย column shows the stratum, andย delay,ย offsetย andย jitterย tell you about the quality of the time source. Lower values are better for these three fields.
Your time server is now able to serve time to the public. You can verify this by callingย ntpdateย from another host:
โฆ ntpdate -q your_server_ip
โฆ
The output should look similar to this and it tells you it adjusted the time server and the offset:
Output
server your_server_ip, stratum 2, offset 0.001172, delay 0.16428
2 Mar 23:06:44 ntpdate[18427]: adjust time server your_server_ip offset 0.001172 sec
Step 4 โ€” Adding the Server to the NTP Pool
To add your server so others can use it, visitย manage.ntppool.orgย and sign up for an account. You will receive an email fromย NTP Poolย help@ntppool.orgย requesting that you verify your account. Confirm your account by following the instructions in the email, and then log in toย manage.ntppool.org.
Once logged in, you’ll see the simple interface for adding servers:

Enter your server’s IP address and clickย Submit.
The next screen asks you to verify that it identified the region of your server. If it shows your server in a different region than you expect, use theย Commentย box to let them know.

If you are happy, confirm the entry by clickingย Yes, this is my server, add it!
Your server is now part of the NTP Pool Project. Visitย http://www.pool.ntp.org/scores/your_server_ipย to see information the NTP Pool’s monitoring system has collected about your server. It checks your server a few times per hour and displays offset data, alog with theย scoreย of your system. As long as your server is keeping good time and is reachable, the score will rise untill it reaches 20 points. Only servers with a score higher than 10 are used in the pool.

Categories: Announcements

0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.