Installing NTP Server on CentOS/RHEL 7/6/5

Network Time Protocol (NTP) is used to synchronize system clocks of different hosts over the network. Most companies will have a local NTP server that they keep in sync with an external timing source and then they have all of their internal servers sync their time with that machine. In this setup, we will configure Linux system as NTP server.

Install the NTP Packages
NTP server package is provided by CentOS/RHEL default repositories and can be installed using yum command.

# yum install ntp

Configure NTP Server
If you have lots of server in the environment and this we will use NTP servers to synchronize time by the ISP or the Public time located at ntp.org. We suggest using any nearby servers also. You can find nearby servers at NTP Public Pool Time Servers (http://www.pool.ntp.org/en/).

# vim /etc/ntp.conf
server 0.asia.pool.ntp.org iburst
server 1.asia.pool.ntp.org iburst
server 2.asia.pool.ntp.org iburst
server 3.asia.pool.ntp.org iburst

Allow LAN Systems
Now, you need to allow clients from your networks to synchronize time with this server. To do it add following entry in configuration file

# vim /etc/ntp.conf
restrict 192.168.5.0 mask 255.255.255.0 nomodify notrap
Enable NTP Log
In case there are problems with your NTP daemon add a log file statement which will record all NTP server issues. Add the following content as below.

# vim /etc/ntp.conf
logfile /var/log/ntp.log

Add Firewall Rules
NTP server listens on UDP port 123. If you are using iptables of the server then run the following command.
CentOS/RHEL 7

# firewall-cmd –add-service=ntp –permanent
# firewall-cmd –reload
CentOS/RHEL 6/5

# iptables -A INPUT -s 192.168.1.0/24 -p udp –dport 123 -j ACCEPT
# iptables -A INPUT -p udp –dport 123 -j DROP
Restart NTP Server
After all NTP configuration, Let’s restart NTP server using following commands.

CentOS/RHEL 7

# systemctl start ntpd
# systemctl enable ntpd
CentOS/RHEL 6/5

# service ntpd start
# chkconfig ntpd on
Verify Configuration
You can verify the configuration using below command.

# ntpq -p
# date -R

Leave a Reply

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