NTP Client And Server in Centos/RHEL System

The Network Time Protocol (NTP) is used to synchronize a computer’s time with another reference time source. Under CentOS / RHEL you can use NTP or OpenNTPD server software. Both package provides client and server software programs for time synchronization.

Install ntp

The ntp package contains utilities and daemons that will synchronize your computer’s time to Coordinated Universal Time (UTC) via the NTP protocol and NTP servers. The ntp packageincludes ntpdate (a program for retrieving the date and time from remote machines via a network) and ntpd (a daemon which continuously adjusts system time). Install the ntp package:
[nepalisupport@blog~]$yum install ntp

How do I configure an NTP Client?

Simply open /etc/ntp.conf file, enter:
[nepalisupport@blog~]$vi /etc/ntp.conf
Make sure the following line exists:
server ntp.server.com

  • ntp.server.com : the hostname or IP address of the site NTP server. If your ntp server located at, enter server You can also use public ntp server located at ntp.org.

You can also run ntpd using cron:
[nepalisupport@blog~]$echo '30 * * * * root /usr/sbin/ntpd -q -u ntp:ntp' > /etc/cron.d/ntpd
The above instructs crond to run ntpd and after setting the clock just exit, and the -u option instructs it to run as the ntp user.

Configure an NTP Server

If you have lots of server and desktop system, configure your own NTP server. Your NTP server contacts a central NTP server,provided by your ISP or a public time
server located at ntp.org, to obtain accurate time data. The server then allows other machines on your network to request the time data. Our sample setup:            ==> CentOS / Fedora / RHEL NTPD Server.              ==> ISP remote NTP server.        ==> NTP clients including desktop systems.

First, install and enable ntpd on
[nepalisupport@blog~]$yum install ntp
[nepalisupport@blog~]$chkconfig ntpd on

Now open /etc/ntp.conf:
[nepalisupport@blog~]$vi /etc/ntp.conf
Make sure the following line exits:
restrict default ignore
Above will deny all access to any machine, server or client. However, you need to specifically authorized policy settings. Set it as follows:

restrict mask nomodify notrap noquery

Replace and mask with actual remote ISP or ntp.org NTP server IP. Save and close the file.

Configure NTP clients to access your NTP Server

Now, you need to allow legitimate NTP clients to access the Server. For example, allow network to synchronize to this server located at Open /etc/ntp.conf and add policy as follows:

[nepalisupport@blog~]$Hosts on local network are less restricted.
restrict mask nomodify notrap

If your system uses Firewall rules:

Update your firewall settings, open /etc/sysconfig/iptables.
[nepalisupport@blog~]$vi /etc/sysconfig/iptables
Add the following line, before the final LOG and DROP lines for the RH-Firewall-1-INPUT chain:

 -A RH-Firewall-1-INPUT -s -m state --state NEW -p udp --dport 123 -j ACCEPT

Save and close the file. Finally, start ntpd:
[nepalisupport@blog~]$service ntpd start
[nepalisupport@blog~]$service iptables restart
[nepalisupport@blog~]$netstat -tulpn

To check if the time is in synchronous or not:
[nepalisupport@blog~]$service ntpd stop

Above command shows the time difference as well as synchronize time with the server

[nepalisupport@blog~]$service ntpd start

Timezone setting

Sometime our timezone file is different than we want, Like when we need NPT time we may have PST timezone, so:

To check timezone simply type

Sun Jan 31 13:43:25 PST 2016

To change timezone:
Backup localtime:
[nepalisupport@blog~]$cp -p /etc/localtime /etc/localtime_bak

Create soft-link to desired timezone file.
[nepalisupport@blog~]$ln -s /usr/share/zoneinfo/Asia/Kathmandu /etc/localtime

Sun Jan 31 14:43:25 NPT 2016

This tutorial is created based on other technical blog and is fully tested on Virtual machine in Centos 6.6. Feel free to comment.

Thank you.

For more reading materials please click here