Linux Administrator

How To Setup NTP (Network Time Protocol) Server In CentOS/RHEL 7

Written by Santosh Prasad

NTP (Network Time Protocol) is used to synchronize computer’s time with another reference time source. It runs over port 123 UDP at transport layer and allows computers to synchronize time over networks for accurate time.

In CentOS and RHEL system you can use NTP or OpenNTPD server package. In both server and client packages comes by default.

Install NTP

Type the below command to install ntp package on RHEL and CentOS system.

# yum install ntp

Configure NTP Client

To configure NTP, edit /etc/ntp.conf file:

# vim /etc/ntp.conf

And put the below line this file.


Where, :- This is the hostname or IP address of the NTP server. You can also use public NTP server located at

Cron For NTP

You can also set cron to run ntpd.

# echo '20 * * * * root /usr/sbin/ntpd -q -u ntp:ntp' > /etc/cron.d/ntpd

In above cron I have instructed cron to run ntpd and after setting the clock exit, and then -u option instructed it to run as the ntp user.

Configure NTP Server

You can also configure your own NTP server if you have lots of server and system in a network. This NTP server will use the central NTP server, provided by your ISP or public time server located at to obtain accurate time and date. Then this server NTP server will allow other system in network to request the time and date. Some Example:           ==> CentOS / Fedora / RHEL NTPD Server.            ==> ISP remote NTP server.        ==> NTP clients including desktop systems.

First, You have to install and enable ntpd on system, typing below command

# yum install ntp
# chkconfig ntpd on

Now edit /etc/ntp.conf file.

# vim /etc/ntp.conf

Put the below line:

restrict default ignore

This entry will deny all access to any machine, client or server, and you need to specifically reauthorized policy setting.

restrict mask nomodify notrap noquery

Now replace and mask with your actual remote ISP or NTP server IP.

Configure NTP Client To Server

After configuring NTP server, you need to allow ntp client to access the server. For example, if you want to allow network. Edit the /etc/ntp.conf fine and add make the below entry:

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

Firewall Setting

Now update your firewall setting.

# vim /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -s -m state --state NEW -p udp --dport 123 -j ACCEPT

Save and close file.

Restart NTPD Service

Restart ntpd and firewall service.

# service ntpd start
# service iptables restart

Check Port

Type below command to check running port on the system.

# netstat -tulpn 


About the author


Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment