NTP server installation& Configuration on CentOs 7/RHEL 7

0
767

NTP server

NTP means Network time Protocol works using UDP on port No 123. It can helpful to clock synchronization between computer systems and NTP server. It synchronizes within few milliseconds of UTC. It uses the modified version of marzullos algorithm to select the accurate time servers.

In this article, We will be known about the installation and configuraton of NTP server on Centos 7 and RHEL 7.

First install the NTP package by using the following command

[root@localhost ~]# yum -y install ntp
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 0:4.2.6p5-22.el7.centos will be updated
---> Package ntp.x86_64 0:4.2.6p5-25.el7.centos will be an update
--> Processing Dependency: ntpdate = 4.2.6p5-25.el7.centos for package: ntp-4.2.6p5-25.el7.centos.x86_64
--> Running transaction check
---> Package ntpdate.x86_64 0:4.2.6p5-22.el7.centos will be updated
---> Package ntpdate.x86_64 0:4.2.6p5-25.el7.centos will be an update
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package             Arch               Version                              Repository        Size
====================================================================================================
Updating:
 ntp                 x86_64             4.2.6p5-25.el7.centos                base             547 k
Updating for dependencies:
 ntpdate             x86_64             4.2.6p5-25.el7.centos                base              85 k

Transaction Summary
====================================================================================================
Upgrade  1 Package (+1 Dependent package)

Total size: 632 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : ntpdate-4.2.6p5-25.el7.centos.x86_64                                             1/4
  Updating   : ntp-4.2.6p5-25.el7.centos.x86_64                                                 2/4
  Cleanup    : ntp-4.2.6p5-22.el7.centos.x86_64                                                 3/4
  Cleanup    : ntpdate-4.2.6p5-22.el7.centos.x86_64                                             4/4
  Verifying  : ntp-4.2.6p5-25.el7.centos.x86_64                                                 1/4
  Verifying  : ntpdate-4.2.6p5-25.el7.centos.x86_64                                             2/4
  Verifying  : ntp-4.2.6p5-22.el7.centos.x86_64                                                 3/4
  Verifying  : ntpdate-4.2.6p5-22.el7.centos.x86_64                                             4/4

Updated:
  ntp.x86_64 0:4.2.6p5-25.el7.centos

Dependency Updated:
  ntpdate.x86_64 0:4.2.6p5-25.el7.centos

Complete!
[root@localhost ~]#

Once the installation completed. From the NTP SERVER POOL select your near servers and copy these address and add to configuration file. Here i select Asia and Address are as follows


The configuration of NTP server is /etc/ntp.conf. Open with the vi editor find the default server list and comment these servers by adding # key before the line add the Nearest server list below that as follows

Now uncomment the restricted hosts then add the log file to save logs at end of the file as follows

logfile /var/log/ntp.log

Now save the file with Esc+:wq.

Now add the firewall rules to allow NTP service as follow

[root@localhost ~]# systemctl start firewalld
[root@localhost ~]# firewall-cmd --add-service=ntp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success

Now start and enable NTP service as follows

#ssystemctl start ntpd
#systemctl enable ntpd

We can check status of NTP server by using the status as follows

[root@localhost ~]# systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2017-01-31 23:33:47 EST; 16s ago
 Main PID: 10143 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─10143 /usr/sbin/ntpd -u ntp:ntp -g

Jan 31 23:33:46 localhost.localdomain systemd[1]: Starting Network Time Service...
Jan 31 23:33:47 localhost.localdomain systemd[1]: Started Network Time Service.
Jan 31 23:33:47 localhost.localdomain ntpd[10143]: proto: precision = 0.071 usec
Jan 31 23:33:47 localhost.localdomain ntpd[10143]: 0.0.0.0 c01d 0d kern kernel time sync enabled

Now we can update and check time as follows

[root@localhost ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+time.iqnet.com  62.201.214.162   2 u   19   64    3  310.031  -38.305  17.225
+82.200.209.236  89.109.251.23    2 u   20   64    3  326.582  -43.341   5.859
*168.63.242.24   203.123.48.219   2 u   16   64    3   80.756   15.638  11.535
-y.ns.gin.ntt.ne 249.224.99.213   2 u   16   64    3  308.751  -113.89   6.931
[root@localhost ~]# date -R
Tue, 31 Jan 2017 23:35:25 -0500

We can also synchronize to particular server by using the following command

[root@localhost ~]# ntpdate -q 2.asia.pool.ntp.org
server 113.20.29.181, stratum 2, offset -0.060098, delay 0.32103
server 45.76.154.118, stratum 2, offset -0.005855, delay 0.45009
server 211.233.40.78, stratum 2, offset 0.034333, delay 0.46214
server 61.216.153.105, stratum 3, offset 0.092340, delay 0.33220
31 Jan 23:39:28 ntpdate[11619]: adjust time server 113.20.29.181 offset -0.060098 sec

In windows clients go to taskbar right click on Time and select Adjust Date/Time. Click on Inrenet time tab and then click on change settings type the server address and click on updatenow to update time.

Now Enjoy NTP server in your network.