How to install NTPD on CentOS Linux – CentOS ntp installation guide

How can I install NTPD on CentOS Linux (desktop and servers)?

You can do it easily using NTPD, NTP means Network Time Protocol. NTPD is a system daemon that helps servers to keep their date and time syncronized with the global CentOS NTPD servers. This tool is available for desktop or servers running any kind of Linux distribution. In this case, we will show you how to install NTPD on CentOS Linux.

Network Time Protocol, aka NTP is an internet protocol that listens on UDP port 123. It allows machines and servers to synchornize time over the networks to get an accurate date and time.

From time to time, computers internal system clocks tend to have time issues, this is specially noticeable while working with linux servers when you need to replicate data over a few hosts, like it happens on apache or mysql databases replication. That’s why having a CentOS ntp server can help you a lot to have the right accurate time, always.

Install NTPD on CentOS: the easy way

Connect to your server as root, then install the NTP required packages:

yum install ntp ntpdate ntp-doc

This command will install:

ntp: ntpd server/daemon, needed to sync system time.
ntpdate: system tool used to configure the date and time via NTP.
ntp-doc: in case you ever need to read the NTP documentation.

Add NTPD to your system boot

chkconfig ntpd on

Test NTPD

This command will synchronize the server system clock with pool.ntp.org server. It’s also useful to test if your server is able to connect to the NTP Global Time server

ntpdate 0.pool.ntp.org

If it is working OK the output should be something like this:

13 Jul 17:18:43 ntpdate[19460]: adjust time server 38.229.71.1 offset 0.266345 sec

If you have a firewall running you may see this issue:

[[email protected]:~]ntpdate pool.ntp.org
13 Jul 16:08:47 ntpdate[2765]: sendto(time-b.timefreq.bldrdoc.gov): Operation not permitted
13 Jul 16:08:47 ntpdate[2765]: sendto(time01.muskegonisd.org): Operation not permitted
13 Jul 16:08:48 ntpdate[2765]: sendto(mirror): Operation not permitted

To allow NTPD sync to work properly you should open UDP port 123 in your iptables firewall.

Once you see it’s working you are ready to stop testing and start the real server daemon
Start the NTP server. The following will continuously adjusts system time from upstream NTP server. No need to run ntpdate:

/etc/init.d/ntpd start

That’s all, at this point your should be able to install NTPD on CentOS without any troubles.

If you ever need to tweak NTPD configuration, you can edit this file:

nano -w /etc/ntpd.conf

It contains the default configuration:

 
[email protected] [~]# cat /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

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

# 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 -6 ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# 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

#broadcast 192.168.1.255 autokey	# broadcast server
#broadcastclient			# broadcast client
#broadcast 224.0.1.1 autokey		# multicast server
#multicastclient 224.0.1.1		# multicast client
#manycastserver 239.255.254.254		# manycast server
#manycastclient 239.255.254.254 autokey # manycast client

# Enable public key cryptography.
#crypto

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography. 
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify th 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

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

# 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 -6 ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# 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

#broadcast 192.168.1.255 autokey	# broadcast server
#broadcastclient			# broadcast client
#broadcast 224.0.1.1 autokey		# multicast server
#multicastclient 224.0.1.1		# multicast client
#manycastserver 239.255.254.254		# manycast server
#manycastclient 239.255.254.254 autokey # manycast client

# Enable public key cryptography.
#crypto

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography. 
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey e key identifier to use with the ntpq utility.
#controlkey 8

# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats

Setup Windows NTP Client

If you are running a microsoft windows machine and you need to synchronize time with your Linux NTP server, you can setup this time sync by following the next steps:

1. Move to Time, on right right side of Taskbar.
2. Click Date and Time Settings.
3. Click Internet Time Tab – Click Settings.
4. Check / Activate ‘Synchronize with an Internet time server’
5. Enter your ntp server IP on the ‘Server0 field.
6. Click Update now – Click OK.

All done, now your windows NTP client should be sync with your CentOS NTPserver.

All done, at this point you should have ntp on CentOS working after following our centos ntp installation step by step. CentOS ntp server is the best way to time sync server settings across the network.

If you need to read more about NTP follow this links:

About the Author: Santiago Borges

Experienced Sr. Linux SysAdmin and Web Technologist, passionate about building tools, automating processes, fixing server issues, troubleshooting, securing and optimizing high traffic websites.

Leave a Reply

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