Setting Up NTP server on CentOS 7

What is NTP

NTP (Network Time Protocol) is a protocol used to synchronize computer times over a network, and it is one of the oldest TCP/IP protocol stack parts which is highly fault-tolerant and scalable. There are thousands of NTP servers around the world with access to highly precise atomic clocks and GPS clocks, NTP uses Coordinated Universal Time (UTC) to synchronize computer clock times with precision.

Install NTP Server

First, install NTP package on your system using “yum” with the command below:

yum install ntp

Set restrict values in the configuration file

Open the NTP configuration file with your preferred text editor, we are going to use “vi”:

vi /etc/ntp.conf

make sure that the following two lines are uncommented:


restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

The restrict line allow clients to query your time server, let’s see the configured parameters:

noquery prevents dumping status data from ntpd.

notrap prevents control message trap the service.

nomodify discards all ntpq queries that attempt to modify the server.

nopeer prevents all packets that attempt to establish a peer association.

kod (kiss-to-death) packet is to be sent to reduce unwanted queries.

Allow only specific clients

To only allow machines from your network to synchronize with your NTP server, you can add the following line to your configuration file:

vi /etc/ntp.conf
restrict 10.0.0.10 mask 255.255.255.0 nomodify notrap

If the localhost should have full access to every query and modify, set the line below:

restrict 127.0.0.1

Add local clock as a backup

Add the local clock to the “ntp.conf” file so that if the NTP server is disconnected from the internet, it can provide time from its local system clock.


server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10

Setup NTP log and Driftfile

declare the log and driffile location in your “ntp.conf” file:

vi /etc/ntp.conf

Add the following lines, you can change location and file values as you preferred:


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

The driftfile is used to log how far your clock is from what it should be, and slowly NTP should lower this value as time progress.

Start and Enable NTP server

After setting the preferred configuration parameters in the configuration file you can start and enable NTP service with the following two commands:

systemctl restart ntpd
systemctl enable ntpd

Leave a Reply

Your email address will not be published. Required fields are marked *